import streamlit as st import os from groq import Groq from dotenv import load_dotenv # Load API Key from environment variable (you can also manually set below if not using .env) load_dotenv() GROQ_API_KEY = os.getenv("GROQ_API_KEY") # Fallback for direct assignment if not GROQ_API_KEY: GROQ_API_KEY = "your_groq_api_key_here" client = Groq(api_key=GROQ_API_KEY) PERSONALITY_PROMPTS = { "Shakespeare": "You are William Shakespeare. Speak in poetic Elizabethan English.", "Einstein": "You are Albert Einstein. Explain with science and clarity.", "Pirate": "You are a pirate. Use pirate slang and humor.", } st.title("🧠 Personality Chatbot with GROQ") st.markdown("Select a personality, ask your question, and get a themed response!") personality = st.selectbox("Choose a personality:", list(PERSONALITY_PROMPTS.keys())) user_input = st.text_area("Ask a question to the chatbot:") if st.button("Get Response") and user_input: messages = [ {"role": "system", "content": PERSONALITY_PROMPTS[personality]}, {"role": "user", "content": user_input}, ] try: response = client.chat.completions.create( messages=messages, model="llama-3.3-70b-versatile", ) st.markdown("### 🤖 Response:") st.write(response.choices[0].message.content) except Exception as e: st.error(f"Error: {e}")