Spaces:
Sleeping
Sleeping
| # app.py | |
| import os | |
| import streamlit as st | |
| from groq import Groq | |
| # Set your GROQ API Key here directly (since in Colab it's easier) | |
| GROQ_API_KEY = "your-groq-api-key-here" # <-- Replace with your key | |
| # Create the GROQ client | |
| client = Groq( | |
| api_key=GROQ_API_KEY, | |
| ) | |
| # Streamlit app | |
| st.title("🤖 Chatbot using GROQ API") | |
| # Store the conversation | |
| if "messages" not in st.session_state: | |
| st.session_state.messages = [] | |
| # Display old messages | |
| for message in st.session_state.messages: | |
| if message["role"] == "user": | |
| with st.chat_message("user"): | |
| st.write(message["content"]) | |
| else: | |
| with st.chat_message("assistant"): | |
| st.write(message["content"]) | |
| # Input from user | |
| user_input = st.chat_input("Type your message...") | |
| if user_input: | |
| # Save user message | |
| st.session_state.messages.append({"role": "user", "content": user_input}) | |
| # Send all messages to model | |
| chat_completion = client.chat.completions.create( | |
| messages=st.session_state.messages, | |
| model="llama-3-3-70b-versatile", | |
| ) | |
| # Get model's reply | |
| reply = chat_completion.choices[0].message.content | |
| # Save assistant reply | |
| st.session_state.messages.append({"role": "assistant", "content": reply}) | |
| # Display assistant reply | |
| with st.chat_message("assistant"): | |
| st.write(reply) | |