MuhammadQASIM111 commited on
Commit
5636b3f
·
verified ·
1 Parent(s): c7489e4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ from groq import Groq
4
+
5
+ # Set up the Groq API Key
6
+
7
+
8
+ # Initialize the Groq client
9
+ client = Groq(api_key=os.environ["GROQ_API_KEY"])
10
+
11
+ # Streamlit user input
12
+ st.title("Personalized Study Assistant Chatbot")
13
+ st.write("I’m here to help you organize your study plan with tailored resources and tips. Let's get started!")
14
+
15
+ # User input for study details
16
+ study_topic = st.text_input("What is your study topic or exam?")
17
+ prep_days = st.number_input("How many days do you have to prepare?", min_value=1)
18
+ hours_per_day = st.number_input("How many hours can you dedicate per day?", min_value=1)
19
+
20
+ # Function to generate chatbot response based on user input
21
+ def generate_study_plan(topic, days, hours):
22
+ prompt = (
23
+ f"I am a study assistant chatbot helping a user prepare for {topic} over {days} days "
24
+ f"with {hours} hours per day. Please provide a personalized study plan, tips for effective "
25
+ "study habits, and suggest specific resources for each session."
26
+ )
27
+
28
+ # Generate response using Groq API
29
+ chat_completion = client.chat.completions.create(
30
+ messages=[{"role": "user", "content": prompt}],
31
+ model="llama3-8b-8192",
32
+ )
33
+
34
+ response = chat_completion.choices[0].message.content
35
+ return response
36
+
37
+ # Display study plan when user submits details
38
+ if study_topic and prep_days and hours_per_day:
39
+ study_plan = generate_study_plan(study_topic, prep_days, hours_per_day)
40
+ st.write("### Your Study Plan")
41
+ st.write(study_plan)
42
+ else:
43
+ st.write("Please enter your study topic, preparation days, and available hours per day to receive a study plan.")