File size: 1,398 Bytes
330ebf8
 
 
 
 
 
 
1820566
330ebf8
 
 
1820566
330ebf8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b6da6ca
330ebf8
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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}")