Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
janthonysantana authored Jun 26, 2024
2 parents 0807318 + 8dcd4a2 commit 5758d96
Show file tree
Hide file tree
Showing 21 changed files with 237 additions and 63 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/main_mental-health-app-api.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# name: Deploy Backend Container

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./server

steps:
- name: Checkout the Git Repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.11.9

- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
- name: Configure Poetry
run: |
echo "$HOME/.local/bin" >> $GITHUB_PATH
poetry config virtualenvs.create false
- name: Install dependencies with Poetry
run: |
poetry install
# - name: Log in to Azure CLI
# uses: azure/login@v2
# with:
# creds: ${{ secrets.AZURE_CREDENTIALS }}
# # Ensure AZURE_CREDENTIALS is set in your GitHub Secrets

# - name: Build and Push Docker image
# run: |
# docker build --pull --rm -t mental-health-app:latest .
# docker tag mental-health-app:latest dgmlgmckl6olsb4registry.azurecr.io/mental-health-app:1.0.0
# echo ${{ secrets.REGISTRY_PASSWORD }} | docker login dgmlgmckl6olsb4registry.azurecr.io -u ${{ secrets.REGISTRY_USERNAME }} --password-stdin
# docker push dgmlgmckl6olsb4registry.azurecr.io/mental-health-app:1.0.0
# # Use REGISTRY_USERNAME and REGISTRY_PASSWORD secrets for Docker registry credentials

# - name: Deploy to Azure Container Apps
# run: |
# az account set --subscription ${{ secrets.SUBSCRIPTION_ID }}
# az extension add --name containerapp --upgrade
# az containerapp env create --name mental-health-app-ctr-env-2 --resource-group mongo-devguide-rg --location "eastus"
# az containerapp up --name mental-health-app-ctr --image dgmlgmckl6olsb4registry.azurecr.io/mental-health-app:1.0.0 --resource-group mongo-devguide-rg --environment mental-health-app-ctr-env-2 --ingress external
# # Use SUBSCRIPTION_ID secret for Azure subscription ID
62 changes: 62 additions & 0 deletions .github/workflows/main_mental-health-app-web.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Build and deploy Node.js app to Azure Web App - mental-health-app-web

# Run the workflow on pushes to main branch
on:
push:
branches:
- main
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
environment:
name: 'production'
defaults:
run:
working-directory: ./client/

steps:
- name: Checkout Git repository
uses: actions/checkout@v4

- name: Set up Node.js version
uses: actions/setup-node@v4
with:
node-version: '20.x'

- name: Install dependencies
run: npm install

- name: Build distribution files
run: npm run build
env:
VITE_AXIOS_BASE_URL: ${{ vars.VITE_AXIOS_BASE_URL }}

- name: Upload artifact for deploment job
uses: actions/upload-artifact@v4
with:
name: node-app
path: ./client/dist/

deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'production'
url: ${{ vars.WEB_APP_URL }}

steps:
- name: Download artifact from build job
uses: actions/download-artifact@v4
with:
name: node-app

