From 06d2811715a16dfd9afdb64c0b33b7c5a18cad16 Mon Sep 17 00:00:00 2001 From: tharoosha Date: Mon, 30 Oct 2023 12:05:31 +0530 Subject: [PATCH] url added to env --- .cache | 1 - backend/controllers/appController.js | 46 ++++++++++++++++++ backend/controllers/mlController.js | 7 +-- .../ml_models/spotify_recommendation/.cache | 2 +- .../spotifyRecommendScript.cpython-311.pyc | Bin 0 -> 9051 bytes .../spotifyRecommendScript.py | 8 +-- frontend/package-lock.json | 20 ++++++-- frontend/package.json | 1 + frontend/src/pages/AI_Assistant.js | 33 +++++++------ frontend/src/pages/MusicTherapy.js | 10 ++-- frontend/src/pages/YT_RecommendationView.js | 4 +- 11 files changed, 101 insertions(+), 31 deletions(-) delete mode 100644 .cache create mode 100644 backend/ml_models/spotify_recommendation/__pycache__/spotifyRecommendScript.cpython-311.pyc diff --git a/.cache b/.cache deleted file mode 100644 index 92498ea..0000000 --- a/.cache +++ /dev/null @@ -1 +0,0 @@ -{"access_token": "BQCyjMGZf4pCx_eJtw1NPa0Ol3r_-ZLTMZA3VKH7ftRL6IxBKFVGzB4-tVJQ09PuG6eXbeuf2QWfLp4ACtFYo6LnCKyxC1hlIbwbdaY6_sMLrd5kNG6AAW4_-ssHLi7wQVHAu6b8Hbv-ghIYq92BLZPGpl4X4WgaduKfOLwRBXxYZuZNiN5C5EhVCMUOp5dtG-KMsu0FAuQP6AaL4hrzP2J45-np3EmaWg", "token_type": "Bearer", "expires_in": 3600, "refresh_token": "AQDj6FSnK3dfmU2SW2SWaGl8da_ds0BdGhSLvMNjB_v0F_9sW-IbhNfbpokuw5IgbA2IfsvO7e5BVjICYtJLtulq9CRcj3i7anQZBwtE7wZ-8WTVamZskikYmDTrmY9i_hs", "scope": "playlist-read-private user-library-read user-read-recently-played user-top-read", "expires_at": 1693866674} \ No newline at end of file diff --git a/backend/controllers/appController.js b/backend/controllers/appController.js index 573bb70..058f3f7 100644 --- a/backend/controllers/appController.js +++ b/backend/controllers/appController.js @@ -314,4 +314,50 @@ export async function resetPassword(req,res){ } } +/** POST: http://localhost:5001/api/emotions/retrieve */ +/** Middleware for saving emotions for a user */ +export async function saveEmotions(req, res, next) { + try { + const { username, emotions } = req.body; + + // Check if the user exists + const user = await UserModel.findOne({ username }); + + if (!user) { + return res.status(404).send({ error: "User not found" }); + } + + // Update the user's emotions field with the new data + user.emotions = emotions; + + await user.save(); + + next(); + } catch (error) { + return res.status(500).send({ error: "Server Error" }); + } + } + + +/** POST: http://localhost:5001/api/emotions/save */ +/** Middleware for retrieving emotions for a user */ +export async function retrieveEmotions(req, res, next) { + try { + const { username } = req.method === "GET" ? req.query : req.body; + + // Check if the user exists + const user = await UserModel.findOne({ username }); + + if (!user) { + return res.status(404).send({ error: "User not found" }); + } + + // Assuming that emotions are stored as a field in the user model + req.userEmotions = user.emotions; + + next(); + } catch (error) { + return res.status(500).send({ error: "Server Error" }); + } + } \ No newline at end of file diff --git a/backend/controllers/mlController.js b/backend/controllers/mlController.js index 99e3d49..6ec4f83 100644 --- a/backend/controllers/mlController.js +++ b/backend/controllers/mlController.js @@ -130,11 +130,11 @@ export async function speech_to_text(req, res) { */ export async function emotion_analyzer(req, res) { - const { tweet } = req.body; + const { message } = req.body; try { - console.log(tweet) + console.log(message) const process = spawn("/usr/src/app/venv/bin/python3", ["/usr/src/app/ml_models/emotion_detection/emotionScript.py", tweet,]); - // const process = spawn("python3", ["../backend/ml_models/emotion_detection/emotionScript.py", tweet,]); + // const process = spawn("python3", ["../backend/ml_models/emotion_detection/emotionScript.py", message,]); let emotion = "" process.stdout.on("data", (data) => { @@ -155,6 +155,7 @@ export async function emotion_analyzer(req, res) { const jsonData = JSON.parse(emotion); // const joy = jsonData.emotion; // console.log(joy); + // console.log(emotion); res.status(200).send(jsonData); } catch (error) { res.status(500).json({ error: "Failed to parse JSON response" }); diff --git a/backend/ml_models/spotify_recommendation/.cache b/backend/ml_models/spotify_recommendation/.cache index 5991830..4c0e021 100644 --- a/backend/ml_models/spotify_recommendation/.cache +++ b/backend/ml_models/spotify_recommendation/.cache @@ -1 +1 @@ -{"access_token": "BQC80QFI4ychDG5CWRViF_eHXkYOT42vHCZY1aPIIPlhVcy4eKZLJA5c2CUdutVIBQTa-5hrNyKT_G6LY154cQythJwSjrfoM2AbG2dUdgAj8Seb63tdcbVVGQ_bGdTfu0WrCDUHTkzz26k5YmB9RKkP8qTWaXLIe1AQyTSnj43YBHe8Za2b8k-ZNl94NVoc68nAmiVZJ0fg5q9q_CnSU4-vPNolZYhCNI429g", "token_type": "Bearer", "expires_in": 3600, "scope": "playlist-read-private user-library-read user-read-recently-played user-top-read", "expires_at": 1698560410, "refresh_token": "AQDPFQQaeVerMmQwRulEXf-J4KgjjUINngJ-7MU19CyzrhZMYfh20NqYWXpHpc-XVrLBe7_gig_4zOmcnQCE2DvOrjAUUaK5YigF0Wg2C4f-NYpccD2MBMTl7qZ4vm3falU"} \ No newline at end of file +{"access_token": "BQC9OMFKcpyPnUKxRzR2QITzzr8GhYPCH2KCS8hk4na6TntReXKzKR91CKupGAvUBqcg0SLic6eae5RFdO4fv0Z1sPNj1cyRsShXpuV7EixiC3HDNGajiGKqRtcd0Ox8gotnH9tj2W09qijsnUuQ-V_M67mc0qRjjQN7nH5lTUBJTxIyfrt6AU27MDdITmZ4Y2POvDLupBjEWxnB3TYWaGuSo-4SxfCb78njbw", "token_type": "Bearer", "expires_in": 3600, "scope": "playlist-read-private user-library-read user-read-recently-played user-top-read", "expires_at": 1698634377, "refresh_token": "AQDPFQQaeVerMmQwRulEXf-J4KgjjUINngJ-7MU19CyzrhZMYfh20NqYWXpHpc-XVrLBe7_gig_4zOmcnQCE2DvOrjAUUaK5YigF0Wg2C4f-NYpccD2MBMTl7qZ4vm3falU"} \ No newline at end of file diff --git a/backend/ml_models/spotify_recommendation/__pycache__/spotifyRecommendScript.cpython-311.pyc b/backend/ml_models/spotify_recommendation/__pycache__/spotifyRecommendScript.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ad4b964c6d3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UnSL{*X7x{;&c9jeEuSO zW-qEkZz#b_YVeZM98#M@iswz$^JdPxZLY}ErGAZNe_Pc~b(>Gev0B(Eq{wC`yuObe zKX-h(f1O!%D76RF+5_2|7s$EYW6T(;^8Y*c!}1(X$2-m0Rq(&6LTDV?vWtF zGh5s=0r*CABvAG*>6m57y#oXZSFlSz*e49(O@R?kda*x+{ALFQq~LUamo<&Phlx7m zX%GQo07~q~#y>1_aoD8*KQZ0`2R1;Lln{-BlfooLHGhd4Hf>r+Mc}&+z)Kw#)mC`> zuW&ugYgRQLtTwCZ2w1a#Om zD|kZCCpsGtUVz>nhg@MlA{~hIB7(f&_$cZ}2|*LQ%h3X$FCF2q@F$R`nL(Il!Clsz z_yeF0gx*CJ{sM6T0%llz*6;@t>>R-d>9_Wyz`GFVhJ=3vMmRZy_&ZR9u%$_|KzOqF zw{0cJmt^9_>Zd^Lk&RD**d>>q0s;Jnr$98wrKdm~kd04)*e5^hDHt1t4ipG?7XJ!_ zBa45=cD*uDd>#{RvhhLVaAoQD+_yl&b`#Onm+$;MDEA##I!~ybC$gqnPMK~~i1tG7 zK>o_-ynNu4()*g)`CCS}W%VwqAcQ(4ot-9>h86J^q3Ldi05QY0v*GI8x9d$x%(dBH~dw}~>TJ3t~g zW)+Q*Zt~zZQ6_B!<;pE>n0L$O-H$0pc1(62TQl8pe&+eaBkwt)G`^}fz6yEpDAbTj z4aw9HKr6&Iws!K)w%LwGbqfp~2H7--*MZS@>gLjU6HuTAm{K5&P zd01@*U8m@%yR{=LsT?lAwxL5;g@zo{jG{vS=10" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/motdotla/dotenv?sponsor=1" } }, "node_modules/dotenv-expand": { @@ -16457,6 +16461,14 @@ } } }, + "node_modules/react-scripts/node_modules/dotenv": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz", + "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==", + "engines": { + "node": ">=10" + } + }, "node_modules/react-slick": { "version": "0.29.0", "resolved": "https://registry.npmjs.org/react-slick/-/react-slick-0.29.0.tgz", diff --git a/frontend/package.json b/frontend/package.json index cc3b4cb..dc21a68 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -10,6 +10,7 @@ "antd": "^5.5.1", "axios": "^1.4.0", "buffer": "^6.0.3", + "dotenv": "^16.3.1", "extendable-media-recorder": "^9.1.3", "extendable-media-recorder-wav-encoder": "^7.0.99", "formik": "^2.4.2", diff --git a/frontend/src/pages/AI_Assistant.js b/frontend/src/pages/AI_Assistant.js index 0b63530..3c716d0 100644 --- a/frontend/src/pages/AI_Assistant.js +++ b/frontend/src/pages/AI_Assistant.js @@ -9,6 +9,8 @@ import useFetch from '../hooks/fetch.hook'; import { useAuthStore } from '../store/store'; import { MediaRecorder, register } from 'extendable-media-recorder'; import { connect } from 'extendable-media-recorder-wav-encoder'; +// import 'dotenv/config'; + import axios from 'axios'; @@ -38,14 +40,14 @@ const AI_Assistant = () => { } }, [response]); - useEffect(() => { - axios.get('http://localhost:5001/api/spotify_recommend', { mood: emotion }) - .then((response) => { - setRecommendations(response.data); - console.log(response.data); - }) - .catch((error) => console.error(error)) - }, [emotion]); + // useEffect(() => { + // axios.get('${process.env.SERVER_ENDPOINT}/api/spotify_recommend', { mood: emotion }) + // .then((response) => { + // setRecommendations(response.data); + // console.log(response.data); + // }) + // .catch((error) => console.error(error)) + // }, [emotion]); const startRecording = async () => { if (isRecording) { @@ -80,7 +82,7 @@ const AI_Assistant = () => { // Send the audio data to the Node.js backend axios - .post('http://localhost:5001/api/voice-input', formData) + .post(`${process.env.REACT_APP_SERVER_ENDPOINT}/api/voice-input`, formData) .then((response) => { console.log(response.data.result); let data = response.data.result; @@ -94,7 +96,7 @@ const AI_Assistant = () => { // console.log(chatLog) // Make an HTTP request to the backend API to analyze user input using axios axios - .post('http://localhost:5001/api/analyze', { message: voice_message }) + .post(`${process.env.REACT_APP_SERVER_ENDPOINT}/api/analyze`, { message: voice_message }) .then((response) => { const updatedChatLogWithAI = [...chatLog, { user: 'User', message: voice_message }, { user: 'AI_Consultant', message: response.data.result }]; setChatLog(updatedChatLogWithAI); @@ -103,7 +105,7 @@ const AI_Assistant = () => { .catch((error) => console.error(error)); axios - .post('http://localhost:5001/api/emotion_analyze', { message: voice_message }) + .post(`${process.env.REACT_APP_SERVER_ENDPOINT}/api/emotion_analyze`, { message: voice_message }) .then((response) => { setEmotion(response.data.emotion); // console.log(response.data.emotion) @@ -128,10 +130,13 @@ const AI_Assistant = () => { e.preventDefault(); const updatedChatLog = [...chatLog, { user: 'User', message: message }]; setChatLog(updatedChatLog); + // console.log('{$process.env.REACT_APP_SERVER_ENDPOINT}') + + // Make an HTTP request to the backend API to analyze user input using axios axios - .post('http://localhost:5001/api/analyze', { message: message }) + .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); @@ -141,10 +146,10 @@ const AI_Assistant = () => { .catch((error) => console.error(error)); axios - .post('http://localhost:5001/api/emotion_analyze', { message: message }) + .post(`${process.env.REACT_APP_SERVER_ENDPOINT}/api/emotion_analyze`, { message: message }) .then((response) => { setEmotion(response.data.emotion); - console.log(response.data.emotion) + console.log(emotion) }) .catch((error) => console.error(error)); // Clear the input field after submitting diff --git a/frontend/src/pages/MusicTherapy.js b/frontend/src/pages/MusicTherapy.js index 7ec3f5d..379208f 100644 --- a/frontend/src/pages/MusicTherapy.js +++ b/frontend/src/pages/MusicTherapy.js @@ -27,13 +27,15 @@ import profileImg from '../images/chat-user.svg'; import chevronDown from '../images/chevron-down.svg'; import { useEffect, useState } from 'react'; import { Buffer } from 'buffer'; +// import 'dotenv/config'; import axios from 'axios'; const qs = require('qs'); -const client_id = '07f4d94fc95d4955ad32cdf68dbefa0c'; // Your client id -const client_secret = 'cd95a4c259a94411b20b6929270c8ab8'; // Your secret -// const client_id = process.env.SPOTIFY_CLIENT_ID; // Your client id -// const client_secret = process.env.SPOTIFY_CLIENT_SECRET; // Your secret + +// const client_id = '07f4d94fc95d4955ad32cdf68dbefa0c'; // Your client id +// const client_secret = 'cd95a4c259a94411b20b6929270c8ab8'; // Your secret +const client_id = process.env.SPOTIFY_CLIENT_ID; // Your client id +const client_secret = process.env.SPOTIFY_CLIENT_SECRET; // Your secret const redirect_uri = process.env.SPOTIFY_REDIRECT_URI; const auth_token = Buffer.from(`${client_id}:${client_secret}`, 'utf-8').toString('base64'); diff --git a/frontend/src/pages/YT_RecommendationView.js b/frontend/src/pages/YT_RecommendationView.js index a1759d9..c0d0eb0 100644 --- a/frontend/src/pages/YT_RecommendationView.js +++ b/frontend/src/pages/YT_RecommendationView.js @@ -4,6 +4,8 @@ import Footer from '../components/Footer'; import '../styles/YT_RecommendationView.scss'; import { Link } from 'react-router-dom'; import axios from 'axios'; +// import 'dotenv/config'; + // get_youtube_videos_from_preferences /** POST: http://localhost:5001/api/youtube_list */ @@ -47,7 +49,7 @@ const YT_RecommendationView = () => { body: storedData, }; axios - .post('http://localhost:5001/api/youtube_list', storedData) + .post(`${process.env.REACT_APP_SERVER_ENDPOINT}/api/youtube_list`, storedData) .then((response) => { console.log(typeof response.data); setVideoIds(response.data);