import os import streamlit as st from groq import Groq from dotenv import load_dotenv # Load environment variables load_dotenv() GROQ_API_KEY = os.getenv("GROQ_API_KEY") if not GROQ_API_KEY: st.error("GROQ_API_KEY not found. Please set it before running the app.") st.stop() # Initialize the Groq client client = Groq(api_key=GROQ_API_KEY) def get_groq_response(user_input): try: chat_completion = client.chat.completions.create( messages=[ {"role": "user", "content": user_input} ], model="llama-3.3-70b-versatile", ) return chat_completion.choices[0].message.content except Exception as e: return f"Error: {str(e)}" # Streamlit UI st.title("Hugging Face + GROQ API Chatbot") user_input = st.text_area("Enter your message:") if st.button("Generate Response"): if user_input: response = get_groq_response(user_input) st.write("**GROQ Response:**") st.write(response) else: st.warning("Please enter a message before submitting.")