jehanzada commited on
Commit
3af2c11
·
verified ·
1 Parent(s): 2019e74

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ from groq import Groq
4
+
5
+ # Page config
6
+ st.set_page_config(page_title="Sample Chatbot", page_icon="🤖")
7
+
8
+ st.title("🤖 Sample Chatbot (Groq + Hugging Face)")
9
+
10
+ # Get API key from environment variable
11
+ api_key = os.environ.get("Samplechatboot")
12
+
13
+ if not api_key:
14
+ st.error("❌ API key not found. Please set environment variable: Samplechatboot")
15
+ st.stop()
16
+
17
+ # Create Groq client
18
+ client = Groq(api_key=api_key)
19
+
20
+ # User input
21
+ user_input = st.text_input("Ask something:")
22
+
23
+ if st.button("Send"):
24
+ if user_input.strip() == "":
25
+ st.warning("Please type a message.")
26
+ else:
27
+ with st.spinner("Thinking..."):
28
+ try:
29
+ chat_completion = client.chat.completions.create(
30
+ messages=[
31
+ {
32
+ "role": "user",
33
+ "content": user_input,
34
+ }
35
+ ],
36
+ model="llama-3.3-70b-versatile",
37
+ )
38
+
39
+ response = chat_completion.choices[0].message.content
40
+ st.success("Response:")
41
+ st.write(response)
42
+
43
+ except Exception as e:
44
+ st.error(f"Error: {e}")