Chatbot / app.py
saherPervaiz's picture
Update app.py
0ccf2c7 verified
raw
history blame
1.66 kB
import os
import streamlit as st
from groq import Groq # Correct import for the Groq client
# Ensure the correct API key is set in the environment
api_key = "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"
# Streamlit interface
st.title("AI Chatbot with Groq")
# User input for the chatbot
user_input = st.text_input("Ask something:", "")
# Scholarship search option
search_scholarships = st.checkbox("Search for scholarships")
# If user asked about scholarships
if search_scholarships:
st.write("You can explore various scholarships for your education:")
st.write("1. **Merit-based Scholarships**: Awarded based on academic performance.")
st.write("2. **Need-based Scholarships**: For students who need financial assistance.")
st.write("3. **Athletic Scholarships**: Given to students excelling in sports.")
st.write("4. **Government Scholarships**: Offered by governments for local or international students.")
st.write("5. **Private Scholarships**: Funded by organizations or businesses.")
# Process user input to interact with the Groq API
if user_input and not search_scholarships:
try:
# Initialize Groq client with the API key
client = Groq(api_key=api_key)
# Create a chat completion request using the user's input
chat_completion = client.chat.completions.create(
messages=[{"role": "user", "content": user_input}],
model="llama-3.3-70b-versatile"
)
# Display the AI's response
st.write("AI's response: ")
st.write(chat_completion.choices[0].message.content)
except Exception as e:
st.error(f"Error: {e}")