MY_BOT / app.py
0o7Hunk's picture
Update app.py
3f8152c verified
import streamlit as st
from groq import Groq
import os
# API key from secrets
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
st.set_page_config(page_title="AI Chatbot", page_icon="🤖")
st.title("🤖 AI Chatbot (Groq)")
st.write("Powered by Groq ⚡")
# Chat memory
if "messages" not in st.session_state:
st.session_state.messages = []
# Show messages
for msg in st.session_state.messages:
with st.chat_message(msg["role"]):
st.markdown(msg["content"])
# Input
user_input = st.chat_input("Type your message...")
if user_input:
st.session_state.messages.append({"role": "user", "content": user_input})
with st.chat_message("user"):
st.markdown(user_input)
with st.chat_message("assistant"):
with st.spinner("Thinking..."):
response = client.chat.completions.create(
model="llama-3.1-8b-instant",
messages=st.session_state.messages,
max_tokens=500
)
reply = response.choices[0].message.content
st.markdown(reply)
st.session_state.messages.append({"role": "assistant", "content": reply})