chatbot / app.py
devfire's picture
Update app.py
ca57036 verified
raw
history blame
1.43 kB
import os
import streamlit as st
from groq import Groq
# Set up the Groq API Key
GROQ_API_KEY = "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"
os.environ["GROQ_API_KEY"] = GROQ_API_KEY
# Initialize the Groq client
client = Groq(api_key=GROQ_API_KEY)
# Streamlit user interface
st.title("AI Study Assistant Chatbot")
st.write("Hello! I'm your AI Study Assistant. You can ask me anything related to your studies or exam preparation.")
# User input for conversation
user_input = st.text_input("Ask me anything about your study plan or exam:")
# Function to generate chatbot response based on user input
def generate_chatbot_response(user_message):
# Generate prompt for Groq based on user message
prompt = f"You are a helpful AI chatbot. The user is asking: {user_message}. Provide a detailed, helpful response."
# Generate response using Groq API
chat_completion = client.chat.completions.create(
messages=[{"role": "user", "content": prompt}],
model="llama3-8b-8192", # You can replace with the appropriate model name
)
response = chat_completion.choices[0].message.content
return response
# Display chatbot response when user submits a message
if user_input:
chatbot_response = generate_chatbot_response(user_input)
st.write("### Chatbot Response:")
st.write(chatbot_response)
else:
st.write("Please ask me a question about your study plan or exam.")