Skip to content

Commit

Permalink
backend url correct
Browse files Browse the repository at this point in the history
  • Loading branch information
tharoosha committed Oct 31, 2023
1 parent 7387169 commit 8c89bff
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 58 deletions.
31 changes: 29 additions & 2 deletions backend/controllers/appController.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,6 @@ export async function updateRecommendation(req, res) {
}
}



/** GET: http://localhost:5001/api/recommendation/:username */
export async function getRecommendation(req, res) {

Expand Down Expand Up @@ -398,4 +396,33 @@ export async function getRecommendation(req, res) {
// } catch (error) {
// return res.status(500).send({ error: "Failed to retrieve recommendations" });
// }
}

/** PUT: http://localhost:5001/api/updateRecommendation */
export async function updateEmotion(req, res){
try {
const { userId } = req.user;

if (userId) {

const body = req.body;

// update the data
UserModel.updateOne({ _id : userId }, body).exec().then(
(response) => {
res.status(201).send({ msg : "Record Updated...!"})
}
)

}else {
return res.status(401).send({ error : "User Not Found...!"});
}

} catch (error) {
return res.status(500).send({ error: "Failed to update recommendations" });
}
}

export async function getEmotion(req, res){

}
Binary file not shown.
Binary file not shown.
30 changes: 15 additions & 15 deletions backend/ml_models/recommanded_system/combinedScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import json

def combined_script(input_mood):
try:
# try:
# Call the function from mood_TO_video.py to get the output JSON
# output_json = train_and_predict_video_types(input_mood)

Expand All @@ -26,27 +26,27 @@ def combined_script(input_mood):
output_json = json.dumps(output)
sys.stdout.flush()
print(result)
except:
error_message = str(e)
output = {"error2011": error_message}

output_json = json.dumps(output)
# print(output_json)
sys.stdout.flush()
return(output_json)
# except:
# error_message = str(e)
# output = {"error2011": error_message}

# output_json = json.dumps(output)
# # print(output_json)
# sys.stdout.flush()
# return(output_json)

if __name__ == '__main__':
# Check if there is at least one command-line argument (excluding the script name)
if len(sys.argv) > 1:
# if len(sys.argv) > 1:
# The first command-line argument (sys.argv[1]) will be the input_mood
# input_mood = sys.argv[1]

# Call the function with the received input_mood
# combined_script(input_mood)
combined_script("Happiness")
combined_script("Happiness")

else:
# If no input_mood is provided, handle the case accordingly
print(json.dumps({"error": "No mood provided"}))
sys.stdout.flush()
# else:
# # If no input_mood is provided, handle the case accordingly
# print(json.dumps({"error": "No mood provided"}))
# sys.stdout.flush()
# combined_script('Happiness')
4 changes: 2 additions & 2 deletions backend/ml_models/recommanded_system/mood_TO_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ def update_user_feedback(mood, video_type, user_feedback):
text = mood + "," + video_type + "," + str(user_feedback)

# Open the CSV file in 'a' (append) mode and write the text
with open('youtube_data.csv', 'a') as file:
with open('backend/ml_models/recommanded_system/youtube_data.csv', 'a') as file:
file.write('\n' + text)


def train_and_predict_video_types(input_mood):
# Load the dataset with user feedback as NaN initially
df = pd.read_csv('youtube_data.csv')
df = pd.read_csv('backend/ml_models/recommanded_system/youtube_data.csv')
# Fill missing user_feedback values with 0
df['user_feedback'].fillna(0, inplace=True)

Expand Down
Binary file modified backend/ml_models/temp_audio.wav
Binary file not shown.
10 changes: 10 additions & 0 deletions backend/models/User.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ export const UserSchema = new mongoose.Schema({
address: { type: String},
profile: { type: String},
recommendation: { type: String},

emotions: {
Monday: { Joy: Number, Surprise: Number, Anger: Number, Sad: Number, Happy: Number },
Tuesday: { Joy: Number, Surprise: Number, Anger: Number, Sad: Number, Happy: Number },
Wednesday: { Joy: Number, Surprise: Number, Anger: Number, Sad: Number, Happy: Number },
Thursday: { Joy: Number, Surprise: Number, Anger: Number, Sad: Number, Happy: Number },
Friday: { Joy: Number, Surprise: Number, Anger: Number, Sad: Number, Happy: Number },
Saturday: { Joy: Number, Surprise: Number, Anger: Number, Sad: Number, Happy: Number },
Sunday: { Joy: Number, Surprise: Number, Anger: Number, Sad: Number, Happy: Number },
},
});

export default mongoose.model.Users || mongoose.model('User', UserSchema );
21 changes: 8 additions & 13 deletions frontend/src/components/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@ import { Chart } from 'react-google-charts';

const EmotionLineChart = () => {
const data = [
['Month', 'Joyful', 'Surprise', 'Anger', 'Sad', 'Happy'],
['January', 20, 15, 10, 5, 8],
['February', 18, 13, 11, 7, 10],
['March', 22, 17, 9, 4, 6],
['April', 25, 12, 15, 6, 9],
['May', 16, 20, 11, 8, 12],
['June', 19, 18, 8, 7, 11],
['July', 23, 16, 13, 5, 9],
['August', 17, 14, 12, 9, 7],
['September', 20, 19, 14, 4, 8],
['October', 18, 15, 10, 6, 10],
['November', 21, 17, 9, 5, 11],
['December', 24, 20, 11, 7, 6],
['Day', 'Joyful', 'Surprise', 'Anger', 'Sad', 'Happy'],
['Monday', 20, 15, 10, 5, 8],
['Tuesday', 18, 13, 11, 7, 10],
['Wednesday', 22, 17, 9, 4, 6],
['Tuesday', 25, 12, 15, 6, 9],
['Friday', 16, 20, 11, 8, 12],
['Saturday', 19, 18, 8, 7, 11],
['Sunday', 23, 16, 13, 5, 9]
];

return (
Expand Down
18 changes: 9 additions & 9 deletions frontend/src/helper/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function getUsername(){
/** authenticate function */
export async function authenticate(username){
try {
return await axios.post('http://localhost:5001/api/authenticate', { username })
return await axios.post(`http://localhost:5001/api/authenticate`, { username })
} catch (error) {
return { error : "Username doesn't exist...!"}
}
Expand Down Expand Up @@ -54,7 +54,7 @@ export async function registerUser(credentials){

/** send email */
if(status === 201){
await axios.post('http://localhost:5001/api/registerMail', { username, userEmail : email, text : msg})
await axios.post(`http://localhost:5001/api/registerMail`, { username, userEmail : email, text : msg})
}

return Promise.resolve(msg)
Expand All @@ -67,7 +67,7 @@ export async function registerUser(credentials){
export async function verifyPassword({ username, password }){
try {
if(username){
const { data } = await axios.post('http://localhost:5001/api/login', { username, password })
const { data } = await axios.post(`http://localhost:5001/api/login`, { username, password })
return Promise.resolve({ data });
}
} catch (error) {
Expand All @@ -80,7 +80,7 @@ export async function updateUser(response){
try {

const token = await localStorage.getItem('token');
const data = await axios.put('http://localhost:5001/api/updateuser', response, { headers : { "Authorization" : `Bearer ${token}`}});
const data = await axios.put(`http://localhost:5001/api/updateuser`, response, { headers : { "Authorization" : `Bearer ${token}`}});

return Promise.resolve({ data })
} catch (error) {
Expand All @@ -94,7 +94,7 @@ export async function updateRecommendation(response){
try {

const token = await localStorage.getItem('token');
const data = await axios.put('http://localhost:5001/api/updateRecommendation', response, { headers : { "Authorization" : `Bearer ${token}`}});
const data = await axios.put(`http://localhost:5001/api/updateRecommendation`, response, { headers : { "Authorization" : `Bearer ${token}`}});

return Promise.resolve({ data })
} catch (error) {
Expand All @@ -105,13 +105,13 @@ export async function updateRecommendation(response){
/** generate OTP */
export async function generateOTP(username){
try {
const {data : { code }, status } = await axios.get('http://localhost:5001/api/generateOTP', { params : { username }});
const {data : { code }, status } = await axios.get(`http://localhost:5001/api/generateOTP`, { params : { username }});

// send mail with the OTP
if(status === 201){
let { data : { email }} = await getUser({ username });
let text = `Your Password Recovery OTP is ${code}. Verify and recover your password.`;
await axios.post('http://localhost:5001/api/registerMail', { username, userEmail: email, text, subject : "Password Recovery OTP"})
await axios.post(`http://localhost:5001/api/registerMail`, { username, userEmail: email, text, subject : "Password Recovery OTP"})
}
return Promise.resolve(code);
} catch (error) {
Expand All @@ -122,7 +122,7 @@ export async function generateOTP(username){
/** verify OTP */
export async function verifyOTP({ username, code }){
try {
const { data, status } = await axios.get('http://localhost:5001/api/verifyOTP', { params : { username, code }})
const { data, status } = await axios.get(`http://localhost:5001/api/verifyOTP`, { params : { username, code }})
return { data, status }
} catch (error) {
return Promise.reject(error);
Expand All @@ -132,7 +132,7 @@ export async function verifyOTP({ username, code }){
/** reset password */
export async function resetPassword({ username, password }){
try {
const { data, status } = await axios.put('http://localhost:5001/api/resetPassword', { username, password });
const { data, status } = await axios.put(`http://localhost:5001/api/resetPassword`, { username, password });
return Promise.resolve({ data, status})
} catch (error) {
return Promise.reject({ error })
Expand Down
33 changes: 17 additions & 16 deletions frontend/src/pages/AI_Assistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const AI_Assistant = () => {
setRecording(false); // Set recording to false when audio is sent

axios
.post(`${process.env.REACT_APP_SERVER_ENDPOINT}/api/voice-input`, formData)
.post(`http://localhost:5001/api/voice-input`, formData)
.then((response) => {
console.log(response.data.result);
let data = response.data.result;
Expand All @@ -86,17 +86,18 @@ const AI_Assistant = () => {
setChatLog(updatedChatLogWithVoice);
const voice_message = response.data.result;
axios
.post(`${process.env.REACT_APP_SERVER_ENDPOINT}/api/analyze`, { message: voice_message })
.post(`http://localhost:5001/api/analyze`, { message: voice_message })
.then((response) => {
const updatedChatLogWithAI = [...chatLog, { user: 'User', message: voice_message }, { user: 'AI_Consultant', message: response.data.result }];
setChatLog(updatedChatLogWithAI);
setResponse(response.data.result);
})
.catch((error) => console.error(error));
axios
.post(`${process.env.REACT_APP_SERVER_ENDPOINT}/api/emotion_analyze`, { message: voice_message })
.post(`http://localhost:5001/api/emotion_analyze`, { message: voice_message })
.then((response) => {
setEmotion(response.data.emotion);
console.log(emotion)
updateRecommendation({"recommendation" : emotion})
console.log('database update done')
})
Expand Down Expand Up @@ -125,21 +126,21 @@ const AI_Assistant = () => {

setLoading(true);

// axios
// .post(`${process.env.REACT_APP_SERVER_ENDPOINT}/api/analyze`, { message: message })
// .then((response) => {
// const updatedChatLogWithAI = [...updatedChatLog, { user: 'AI_Consultant', message: response.data.result }];
// setChatLog(updatedChatLogWithAI);
// setResponse(response.data.result);
// setLoading(false);
// })
// .catch((error) => {
// console.error(error);
// setLoading(false);
// });
axios
.post(`http://localhost:5001/api/analyze`, { message: message })
.then((response) => {
const updatedChatLogWithAI = [...updatedChatLog, { user: 'AI_Consultant', message: response.data.result }];
setChatLog(updatedChatLogWithAI);
setResponse(response.data.result);
setLoading(false);
})
.catch((error) => {
console.error(error);
setLoading(false);
});

axios
.post(`${process.env.REACT_APP_SERVER_ENDPOINT}/api/emotion_analyze`, { message: message })
.post(`http://localhost:5001/api/emotion_analyze`, { message: message })
.then((response) => {
setEmotion(response.data.emotion);

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/MusicTherapy.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const MusicTherapy = () => {
console.log(typeof emotion)
// const data = {"mood": emotion}

axios.get(`${process.env.REACT_APP_SERVER_ENDPOINT}/api/spotify_recommend`, { emotion: emotion } )
axios.get(`http://localhost:5001/api/spotify_recommend`, { emotion: emotion } )
.then((response) => {
// const ytTrackIds = response.data.result;
console.log(response.data.result);
Expand Down

0 comments on commit 8c89bff

Please sign in to comment.