Spaces:
Sleeping
Sleeping
| import os | |
| import streamlit as st | |
| from groq import Groq | |
| from dotenv import load_dotenv | |
| # Load environment variables from .env file | |
| load_dotenv() | |
| # Get API key from .env | |
| GROQ_API_KEY = os.getenv("GROQ_API_KEY") | |
| # Streamlit UI | |
| st.title("Hugging Face & GROQ API Chatbot") | |
| st.write("Enter a message below to interact with the AI.") | |
| # User input | |
| user_input = st.text_area("Your Message", "Explain the importance of fast language models") | |
| if st.button("Generate Response"): | |
| if not GROQ_API_KEY: | |
| st.error("API Key is missing. Please check your .env file.") | |
| else: | |
| try: | |
| # Initialize GROQ client | |
| client = Groq(api_key=GROQ_API_KEY) | |
| # Generate response | |
| chat_completion = client.chat.completions.create( | |
| messages=[{"role": "user", "content": user_input}], | |
| model="llama-3.3-70b-versatile", | |
| ) | |
| # Display response | |
| response = chat_completion.choices[0].message.content | |
| st.write("### AI Response:") | |
| st.write(response) | |
| except Exception as e: | |
| st.error(f"Error: {e}") | |