0o7Hunk commited on
Commit
775cdc1
·
verified ·
1 Parent(s): 5c6d869

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from groq import Groq
3
+ import os
4
+
5
+ # API key from secrets
6
+ client = Groq(api_key=os.getenv("GROQ_API_KEY"))
7
+
8
+ st.set_page_config(page_title="AI Chatbot", page_icon="🤖")
9
+
10
+ st.title("🤖 AI Chatbot (Groq)")
11
+ st.write("Powered by Groq ⚡")
12
+
13
+ # Chat memory
14
+ if "messages" not in st.session_state:
15
+ st.session_state.messages = []
16
+
17
+ # Show messages
18
+ for msg in st.session_state.messages:
19
+ with st.chat_message(msg["role"]):
20
+ st.markdown(msg["content"])
21
+
22
+ # Input
23
+ user_input = st.chat_input("Type your message...")
24
+
25
+ if user_input:
26
+ st.session_state.messages.append({"role": "user", "content": user_input})
27
+
28
+ with st.chat_message("user"):
29
+ st.markdown(user_input)
30
+
31
+ with st.chat_message("assistant"):
32
+ with st.spinner("Thinking..."):
33
+ response = client.chat.completions.create(
34
+ model="mixtral-8x7b-32768",
35
+ messages=st.session_state.messages,
36
+ max_tokens=500
37
+ )
38
+ reply = response.choices[0].message.content
39
+ st.markdown(reply)
40
+
41
+ st.session_state.messages.append({"role": "assistant", "content": reply})