Spaces:
Sleeping
Sleeping
| import os | |
| import streamlit as st | |
| from groq import Groq | |
| # Set up the API key (Make sure to set this in your Hugging Face Space secrets) | |
| GROQ_API_KEY = os.getenv("GROQ_API_KEY") | |
| # Initialize the Groq client | |
| client = Groq(api_key=GROQ_API_KEY) | |
| # Streamlit UI | |
| st.title("Groq Chatbot") | |
| st.write("Ask me anything!") | |
| # User input | |
| user_input = st.text_input("Enter your message:") | |
| if st.button("Send"): | |
| if user_input: | |
| try: | |
| chat_completion = client.chat.completions.create( | |
| messages=[{"role": "user", "content": user_input}], | |
| model="llama-3.3-70b-versatile", | |
| ) | |
| response = chat_completion.choices[0].message.content | |
| st.write("### Response:") | |
| st.write(response) | |
| except Exception as e: | |
| st.error(f"Error: {e}") | |
| else: | |
| st.warning("Please enter a message before sending.") | |