Spaces:
Sleeping
Sleeping
File size: 1,296 Bytes
5319854 2e05a87 5319854 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | # app.py
import streamlit as st
from groq_chat import chat_with_groq
st.set_page_config(page_title="Groq Chatbot", page_icon="🤖", layout="centered")
st.title("🤖 Groq Chatbot (LLaMA3-powered)")
st.markdown("Chat with a blazing-fast LLaMA model via the Groq API.")
# Initialize session state
if "chat_history" not in st.session_state:
st.session_state.chat_history = []
# Clear chat button
if st.button("🧹 Clear Chat"):
st.session_state.chat_history = []
st.rerun()
# Display previous chat
for msg in st.session_state.chat_history:
with st.chat_message(msg["role"]):
st.markdown(msg["content"])
# Chat input
prompt = st.chat_input("Type your message...")
if prompt:
# Add user message
st.session_state.chat_history.append({"role": "user", "content": prompt})
with st.chat_message("user"):
st.markdown(prompt)
# Get and display AI response
with st.spinner("Groq is thinking..."):
try:
response = chat_with_groq(prompt, history=st.session_state.chat_history)
st.session_state.chat_history.append({"role": "assistant", "content": response})
with st.chat_message("assistant"):
st.markdown(response)
except Exception as e:
st.error(f"💥 Error: {e}")
|