Update app.py
Browse files
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
|
| 14 |
-
st.title("
|
| 15 |
-
st.write("I
|
| 16 |
|
| 17 |
-
# User input for
|
| 18 |
-
|
| 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
|
| 24 |
-
prompt
|
| 25 |
-
|
| 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
|
| 40 |
-
if
|
| 41 |
-
|
| 42 |
-
st.write("###
|
| 43 |
-
st.write(
|
| 44 |
else:
|
| 45 |
-
st.write("Please
|
| 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.")
|
|
|