Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,13 +8,11 @@ openai.api_base = "https://api.groq.com/openai/v1"
|
|
8 |
|
9 |
# Function to get response from GROQ API
|
10 |
def get_groq_response(message, category):
|
11 |
-
# Define system message based on category
|
12 |
system_messages = {
|
13 |
"Study Tips": "Provide effective study strategies, time management advice, and tips for staying organized and focused.",
|
14 |
"Exam Preparation": "Offer tips for preparing for exams, managing anxiety, and optimizing performance on test day.",
|
15 |
"Project Guidance": "Provide advice on how to tackle academic projects, group assignments, and presentations effectively.",
|
16 |
"Stress Management": "Offer calming techniques and advice to handle stress effectively.",
|
17 |
-
# (Continue with all other categories...)
|
18 |
"Friendly Buddy": "Respond as a supportive and fun friend. Be informal, cheerful, and light-hearted."
|
19 |
}
|
20 |
system_message = system_messages.get(category, "Respond appropriately to the user's input.")
|
@@ -37,7 +35,7 @@ def chatbot(user_input, category, history=[]):
|
|
37 |
history.append((f"You: {user_input}", f"Bot: {bot_response}"))
|
38 |
return history, history
|
39 |
|
40 |
-
#
|
41 |
categories = {
|
42 |
"Academic Support": [
|
43 |
"Study Tips", "Exam Preparation", "Project Guidance", "Time Management", "Building Confidence"
|
@@ -57,12 +55,8 @@ categories = {
|
|
57 |
]
|
58 |
}
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
with gr.Blocks(css="""
|
64 |
-
/* Add custom CSS here */
|
65 |
-
""") as chat_interface:
|
66 |
with gr.Row():
|
67 |
gr.Markdown("<h1 style='text-align:center;'>π Vibrant Personal Assistant Chatbot π</h1>")
|
68 |
|
@@ -77,11 +71,14 @@ with gr.Blocks(css="""
|
|
77 |
)
|
78 |
sub_category = gr.Dropdown(
|
79 |
label="Subcategory",
|
80 |
-
choices=
|
|
|
81 |
)
|
82 |
|
83 |
-
def update_subcategories(
|
84 |
-
|
|
|
|
|
85 |
|
86 |
main_category.change(update_subcategories, inputs=main_category, outputs=sub_category)
|
87 |
|
@@ -92,11 +89,10 @@ with gr.Blocks(css="""
|
|
92 |
with gr.Row():
|
93 |
chatbot_output = gr.Chatbot(label="Chat History")
|
94 |
|
95 |
-
|
96 |
-
def handle_chat(user_input, category, history):
|
97 |
if not user_input.strip():
|
98 |
return history, history
|
99 |
-
updated_history, _ = chatbot(user_input,
|
100 |
return updated_history, updated_history
|
101 |
|
102 |
send_button.click(
|
|
|
8 |
|
9 |
# Function to get response from GROQ API
|
10 |
def get_groq_response(message, category):
|
|
|
11 |
system_messages = {
|
12 |
"Study Tips": "Provide effective study strategies, time management advice, and tips for staying organized and focused.",
|
13 |
"Exam Preparation": "Offer tips for preparing for exams, managing anxiety, and optimizing performance on test day.",
|
14 |
"Project Guidance": "Provide advice on how to tackle academic projects, group assignments, and presentations effectively.",
|
15 |
"Stress Management": "Offer calming techniques and advice to handle stress effectively.",
|
|
|
16 |
"Friendly Buddy": "Respond as a supportive and fun friend. Be informal, cheerful, and light-hearted."
|
17 |
}
|
18 |
system_message = system_messages.get(category, "Respond appropriately to the user's input.")
|
|
|
35 |
history.append((f"You: {user_input}", f"Bot: {bot_response}"))
|
36 |
return history, history
|
37 |
|
38 |
+
# Categories grouped into main and subcategories
|
39 |
categories = {
|
40 |
"Academic Support": [
|
41 |
"Study Tips", "Exam Preparation", "Project Guidance", "Time Management", "Building Confidence"
|
|
|
55 |
]
|
56 |
}
|
57 |
|
58 |
+
# Gradio Interface with grouped categories
|
59 |
+
with gr.Blocks() as chat_interface:
|
|
|
|
|
|
|
|
|
60 |
with gr.Row():
|
61 |
gr.Markdown("<h1 style='text-align:center;'>π Vibrant Personal Assistant Chatbot π</h1>")
|
62 |
|
|
|
71 |
)
|
72 |
sub_category = gr.Dropdown(
|
73 |
label="Subcategory",
|
74 |
+
choices=categories["Academic Support"],
|
75 |
+
value="Study Tips"
|
76 |
)
|
77 |
|
78 |
+
def update_subcategories(selected_main_category):
|
79 |
+
"""Update the subcategory dropdown based on the main category."""
|
80 |
+
new_subcategories = categories.get(selected_main_category, [])
|
81 |
+
return gr.Dropdown.update(choices=new_subcategories, value=new_subcategories[0] if new_subcategories else None)
|
82 |
|
83 |
main_category.change(update_subcategories, inputs=main_category, outputs=sub_category)
|
84 |
|
|
|
89 |
with gr.Row():
|
90 |
chatbot_output = gr.Chatbot(label="Chat History")
|
91 |
|
92 |
+
def handle_chat(user_input, sub_category, history):
|
|
|
93 |
if not user_input.strip():
|
94 |
return history, history
|
95 |
+
updated_history, _ = chatbot(user_input, sub_category, history)
|
96 |
return updated_history, updated_history
|
97 |
|
98 |
send_button.click(
|