Spaces:
Build error
Build error
| import os | |
| import streamlit as st | |
| from groq import Groq | |
| from dotenv import load_dotenv | |
| # Load environment variables from .env file | |
| load_dotenv() | |
| # Retrieve API key | |
| api_key = os.getenv("GROQ_API_KEY") | |
| # Initialize Groq client | |
| client = Groq(api_key=api_key) | |
| # Streamlit UI | |
| st.title("GROQ AI Chatbot") | |
| # User input | |
| user_input = st.text_input("Ask me anything:") | |
| if st.button("Submit"): | |
| if not api_key: | |
| st.error("API Key is missing. Please check your .env file.") | |
| elif not user_input: | |
| st.warning("Please enter a question.") | |
| else: | |
| try: | |
| response = client.chat.completions.create( | |
| messages=[{"role": "user", "content": user_input}], | |
| model="llama-3.3-70b-versatile", | |
| ) | |
| st.write("### Response:") | |
| st.write(response.choices[0].message.content) | |
| except Exception as e: | |
| st.error(f"Error: {e}") | |