Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,64 +9,16 @@ openai.api_base = "https://api.groq.com/openai/v1"
|
|
9 |
# Function to get response from GROQ API
|
10 |
def get_groq_response(message, category):
|
11 |
# Define system message based on category
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
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 |
-
elif category == "Funny":
|
56 |
-
system_message = "Respond with humorous remarks and witty commentary. Be entertaining but remain respectful."
|
57 |
-
elif category == "Flirty":
|
58 |
-
system_message = "Respond playfully and with charm. Keep it light-hearted, fun, and appropriate."
|
59 |
-
elif category == "Scary":
|
60 |
-
system_message = "Respond with spooky or thrilling remarks. Set a mysterious and eerie tone."
|
61 |
-
elif category == "Business Mind":
|
62 |
-
system_message = "Respond with a sharp, professional focus. Offer strategic advice and maintain a results-driven tone."
|
63 |
-
elif category == "Extrovert":
|
64 |
-
system_message = "Respond with high energy and enthusiasm. Be engaging, sociable, and vibrant."
|
65 |
-
elif category == "Friendly Buddy":
|
66 |
-
system_message = "Respond as a supportive and fun friend. Be informal, cheerful, and light-hearted."
|
67 |
-
else:
|
68 |
-
system_message = "Category not recognized. Respond appropriately to the user's input."
|
69 |
-
|
70 |
try:
|
71 |
response = openai.ChatCompletion.create(
|
72 |
model="llama-3.1-70b-versatile",
|
@@ -85,96 +37,60 @@ def chatbot(user_input, category, history=[]):
|
|
85 |
history.append((f"You: {user_input}", f"Bot: {bot_response}"))
|
86 |
return history, history
|
87 |
|
88 |
-
# Gradio Interface with
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
padding: 0.5rem 1rem; /* Smaller button padding */
|
107 |
-
font-size: 0.9rem; /* Smaller button text */
|
108 |
-
font-weight: bold;
|
109 |
-
border-radius: 15px; /* Slightly smaller border radius */
|
110 |
-
border: none;
|
111 |
-
cursor: pointer;
|
112 |
-
transition: transform 0.2s ease, background 0.2s ease;
|
113 |
-
}
|
114 |
-
button:hover {
|
115 |
-
background: linear-gradient(90deg, #2575fc, #6a11cb);
|
116 |
-
transform: scale(1.05); /* Smaller hover effect */
|
117 |
-
}
|
118 |
-
header {
|
119 |
-
text-align: center;
|
120 |
-
margin-bottom: 20px;
|
121 |
-
padding: 10px;
|
122 |
-
border-radius: 15px;
|
123 |
-
background: linear-gradient(90deg, #ff758c, #ff7eb3);
|
124 |
-
color: white;
|
125 |
-
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
|
126 |
-
}
|
127 |
-
.chat-container {
|
128 |
-
border: 2px solid #ff7eb3;
|
129 |
-
background: rgba(255, 255, 255, 0.9); /* Slightly higher contrast for readability */
|
130 |
-
border-radius: 15px;
|
131 |
-
padding: 20px; /* Slightly larger padding for better spacing */
|
132 |
-
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
|
133 |
-
max-height: 400px; /* Increased height to show more history */
|
134 |
-
overflow-y: auto;
|
135 |
-
width: 80%; /* Wider container */
|
136 |
-
margin: 0 auto; /* Center the container */
|
137 |
-
font-size: 1rem; /* Larger font for readability */
|
138 |
-
line-height: 1.5; /* Improved line spacing for easier reading */
|
139 |
-
}
|
140 |
-
.chat-container p {
|
141 |
-
margin: 0 0 10px; /* Spacing between messages */
|
142 |
-
}
|
143 |
-
.chat-container .user-message {
|
144 |
-
color: #2575fc; /* Highlight user messages in blue */
|
145 |
-
font-weight: bold;
|
146 |
-
}
|
147 |
-
.chat-container .bot-response {
|
148 |
-
color: #6a11cb; /* Highlight bot responses in purple */
|
149 |
}
|
150 |
-
""")
|
151 |
|
|
|
|
|
152 |
|
153 |
-
|
154 |
-
|
|
|
155 |
with gr.Row():
|
156 |
gr.Markdown("<h1 style='text-align:center;'>🌟 Vibrant Personal Assistant Chatbot 🌈</h1>")
|
|
|
157 |
with gr.Row():
|
158 |
gr.Markdown("<p style='text-align:center;'>Select a category and type your message to get tailored responses.</p>")
|
|
|
159 |
with gr.Row():
|
160 |
-
|
161 |
-
|
162 |
-
choices=
|
163 |
-
|
164 |
-
"Project Guidance", "Time Management", "Motivation & Focus", "Building Confidence",
|
165 |
-
"Friendship & Social Skills", "Networking & Career Building", "Work-Life Balance",
|
166 |
-
"Mental Health", "Physical Health", "Budgeting Tips", "Finding Part-Time Jobs",
|
167 |
-
"Scholarships & Financial Aid", "Resume Building", "Interview Preparation", "Skill Development",
|
168 |
-
"Exploring New Hobbies", "Clubs & Extracurriculars", "Creative Projects", "Funny",
|
169 |
-
"Flirty", "Scary", "Business Mind", "Extrovert"
|
170 |
-
],
|
171 |
-
label="Choose Chat Category"
|
172 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
with gr.Row():
|
|
|
174 |
send_button = gr.Button("Send")
|
|
|
175 |
with gr.Row():
|
176 |
-
|
177 |
-
chatbot_output = gr.Chatbot(label="Chat History")
|
178 |
|
179 |
# Add functionality to handle interactions
|
180 |
def handle_chat(user_input, category, history):
|
@@ -185,7 +101,7 @@ with chat_interface:
|
|
185 |
|
186 |
send_button.click(
|
187 |
handle_chat,
|
188 |
-
inputs=[user_input,
|
189 |
outputs=[chatbot_output, chatbot_output]
|
190 |
)
|
191 |
|
|
|
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.")
|
21 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
try:
|
23 |
response = openai.ChatCompletion.create(
|
24 |
model="llama-3.1-70b-versatile",
|
|
|
37 |
history.append((f"You: {user_input}", f"Bot: {bot_response}"))
|
38 |
return history, history
|
39 |
|
40 |
+
# Gradio Interface with grouped categories
|
41 |
+
categories = {
|
42 |
+
"Academic Support": [
|
43 |
+
"Study Tips", "Exam Preparation", "Project Guidance", "Time Management", "Building Confidence"
|
44 |
+
],
|
45 |
+
"Mental & Physical Wellness": [
|
46 |
+
"Stress Management", "Motivation & Focus", "Mental Health", "Physical Health", "Work-Life Balance"
|
47 |
+
],
|
48 |
+
"Career & Financial": [
|
49 |
+
"Networking & Career Building", "Finding Part-Time Jobs", "Scholarships & Financial Aid",
|
50 |
+
"Resume Building", "Interview Preparation", "Budgeting Tips", "Skill Development"
|
51 |
+
],
|
52 |
+
"Social & Personal Growth": [
|
53 |
+
"Friendship & Social Skills", "Exploring New Hobbies", "Clubs & Extracurriculars", "Creative Projects"
|
54 |
+
],
|
55 |
+
"Fun & Miscellaneous": [
|
56 |
+
"Funny", "Flirty", "Scary", "Business Mind", "Extrovert", "Friendly Buddy"
|
57 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
}
|
|
|
59 |
|
60 |
+
def get_subcategories(main_category):
|
61 |
+
return categories.get(main_category, [])
|
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 |
+
|
69 |
with gr.Row():
|
70 |
gr.Markdown("<p style='text-align:center;'>Select a category and type your message to get tailored responses.</p>")
|
71 |
+
|
72 |
with gr.Row():
|
73 |
+
main_category = gr.Radio(
|
74 |
+
label="Main Category",
|
75 |
+
choices=list(categories.keys()),
|
76 |
+
value="Academic Support"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
)
|
78 |
+
sub_category = gr.Dropdown(
|
79 |
+
label="Subcategory",
|
80 |
+
choices=get_subcategories("Academic Support")
|
81 |
+
)
|
82 |
+
|
83 |
+
def update_subcategories(main_category):
|
84 |
+
return gr.Dropdown.update(choices=get_subcategories(main_category), value=None)
|
85 |
+
|
86 |
+
main_category.change(update_subcategories, inputs=main_category, outputs=sub_category)
|
87 |
+
|
88 |
with gr.Row():
|
89 |
+
user_input = gr.Textbox(label="Your Message", placeholder="Type something...", lines=2)
|
90 |
send_button = gr.Button("Send")
|
91 |
+
|
92 |
with gr.Row():
|
93 |
+
chatbot_output = gr.Chatbot(label="Chat History")
|
|
|
94 |
|
95 |
# Add functionality to handle interactions
|
96 |
def handle_chat(user_input, category, history):
|
|
|
101 |
|
102 |
send_button.click(
|
103 |
handle_chat,
|
104 |
+
inputs=[user_input, sub_category, chatbot_output],
|
105 |
outputs=[chatbot_output, chatbot_output]
|
106 |
)
|
107 |
|