Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -55,44 +55,60 @@ def chatbot(user_input, history=[]):
|
|
55 |
category = recognize_category(user_input) # Determine the category based on user input
|
56 |
bot_response = get_groq_response(user_input, category)
|
57 |
history.append((category, user_input, bot_response)) # Save category, user input, and bot response
|
58 |
-
return history
|
59 |
|
60 |
-
# Gradio Interface setup with
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
gr.Textbox(label="Your Message"), # User input
|
65 |
-
"state" # History
|
66 |
-
],
|
67 |
-
outputs=["chatbot", "state"],
|
68 |
-
live=False,
|
69 |
-
title="Meet your Personal Assistant: Your Helpful and Caring Chatbot",
|
70 |
-
description="This chatbot is here to help you with anything you need, whether it’s answering questions, offering support, or guiding you through tasks. With a friendly and empathetic approach, it listens carefully to your concerns and provides thoughtful, understanding responses. Whether you’re seeking information or just someone to chat with, our chatbot is designed to make you feel heard and supported. It’s more than just a tool—it’s a companion dedicated to making your day easier and more enjoyable.",
|
71 |
-
layout="vertical"
|
72 |
-
)
|
73 |
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
80 |
|
81 |
-
|
82 |
-
if category == "Stress Management":
|
83 |
-
stress_responses.append(f"**User**: {user_input}\n**Bot**: {bot_response}")
|
84 |
-
elif category == "Career Advice":
|
85 |
-
career_responses.append(f"**User**: {user_input}\n**Bot**: {bot_response}")
|
86 |
-
elif category == "General":
|
87 |
-
general_responses.append(f"**User**: {user_input}\n**Bot**: {bot_response}")
|
88 |
-
elif category == "Friendly Buddy":
|
89 |
-
friendly_responses.append(f"**User**: {user_input}\n**Bot**: {bot_response}")
|
90 |
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
gr.Column([gr.Markdown(f"### Friendly Buddy\n{response}") for response in friendly_responses])
|
96 |
-
]
|
97 |
|
98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
category = recognize_category(user_input) # Determine the category based on user input
|
56 |
bot_response = get_groq_response(user_input, category)
|
57 |
history.append((category, user_input, bot_response)) # Save category, user input, and bot response
|
58 |
+
return history
|
59 |
|
60 |
+
# Gradio Interface setup with Blocks for custom layout
|
61 |
+
with gr.Blocks() as demo:
|
62 |
+
gr.Markdown("## Meet your Personal Assistant: Your Helpful and Caring Chatbot")
|
63 |
+
gr.Markdown("This chatbot is here to help you with anything you need, whether it’s answering questions, offering support, or guiding you through tasks. With a friendly and empathetic approach, it listens carefully to your concerns and provides thoughtful, understanding responses.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
+
with gr.Row():
|
66 |
+
user_input = gr.Textbox(label="Your Message", placeholder="Type your message here...")
|
67 |
+
submit_button = gr.Button("Submit")
|
68 |
+
|
69 |
+
history = gr.State([])
|
70 |
+
stress_column = gr.Column()
|
71 |
+
career_column = gr.Column()
|
72 |
+
general_column = gr.Column()
|
73 |
+
friendly_column = gr.Column()
|
74 |
|
75 |
+
output_area = gr.Row([stress_column, career_column, general_column, friendly_column])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
+
def process_input(user_input, history):
|
78 |
+
category = recognize_category(user_input)
|
79 |
+
bot_response = get_groq_response(user_input, category)
|
80 |
+
history.append((category, user_input, bot_response))
|
|
|
|
|
81 |
|
82 |
+
# Organize responses by category
|
83 |
+
stress_responses = []
|
84 |
+
career_responses = []
|
85 |
+
general_responses = []
|
86 |
+
friendly_responses = []
|
87 |
+
|
88 |
+
for cat, user_msg, bot_msg in history:
|
89 |
+
response = f"**User**: {user_msg}\n**Bot**: {bot_msg}"
|
90 |
+
if cat == "Stress Management":
|
91 |
+
stress_responses.append(response)
|
92 |
+
elif cat == "Career Advice":
|
93 |
+
career_responses.append(response)
|
94 |
+
elif cat == "General":
|
95 |
+
general_responses.append(response)
|
96 |
+
elif cat == "Friendly Buddy":
|
97 |
+
friendly_responses.append(response)
|
98 |
+
|
99 |
+
# Update the columns
|
100 |
+
return {
|
101 |
+
stress_column: "\n\n".join(stress_responses) or "No responses yet.",
|
102 |
+
career_column: "\n\n".join(career_responses) or "No responses yet.",
|
103 |
+
general_column: "\n\n".join(general_responses) or "No responses yet.",
|
104 |
+
friendly_column: "\n\n".join(friendly_responses) or "No responses yet.",
|
105 |
+
history: history
|
106 |
+
}
|
107 |
+
|
108 |
+
submit_button.click(
|
109 |
+
fn=process_input,
|
110 |
+
inputs=[user_input, history],
|
111 |
+
outputs=[stress_column, career_column, general_column, friendly_column, history]
|
112 |
+
)
|
113 |
+
|
114 |
+
demo.launch()
|