- name: 'Deploy to Azure Web App'
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: mental-health-app-web
slot-name: 'Production'
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: .
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 DHRUMIL PATEL

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
name="description"
content="This AI-Driven Mental Health Companion app provides mental health support through conversational AI, offering personalized advice, mood tracking, and mental health resources based on user inputs and interaction history. "
/>
<title>Mental Health Companion</title>
<title>Earlent - Mental Health Companion</title>
</head>
<body>
<div id="root"></div>
Expand Down
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mental-health-app-client",
"private": true,
"version": "0.1.0",
"version": "1.1.2",
"type": "module",
"scripts": {
"dev": "vite --port 3000 ",
Expand Down
7 changes: 4 additions & 3 deletions client/src/Components/authComponent.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState, useContext } from 'react';
import axios from 'axios';
import apiServerAxios from '../api/axios';
import { useNavigate } from 'react-router-dom';
import { UserContext } from './userContext';
import { Link } from 'react-router-dom';
Expand Down Expand Up @@ -105,7 +106,7 @@ function AuthComponent() {
e.preventDefault();
setLoading(true);
try {
const response = await axios.post('/api/user/login', { username, password });
const response = await apiServerAxios.post('/api/user/login', { username, password });
if (response && response.data) {
const userId = response.data.userId;
localStorage.setItem('token', response.data.access_token); // Ensure this is correctly saving the token
Expand Down Expand Up @@ -133,7 +134,7 @@ function AuthComponent() {
e.preventDefault();
setLoading(true);
try {
const response = await axios.post('/api/user/signup', {
const response = await apiServerAxios.post('/api/user/signup', {
username,
email,
password,
Expand Down Expand Up @@ -171,7 +172,7 @@ function AuthComponent() {
e.preventDefault();
setLoading(true);
try {
const response = await axios.post('/api/user/anonymous_signin');
const response = await apiServerAxios.post('/api/user/anonymous_signin');
if (response && response.data) {
const userId = null;
localStorage.setItem('token', response.data.access_token); // Ensure this is correctly saving the token
Expand Down
52 changes: 24 additions & 28 deletions client/src/Components/chatComponent.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState, useEffect, useContext, useCallback, useRef } from 'react';
import axios from 'axios';
import { InputAdornment,Switch, IconButton, Box, Card, CardContent, Typography, TextField, Button, List, ListItem, ListItemAvatar, ListItemText, CircularProgress, Snackbar, Divider, Avatar, Tooltip } from '@mui/material';
import apiServerAxios from '../api/axios';
import { InputAdornment, IconButton, Box, Card, CardContent, Typography, TextField, Button, List, ListItem, ListItemAvatar, ListItemText, CircularProgress, Snackbar, Divider, Avatar, Tooltip } from '@mui/material';
import MuiAlert from '@mui/material/Alert';
import SendIcon from '@mui/icons-material/Send';
import MicIcon from '@mui/icons-material/Mic';
Expand Down Expand Up @@ -48,7 +49,7 @@ const ChatComponent = () => {
event.preventDefault(); // Prevents the IconButton from triggering form submissions if used in forms
setVoiceEnabled(!voiceEnabled);
};

const speak = (text) => {

if (!voiceEnabled || text === currentPlayingMessage) {
Expand Down Expand Up @@ -78,7 +79,7 @@ const ChatComponent = () => {
synth.speak(utterance);
};

if (synth.getVoices().length === 0){
if (synth.getVoices().length === 0) {
synth.onvoiceschanged = setVoiceAndSpeak;
} else {
setVoiceAndSpeak();
Expand All @@ -91,15 +92,13 @@ const ChatComponent = () => {
setIsLoading(true);
setIsFetchingMessage(true);
try {
const response = await fetch(`/api/ai/mental_health/welcome/${userId}`, {
method: 'POST',
const response = await apiServerAxios.post(`/api/ai/mental_health/welcome/${userId}`, {
headers: {
'Content-Type': 'application/json'
"Content-Type": "application/json"
}
});
const data = await response.json();
console.log(data);
if (response.ok) {
if (response && response.data) {
const data = response.data
setWelcomeMessage(data.message);
if (voiceEnabled && data.message) { // Ensure voice is enabled and the message is not empty
speak(data.message);
Expand Down Expand Up @@ -134,13 +133,10 @@ const ChatComponent = () => {
if (chatId === null) return;
setIsLoading(true);
try {
const response = await fetch(`/api/ai/mental_health/finalize/${userId}/${chatId}`, {
method: 'POST',
const response = await apiServerAxios.patch(`/api/ai/mental_health/finalize/${userId}/${chatId}`, {
headers: { 'Content-Type': 'application/json' }
});

const data = await response.json();
if (response.ok) {
if (response) {
setSnackbarMessage('Chat finalized successfully');
setSnackbarSeverity('success');
// Reset chat state to start a new chat
Expand Down Expand Up @@ -169,19 +165,19 @@ const ChatComponent = () => {


try {
const body = JSON.stringify({
const body = {
prompt: input,
turn_id: turnId
});
const response = await fetch(`/api/ai/mental_health/${userId}/${chatId}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: body
};
const response = await apiServerAxios.post(`/api/ai/mental_health/${userId}/${chatId}`, {
headers: {
"Content-Type": "application/json"
},
...body
});

const data = await response.json();
console.log(data);
if (response.ok) {
const data = response.data;
if (response && data) {
setMessages(prev => [...prev, { message: input, sender: 'user' }, { message: data, sender: 'agent' }]);
// Speak the agent's message immediately after it's received and processed
if (voiceEnabled && data) { // Ensure voice is enabled and the message is not empty
Expand Down Expand Up @@ -281,11 +277,11 @@ const sendAudioToServer = (audioBlob) => {
formData.append('audio', audioBlob);
setIsLoading(true);

axios.post('/api/ai/mental_health/voice-to-text', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
})
apiServerAxios.post('/api/ai/mental_health/voice-to-text', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
})
.then(response => {
const { message } = response.data;
setInput(message);
Expand Down
12 changes: 7 additions & 5 deletions client/src/Components/chatInterface.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState, useEffect, useContext,useCallback, useRef } from 'react';
import axios from 'axios';
import { InputAdornment,IconButton,Box,Switch, Card, CardContent, Typography, TextField, Button, List, ListItem,ListItemAvatar, ListItemText, CircularProgress, Snackbar, Divider, Avatar, Tooltip } from '@mui/material';
import apiServerAxios from '../api/axios';
import { InputAdornment,IconButton,Box, Card, CardContent, Typography, TextField, Button, List, ListItem,ListItemAvatar, ListItemText, CircularProgress, Snackbar, Divider, Avatar, Tooltip } from '@mui/material';
import MuiAlert from '@mui/material/Alert';
import SendIcon from '@mui/icons-material/Send';
import MicIcon from '@mui/icons-material/Mic';
Expand Down Expand Up @@ -226,10 +227,11 @@ const sendAudioToServer = (audioBlob) => {
formData.append('audio', audioBlob);
setIsLoading(true);

axios.post('/api/ai/mental_health/voice-to-text', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
apiServerAxios.post('/api/ai/mental_health/voice-to-text', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
})
})
.then(response => {
const { message } = response.data;
Expand Down
5 changes: 3 additions & 2 deletions client/src/Components/chatLogManager.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState } from 'react';
import axios from 'axios';
import apiServerAxios from '../api/axios';
import {
Button, Snackbar, Alert, Tooltip, Paper, Typography, CircularProgress, TextField,
Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle
Expand Down Expand Up @@ -58,7 +59,7 @@ function ChatLogManager() {
const endpoint = range ? '/api/user/download_chat_logs/range' : '/api/user/download_chat_logs';
const params = range ? { params: { start_date: startDate, end_date: endDate } } : {};

const response = await axios.get(endpoint, {
const response = await apiServerAxios.get(endpoint, {
...params,
headers: {
'Authorization': `Bearer ${localStorage.getItem('token')}`
Expand Down Expand Up @@ -91,7 +92,7 @@ function ChatLogManager() {
const endpoint = dialogRange ? '/api/user/delete_chat_logs/range' : '/api/user/delete_chat_logs';
const params = dialogRange ? { params: { start_date: startDate, end_date: endDate } } : {};

const response = await axios.delete(endpoint, {
const response = await apiServerAxios.delete(endpoint, {
...params,
headers: {
'Authorization': `Bearer ${localStorage.getItem('token')}`
Expand Down
5 changes: 3 additions & 2 deletions client/src/Components/checkInForm.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState, useEffect } from 'react';
import axios from 'axios';
import apiServerAxios from '../api/axios';
import PropTypes from 'prop-types';
import { useParams } from 'react-router-dom';
import {
Expand Down Expand Up @@ -34,7 +35,7 @@ function CheckInForm({ userId, update }) {
if (update && checkInId) {
// Fetch existing check-in data
setLoading(true);
axios.get(`/api/check-in/${checkInId}`,{
apiServerAxios.get(`/api/check-in/${checkInId}`,{
headers: {
'Authorization': `Bearer ${token}` // Ensure the Authorization header is set
}
Expand Down Expand Up @@ -78,7 +79,7 @@ function CheckInForm({ userId, update }) {
const data = { user_id: userId, check_in_time: checkInTime, frequency, notify };
console.log('Submitting:', data);
try {
const response = await axios[method](url, data, config);
const response = await apiServerAxios[method](url, data, config);
console.log('Success:', response.data.message);
setSnackbar({ open: true, message: response.data.message, severity: 'success' });
// Optionally reset form or handle next steps
Expand Down
Loading

0 comments on commit 5758d96

Please sign in to comment.