Upload 2 files
Browse files- app.py +46 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Import necessary libraries
|
| 2 |
+
import os
|
| 3 |
+
import streamlit as st
|
| 4 |
+
from groq import Groq
|
| 5 |
+
|
| 6 |
+
# Set up the Groq API Key
|
| 7 |
+
GROQ_API_KEY = "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"
|
| 8 |
+
os.environ["GROQ_API_KEY"] = GROQ_API_KEY
|
| 9 |
+
|
| 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("I’m 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 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
groq
|
| 2 |
+
streamlit
|