arpit13 commited on
Commit
4bde0d5
·
verified ·
1 Parent(s): b9a3331

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +84 -15
app.py CHANGED
@@ -8,7 +8,6 @@ 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
- # System message to tailor responses based on the category
12
  system_message = ""
13
  if category == "Stress Management":
14
  system_message = "Provide soothing advice and tips to help the user manage stress. Be calm and empathetic."
@@ -34,21 +33,91 @@ def get_groq_response(message, category):
34
  # Chatbot function
35
  def chatbot(user_input, category, history=[]):
36
  bot_response = get_groq_response(user_input, category)
37
- history.append((user_input, bot_response))
38
  return history, history
39
 
40
- # Gradio Interface setup
41
- chat_interface = gr.Interface(
42
- fn=chatbot,
43
- inputs=[
44
- "text", # User input
45
- gr.Dropdown(choices=["Stress Management", "Career Advice", "General", "Friendly Buddy"], label="Choose Chat Category"), # Category selection
46
- "state" # History
47
- ],
48
- outputs=["chatbot", "state"],
49
- live=False,
50
- title="Meet your Personal Assistant: Your Helpful and Caring Chatbot",
51
- 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."
52
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
  chat_interface.launch()
 
8
 
9
  # Function to get response from GROQ API
10
  def get_groq_response(message, category):
 
11
  system_message = ""
12
  if category == "Stress Management":
13
  system_message = "Provide soothing advice and tips to help the user manage stress. Be calm and empathetic."
 
33
  # Chatbot function
34
  def chatbot(user_input, category, history=[]):
35
  bot_response = get_groq_response(user_input, category)
36
+ history.append((f"You: {user_input}", f"Bot: {bot_response}"))
37
  return history, history
38
 
39
+ # Gradio Interface with enhanced styling
40
+ chat_interface = gr.Blocks(css="""
41
+ body {
42
+ font-family: 'Poppins', sans-serif;
43
+ background: linear-gradient(120deg, #ff9a9e, #fad0c4, #a1c4fd);
44
+ animation: gradientBG 10s ease infinite;
45
+ margin: 0;
46
+ padding: 0;
47
+ color: #333;
48
+ }
49
+
50
+ @keyframes gradientBG {
51
+ 0% { background-position: 0% 50%; }
52
+ 50% { background-position: 100% 50%; }
53
+ 100% { background-position: 0% 50%; }
54
+ }
55
+
56
+ button {
57
+ background: linear-gradient(90deg, #6a11cb, #2575fc);
58
+ color: white;
59
+ padding: 0.8rem 1.5rem;
60
+ font-size: 1rem;
61
+ font-weight: bold;
62
+ border-radius: 20px;
63
+ border: none;
64
+ cursor: pointer;
65
+ transition: transform 0.2s ease, background 0.2s ease;
66
+ }
67
+
68
+ button:hover {
69
+ background: linear-gradient(90deg, #2575fc, #6a11cb);
70
+ transform: scale(1.1);
71
+ }
72
+
73
+ header {
74
+ text-align: center;
75
+ margin-bottom: 20px;
76
+ padding: 10px;
77
+ border-radius: 15px;
78
+ background: linear-gradient(90deg, #ff758c, #ff7eb3);
79
+ color: white;
80
+ box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
81
+ }
82
+
83
+ .chatbot-output {
84
+ border: 2px solid #ff7eb3;
85
+ background: rgba(255, 255, 255, 0.8);
86
+ border-radius: 15px;
87
+ padding: 15px;
88
+ box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
89
+ max-height: 300px;
90
+ overflow-y: auto;
91
+ }
92
+ """)
93
+
94
+ with chat_interface:
95
+ with gr.Row():
96
+ gr.Markdown("<h1 style='text-align:center;'>🌟 Vibrant Personal Assistant Chatbot 🌈</h1>")
97
+ with gr.Row():
98
+ gr.Markdown("<p style='text-align:center;'>Select a category and type your message to get tailored responses.</p>")
99
+ with gr.Row():
100
+ user_input = gr.Textbox(label="Your Message", placeholder="Type something...", lines=2)
101
+ category_dropdown = gr.Dropdown(
102
+ choices=["Stress Management", "Career Advice", "General", "Friendly Buddy"],
103
+ label="Choose Chat Category"
104
+ )
105
+ with gr.Row():
106
+ send_button = gr.Button("Send")
107
+ with gr.Row():
108
+ chatbot_output = gr.Chatbot(label="Chat History", css_class="chatbot-output")
109
+
110
+ # Add functionality to handle interactions
111
+ def handle_chat(user_input, category, history):
112
+ if not user_input.strip():
113
+ return history, history
114
+ updated_history, _ = chatbot(user_input, category, history)
115
+ return updated_history, updated_history
116
+
117
+ send_button.click(
118
+ handle_chat,
119
+ inputs=[user_input, category_dropdown, chatbot_output],
120
+ outputs=[chatbot_output, chatbot_output]
121
+ )
122
 
123
  chat_interface.launch()