File size: 921 Bytes
517ad16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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}")