Update app.py
Browse files
app.py
CHANGED
@@ -10,17 +10,30 @@ os.environ["GROQ_API_KEY"] = GROQ_API_KEY
|
|
10 |
client = Groq(api_key=GROQ_API_KEY)
|
11 |
|
12 |
# Streamlit user interface setup
|
13 |
-
st.title("AI Chatbot")
|
14 |
-
st.write("Hello! I'm your AI Study Assistant.
|
15 |
|
16 |
# Initialize session state for maintaining conversation
|
17 |
if 'conversation_history' not in st.session_state:
|
18 |
st.session_state.conversation_history = []
|
19 |
|
20 |
-
#
|
|
|
|
|
|
|
21 |
def generate_chatbot_response(user_message):
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
23 |
|
|
|
|
|
|
|
|
|
|
|
24 |
# Generate response using Groq API
|
25 |
chat_completion = client.chat.completions.create(
|
26 |
messages=[{"role": "user", "content": prompt}],
|
@@ -31,7 +44,7 @@ def generate_chatbot_response(user_message):
|
|
31 |
return response
|
32 |
|
33 |
# User input for conversation
|
34 |
-
user_input = st.text_input("Ask me
|
35 |
|
36 |
# Handle user input and display conversation
|
37 |
if user_input:
|
|
|
10 |
client = Groq(api_key=GROQ_API_KEY)
|
11 |
|
12 |
# Streamlit user interface setup
|
13 |
+
st.title("Subject-specific AI Chatbot")
|
14 |
+
st.write("Hello! I'm your AI Study Assistant. You can ask me any questions related to your subjects, and I'll try to help.")
|
15 |
|
16 |
# Initialize session state for maintaining conversation
|
17 |
if 'conversation_history' not in st.session_state:
|
18 |
st.session_state.conversation_history = []
|
19 |
|
20 |
+
# Define a list of subjects for which the chatbot will answer
|
21 |
+
subjects = ["Chemistry", "Computer", "English", "Islamiat", "Mathematics", "Physics", "Urdu"]
|
22 |
+
|
23 |
+
# Function to generate chatbot response based on subject-specific user input
|
24 |
def generate_chatbot_response(user_message):
|
25 |
+
# Check if the user's question is related to any subject
|
26 |
+
related_subject = None
|
27 |
+
for subject in subjects:
|
28 |
+
if subject.lower() in user_message.lower():
|
29 |
+
related_subject = subject
|
30 |
+
break
|
31 |
|
32 |
+
if related_subject:
|
33 |
+
prompt = f"You are a helpful AI chatbot for studying {related_subject}. The user is asking: {user_message}. Provide a detailed, helpful response related to {related_subject}."
|
34 |
+
else:
|
35 |
+
prompt = f"You are a helpful AI chatbot. The user is asking: {user_message}. If the question is not related to any of the specified subjects (Chemistry, Computer, English, Islamiat, Mathematics, Physics, Urdu), politely let them know."
|
36 |
+
|
37 |
# Generate response using Groq API
|
38 |
chat_completion = client.chat.completions.create(
|
39 |
messages=[{"role": "user", "content": prompt}],
|
|
|
44 |
return response
|
45 |
|
46 |
# User input for conversation
|
47 |
+
user_input = st.text_input("Ask me a subject-related question:")
|
48 |
|
49 |
# Handle user input and display conversation
|
50 |
if user_input:
|