Tanseer45203 commited on
Commit
c8aef16
·
verified ·
1 Parent(s): cf440f4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -12
app.py CHANGED
@@ -1,17 +1,34 @@
1
  import os
 
2
  from groq import Groq
3
 
4
- # Set API key directly for testing (remove this after testing)
5
- os.environ["GROQ_API_KEY"] = "your_actual_api_key_here"
6
 
7
- client = Groq(api_key=os.getenv("GROQ_API_KEY"))
 
8
 
9
- # Test API authentication
10
- try:
11
- chat_completion = client.chat.completions.create(
12
- messages=[{"role": "user", "content": "Test message"}],
13
- model="llama-3.3-70b-versatile",
14
- )
15
- print(chat_completion.choices[0].message.content)
16
- except Exception as e:
17
- print("Error:", e)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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!")