Spaces:
Sleeping
Sleeping
Download old_2_app.py from DanishShahzad/Sample_ChatBot: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/spaces/DanishShahzad/Sample_ChatBot/resolve/main/old_2_app.py
- Command line
-
hf download hf://spaces/DanishShahzad/Sample_ChatBot/old_2_app.py
-
curl -L -o old_2_app.py https://huggingface.co/spaces/DanishShahzad/Sample_ChatBot/resolve/main/old_2_app.py
1.3 kB
| # 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}") | |