From 7e29702dd628807688d78637ba51697615873785 Mon Sep 17 00:00:00 2001 From: pavan3008 Date: Sun, 3 Mar 2024 02:03:52 -0800 Subject: [PATCH] Added video recommendations --- backend/main.py | 18 +++++++++++++++++- frontend/app.py | 7 ++++++- frontend/utils.py | 9 +++++++++ videos.csv | 5 +++++ 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 videos.csv diff --git a/backend/main.py b/backend/main.py index 88d6461..32a06e6 100644 --- a/backend/main.py +++ b/backend/main.py @@ -64,4 +64,20 @@ def run_tts(): gpt4_model = TextModel(model_name="gpt-4-1106-preview") response_text = gpt4_model.complete(input_text) # Call the tts function with the formatted string - tts(response_text) \ No newline at end of file + tts(response_text) + +def recommend_video_link(question, context): + client = OpenAI() + response = client.chat.completions.create( + model="gpt-3.5-turbo", + messages=[ + {"role": "system", "content": "Based on the video titles below, recommend the most relevant video for the question. If the question can't be answered based on the titles, then return empty string. Note: Only provide the link to the video and no additional text.\n\n" + context}, + {"role": "user", "content": f"Question: {question}\nAnswer:"} + ], + temperature=0, + max_tokens=100, + top_p=1, + frequency_penalty=0, + presence_penalty=0, + ) + return response.choices[0].message.content \ No newline at end of file diff --git a/frontend/app.py b/frontend/app.py index e9aea08..253e3a8 100644 --- a/frontend/app.py +++ b/frontend/app.py @@ -18,6 +18,7 @@ VOICE_TESTING = "backend/speech.mp3" LOGO = "frontend/testing_data/logo.jpeg" FAVICON = "frontend/testing_data/logo.png" +VIDEO_LINK = "videos.csv" # Initialize state variables if not already present if "student_images_paths" not in st.session_state: @@ -166,6 +167,8 @@ audio_bytes = audio_file.read() st.audio(audio_bytes, format="audio/mp3", start_time=0) + df = pd.read_csv(VIDEO_LINK) + context = read_video_csv(df) results = "🌟 Here are the recommended questions for improvement! Let's dive in and explore 🚀✨ Keep up the great work, and remember, every question is a step towards mastery! 📚" diff --git a/frontend/utils.py b/frontend/utils.py index 5b86c21..4536640 100644 --- a/frontend/utils.py +++ b/frontend/utils.py @@ -31,3 +31,12 @@ def display_images(file_paths, default_image_path, title): else: # Display default image if no images are found st.image(default_image_path, caption="Default Image", width=500) + +def read_video_csv(df): + # Prepare the context for GPT based on video names and their links + context = "Based on the following video titles and their links:\n" + for _, row in df.iterrows(): + question = row['question'] + video_link = row['link'] + context += f"- {question}: {video_link}\n" + return context \ No newline at end of file diff --git a/videos.csv b/videos.csv new file mode 100644 index 0000000..f03731e --- /dev/null +++ b/videos.csv @@ -0,0 +1,5 @@ +question,link +Solve for x: 2x + 5 = 15,https://www.youtube.com/watch?v=pOeotbDbC7I +Find the roots of the quadratic equation: x^2 - 5x + 6 = 0 ,https://www.youtube.com/watch?v=ri5PJ7b6594 +"If f(x) = 3x^2 - 2x + 1, find f(2) ",https://www.youtube.com/watch?v=UzeLsa38wQI +Simplify the expression 2x^2 - 8 / x - 2 ,https://www.youtube.com/watch?v=M-AqHlSQwcI \ No newline at end of file