Chatbot / app.py
saherPervaiz's picture
Update app.py
556ffec verified
raw
history blame
917 Bytes
import os
import streamlit as st
from groq import * # Import everything from groq, so you can access the chat functionality
# Ensure you have the correct API key set in the environment variable
api_key = "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"
# Streamlit interface
st.title("AI Chatbot with Groq")
user_input = st.text_input("Ask something:", "")
if user_input:
try:
# Create the Groq client using the API key
client = Groq(api_key=api_key)
# Create chat completion with user input
chat_completion = client.chat.completions.create(
messages=[{"role": "user", "content": user_input}],
model="llama-3.3-70b-versatile"
)
# Display the response
st.write("AI's response: ")
st.write(chat_completion.choices[0].message.content)
except Exception as e:
st.error(f"Error: {e}")