devfire commited on
Commit
ca57036
·
verified ·
1 Parent(s): 4750e9c

Update app.py

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