Waseemhassan771 commited on
Commit
a0942ef
·
verified ·
1 Parent(s): 0ffe368

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ from groq import Groq
4
+
5
+ # Set up the API key (Make sure to set this in your Hugging Face Space secrets)
6
+ GROQ_API_KEY = os.getenv("GROQ_API_KEY")
7
+
8
+ # Initialize the Groq client
9
+ client = Groq(api_key=GROQ_API_KEY)
10
+
11
+ # Streamlit UI
12
+ st.title("Groq Chatbot")
13
+ st.write("Ask me anything!")
14
+
15
+ # User input
16
+ user_input = st.text_input("Enter your message:")
17
+
18
+ if st.button("Send"):
19
+ if user_input:
20
+ try:
21
+ chat_completion = client.chat.completions.create(
22
+ messages=[{"role": "user", "content": user_input}],
23
+ model="llama-3.3-70b-versatile",
24
+ )
25
+ response = chat_completion.choices[0].message.content
26
+ st.write("### Response:")
27
+ st.write(response)
28
+ except Exception as e:
29
+ st.error(f"Error: {e}")
30
+ else:
31
+ st.warning("Please enter a message before sending.")