Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,40 +8,52 @@ 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 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
try:
|
47 |
response = openai.ChatCompletion.create(
|
@@ -61,28 +73,57 @@ def chatbot(user_input, category, history=[]):
|
|
61 |
history.append((f"You: {user_input}", f"Bot: {bot_response}"))
|
62 |
return history, history
|
63 |
|
64 |
-
#
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
-
|
85 |
-
with gr.Blocks() as chat_interface:
|
86 |
with gr.Row():
|
87 |
gr.Markdown("<h1 style='text-align:center;'>🌟 Vibrant Personal Assistant Chatbot 🌈</h1>")
|
88 |
|
@@ -90,42 +131,37 @@ with gr.Blocks() as chat_interface:
|
|
90 |
gr.Markdown("<p style='text-align:center;'>Select a category and type your message to get tailored responses.</p>")
|
91 |
|
92 |
with gr.Row():
|
93 |
-
|
94 |
-
|
95 |
-
choices=
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
|
|
102 |
)
|
103 |
-
|
104 |
-
def update_subcategories(selected_main_category):
|
105 |
-
"""Update the subcategory dropdown based on the main category."""
|
106 |
-
new_subcategories = categories.get(selected_main_category, [])
|
107 |
-
return gr.update(choices=new_subcategories, value=new_subcategories[0] if new_subcategories else None)
|
108 |
-
|
109 |
-
# Handle main category change to update subcategories
|
110 |
-
main_category.change(update_subcategories, inputs=main_category, outputs=sub_category)
|
111 |
-
|
112 |
with gr.Row():
|
113 |
-
user_input = gr.Textbox(label="Your Message", placeholder="Type something...", lines=2)
|
114 |
send_button = gr.Button("Send")
|
115 |
-
|
116 |
with gr.Row():
|
117 |
-
|
|
|
118 |
|
119 |
-
|
|
|
120 |
if not user_input.strip():
|
121 |
return history, history
|
122 |
-
updated_history, _ = chatbot(user_input,
|
123 |
return updated_history, updated_history
|
124 |
|
125 |
send_button.click(
|
126 |
handle_chat,
|
127 |
-
inputs=[user_input,
|
128 |
outputs=[chatbot_output, chatbot_output]
|
129 |
)
|
130 |
|
131 |
chat_interface.launch()
|
|
|
|
8 |
|
9 |
# Function to get response from GROQ API
|
10 |
def get_groq_response(message, category):
|
11 |
+
system_message = ""
|
12 |
+
|
13 |
+
if category == "Study Tips":
|
14 |
+
system_message = "Provide effective study strategies, time management advice, and tips for staying organized and focused."
|
15 |
+
elif category == "Exam Preparation":
|
16 |
+
system_message = "Offer tips for preparing for exams, managing anxiety, and optimizing performance on test day."
|
17 |
+
elif category == "Project Guidance":
|
18 |
+
system_message = "Provide advice on how to tackle academic projects, group assignments, and presentations effectively."
|
19 |
+
elif category == "Time Management":
|
20 |
+
system_message = "Help the user manage their time effectively with practical scheduling and prioritization tips."
|
21 |
+
elif category == "Motivation & Focus":
|
22 |
+
system_message = "Provide encouraging advice to stay motivated and maintain focus on long-term goals."
|
23 |
+
elif category == "Building Confidence":
|
24 |
+
system_message = "Offer advice to help boost self-esteem, overcome self-doubt, and build confidence."
|
25 |
+
elif category == "Friendship & Social Skills":
|
26 |
+
system_message = "Provide tips for making friends, improving communication skills, and navigating social dynamics."
|
27 |
+
elif category == "Networking & Career Building":
|
28 |
+
system_message = "Offer advice on networking, building professional relationships, and finding internships or job opportunities."
|
29 |
+
elif category == "Work-Life Balance":
|
30 |
+
system_message = "Help the user balance academics, social life, and personal well-being."
|
31 |
+
elif category == "Mental Health":
|
32 |
+
system_message = "Provide empathetic advice to manage stress, anxiety, and other mental health challenges. Encourage seeking professional help when needed."
|
33 |
+
elif category == "Physical Health":
|
34 |
+
system_message = "Share tips for maintaining physical health, including fitness, sleep, and nutrition."
|
35 |
+
elif category == "Stress Management":
|
36 |
+
system_message = "Offer calming techniques and advice to handle stress effectively."
|
37 |
+
elif category == "Budgeting Tips":
|
38 |
+
system_message = "Provide practical advice for managing money, creating a budget, and saving effectively as a student."
|
39 |
+
elif category == "Finding Part-Time Jobs":
|
40 |
+
system_message = "Share tips for finding and balancing part-time work with academic responsibilities."
|
41 |
+
elif category == "Scholarships & Financial Aid":
|
42 |
+
system_message = "Provide advice on applying for scholarships, grants, and understanding financial aid options."
|
43 |
+
elif category == "Resume Building":
|
44 |
+
system_message = "Offer tips for creating an impressive resume tailored for internships or entry-level positions."
|
45 |
+
elif category == "Interview Preparation":
|
46 |
+
system_message = "Provide advice on how to prepare for interviews, including common questions and presentation tips."
|
47 |
+
elif category == "Skill Development":
|
48 |
+
system_message = "Suggest ways to build skills, gain certifications, and stand out in competitive fields."
|
49 |
+
elif category == "Exploring New Hobbies":
|
50 |
+
system_message = "Encourage trying new activities and provide ideas for hobbies that fit college life."
|
51 |
+
elif category == "Clubs & Extracurriculars":
|
52 |
+
system_message = "Offer advice on joining clubs, participating in activities, and enhancing the college experience."
|
53 |
+
elif category == "Creative Projects":
|
54 |
+
system_message = "Provide inspiration and resources for personal or group creative endeavors."
|
55 |
+
else:
|
56 |
+
system_message = "Category not recognized. Respond appropriately to the user's input."
|
57 |
|
58 |
try:
|
59 |
response = openai.ChatCompletion.create(
|
|
|
73 |
history.append((f"You: {user_input}", f"Bot: {bot_response}"))
|
74 |
return history, history
|
75 |
|
76 |
+
# Gradio Interface with enhanced styling
|
77 |
+
chat_interface = gr.Blocks(css="""
|
78 |
+
body {
|
79 |
+
font-family: 'Poppins', sans-serif;
|
80 |
+
background: linear-gradient(120deg, #ff9a9e, #fad0c4, #a1c4fd);
|
81 |
+
animation: gradientBG 10s ease infinite;
|
82 |
+
margin: 0;
|
83 |
+
padding: 0;
|
84 |
+
color: #333;
|
85 |
+
}
|
86 |
+
@keyframes gradientBG {
|
87 |
+
0% { background-position: 0% 50%; }
|
88 |
+
50% { background-position: 100% 50%; }
|
89 |
+
100% { background-position: 0% 50%; }
|
90 |
+
}
|
91 |
+
button {
|
92 |
+
background: linear-gradient(90deg, #6a11cb, #2575fc);
|
93 |
+
color: white;
|
94 |
+
padding: 0.8rem 1.5rem;
|
95 |
+
font-size: 1rem;
|
96 |
+
font-weight: bold;
|
97 |
+
border-radius: 20px;
|
98 |
+
border: none;
|
99 |
+
cursor: pointer;
|
100 |
+
transition: transform 0.2s ease, background 0.2s ease;
|
101 |
+
}
|
102 |
+
button:hover {
|
103 |
+
background: linear-gradient(90deg, #2575fc, #6a11cb);
|
104 |
+
transform: scale(1.1);
|
105 |
}
|
106 |
+
header {
|
107 |
+
text-align: center;
|
108 |
+
margin-bottom: 20px;
|
109 |
+
padding: 10px;
|
110 |
+
border-radius: 15px;
|
111 |
+
background: linear-gradient(90deg, #ff758c, #ff7eb3);
|
112 |
+
color: white;
|
113 |
+
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
|
114 |
+
}
|
115 |
+
.chat-container {
|
116 |
+
border: 2px solid #ff7eb3;
|
117 |
+
background: rgba(255, 255, 255, 0.8);
|
118 |
+
border-radius: 15px;
|
119 |
+
padding: 15px;
|
120 |
+
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
|
121 |
+
max-height: 300px;
|
122 |
+
overflow-y: auto;
|
123 |
+
}
|
124 |
+
""")
|
125 |
|
126 |
+
with chat_interface:
|
|
|
127 |
with gr.Row():
|
128 |
gr.Markdown("<h1 style='text-align:center;'>🌟 Vibrant Personal Assistant Chatbot 🌈</h1>")
|
129 |
|
|
|
131 |
gr.Markdown("<p style='text-align:center;'>Select a category and type your message to get tailored responses.</p>")
|
132 |
|
133 |
with gr.Row():
|
134 |
+
user_input = gr.Textbox(label="Your Message", placeholder="Type something...", lines=2)
|
135 |
+
category_dropdown = gr.Dropdown(
|
136 |
+
choices=[
|
137 |
+
"Study Tips", "Exam Preparation", "Project Guidance", "Time Management", "Motivation & Focus",
|
138 |
+
"Building Confidence", "Friendship & Social Skills", "Networking & Career Building", "Work-Life Balance",
|
139 |
+
"Mental Health", "Physical Health", "Stress Management", "Budgeting Tips", "Finding Part-Time Jobs",
|
140 |
+
"Scholarships & Financial Aid", "Resume Building", "Interview Preparation", "Skill Development",
|
141 |
+
"Exploring New Hobbies", "Clubs & Extracurriculars", "Creative Projects"
|
142 |
+
],
|
143 |
+
label="Choose Chat Category"
|
144 |
)
|
145 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
with gr.Row():
|
|
|
147 |
send_button = gr.Button("Send")
|
148 |
+
|
149 |
with gr.Row():
|
150 |
+
with gr.Column() as chat_container:
|
151 |
+
chatbot_output = gr.Chatbot(label="Chat History")
|
152 |
|
153 |
+
# Add functionality to handle interactions
|
154 |
+
def handle_chat(user_input, category, history):
|
155 |
if not user_input.strip():
|
156 |
return history, history
|
157 |
+
updated_history, _ = chatbot(user_input, category, history)
|
158 |
return updated_history, updated_history
|
159 |
|
160 |
send_button.click(
|
161 |
handle_chat,
|
162 |
+
inputs=[user_input, category_dropdown, chatbot_output],
|
163 |
outputs=[chatbot_output, chatbot_output]
|
164 |
)
|
165 |
|
166 |
chat_interface.launch()
|
167 |
+
|