Spaces:
Build error
Build error
Create app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,34 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
from groq import Groq
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
os.environ
|
| 6 |
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import streamlit as st
|
| 3 |
from groq import Groq
|
| 4 |
|
| 5 |
+
# Load API key from environment variables
|
| 6 |
+
api_key = os.environ.get("GROQ_API_KEY")
|
| 7 |
|
| 8 |
+
# Initialize Groq client
|
| 9 |
+
client = Groq(api_key=api_key)
|
| 10 |
|
| 11 |
+
# Streamlit app setup
|
| 12 |
+
st.title("AI-powered Routine Assistant")
|
| 13 |
+
|
| 14 |
+
# Function to get response from the Groq model
|
| 15 |
+
def get_groq_response(user_message):
|
| 16 |
+
try:
|
| 17 |
+
chat_completion = client.chat.completions.create(
|
| 18 |
+
messages=[{"role": "user", "content": user_message}],
|
| 19 |
+
model="llama-3.3-70b-versatile",
|
| 20 |
+
)
|
| 21 |
+
return chat_completion.choices[0].message.content
|
| 22 |
+
except Exception as e:
|
| 23 |
+
return f"Error: {str(e)}"
|
| 24 |
+
|
| 25 |
+
# Display the chatbot's response based on the user's input
|
| 26 |
+
user_input = st.text_input("Ask me about your routine:")
|
| 27 |
+
|
| 28 |
+
if user_input:
|
| 29 |
+
# Make sure the question is routine-related, otherwise guide the user
|
| 30 |
+
if "routine" in user_input.lower() or "schedule" in user_input.lower():
|
| 31 |
+
response = get_groq_response(user_input)
|
| 32 |
+
st.write(response)
|
| 33 |
+
else:
|
| 34 |
+
st.write("I'm here to help with your study routine. Please ask me about your schedule!")
|