invincible-jha commited on
Commit
8e60da3
Β·
1 Parent(s): 5a6069c

Fix Gradio 5.8.0 compatibility issues

Browse files
Files changed (1) hide show
  1. interface/app.py +82 -93
interface/app.py CHANGED
@@ -16,78 +16,73 @@ class WellnessInterface:
16
  self.logger.info("Setting up interface components")
17
 
18
  try:
19
- # Chat interface
20
- self.chatbot = gr.Chatbot(
21
- label="Mental Wellness Assistant",
22
- type="messages", # Using new message format
23
- height=400
24
- )
25
-
26
- # Text input
27
- self.text_input = gr.Textbox(
28
- label="Type your message",
29
- placeholder="Enter your message here...",
30
- lines=2
31
- )
32
-
33
- # Audio input
34
- self.audio_input = gr.Audio(
35
- label="Voice Input",
36
- type="filepath", # Using filepath instead of source
37
- format="wav"
38
- )
39
-
40
- # Image input
41
- self.image_input = gr.Image(
42
- label="Image Upload",
43
- type="filepath"
44
- )
45
-
46
- # Control buttons
47
- self.submit_btn = gr.Button("Send")
48
- self.clear_btn = gr.Button("Clear Chat")
49
- self.emergency_btn = gr.Button("Emergency Help", variant="secondary")
50
-
51
- # Setup interface layout
52
- self.interface = gr.Interface(
53
- fn=self.process_input,
54
- inputs=[
55
- self.text_input,
56
- self.audio_input,
57
- self.image_input,
58
- self.chatbot
59
- ],
60
- outputs=[self.chatbot],
61
- title="Mental Wellness Support",
62
- description="A safe space for mental health support and guidance.",
63
- theme=self.config["INTERFACE_CONFIG"]["theme"],
64
- allow_flagging="never"
65
- )
66
-
67
- # Setup event handlers
68
- self.submit_btn.click(
69
- fn=self.process_input,
70
- inputs=[
71
- self.text_input,
72
- self.audio_input,
73
- self.image_input,
74
- self.chatbot
75
- ],
76
- outputs=[self.chatbot]
77
- )
78
-
79
- self.clear_btn.click(
80
- fn=self.clear_chat,
81
- inputs=[],
82
- outputs=[self.chatbot]
83
- )
84
-
85
- self.emergency_btn.click(
86
- fn=self.emergency_help,
87
- inputs=[],
88
- outputs=[self.chatbot]
89
- )
90
-
91
  self.logger.info("Interface setup completed successfully")
92
 
93
  except Exception as e:
@@ -114,41 +109,35 @@ class WellnessInterface:
114
  # Process the input (placeholder)
115
  response = "I understand and I'm here to help. Could you tell me more about how you're feeling?"
116
 
117
- # Add to chat history using the new message format
118
- history.append({"role": "user", "content": text if text else "Sent media"})
119
- history.append({"role": "assistant", "content": response})
120
 
121
  return history
122
 
123
  except Exception as e:
124
  self.logger.error(f"Error processing input: {str(e)}")
125
- return history + [
126
- {"role": "assistant", "content": "I apologize, but I encountered an error. Please try again."}
127
- ]
128
 
129
  def clear_chat(self):
130
  """Clear the chat history"""
131
  self.logger.info("Clearing chat history")
132
- return []
133
 
134
  def emergency_help(self):
135
  """Provide emergency help information"""
136
  self.logger.info("Emergency help requested")
137
 
138
- emergency_message = [
139
- {"role": "assistant", "content": """
140
- If you're experiencing a mental health emergency:
141
-
142
- 🚨 Emergency Services: 911 (US)
143
- πŸ†˜ National Crisis Hotline: 988
144
- πŸ’­ Crisis Text Line: Text HOME to 741741
145
-
146
- These services are available 24/7 and are staffed by trained professionals.
147
- Your life matters, and help is available.
148
- """}
149
- ]
150
-
151
- return emergency_message
152
 
153
  def launch(self, **kwargs):
154
  """Launch the interface"""
 
16
  self.logger.info("Setting up interface components")
17
 
18
  try:
19
+ with gr.Blocks(theme=gr.themes.Default()) as self.interface:
20
+ gr.Markdown("# Mental Wellness Support")
21
+ gr.Markdown("A safe space for mental health support and guidance.")
22
+
23
+ with gr.Row():
24
+ with gr.Column(scale=3):
25
+ self.chatbot = gr.Chatbot(
26
+ label="Mental Wellness Assistant",
27
+ height=400,
28
+ value=[],
29
+ elem_id="wellness_chat"
30
+ )
31
+
32
+ with gr.Row():
33
+ self.text_input = gr.Textbox(
34
+ label="Type your message",
35
+ placeholder="Enter your message here...",
36
+ lines=2,
37
+ scale=4
38
+ )
39
+ self.submit_btn = gr.Button("Send", scale=1)
40
+
41
+ with gr.Row():
42
+ self.audio_input = gr.Audio(
43
+ label="Voice Input",
44
+ type="filepath",
45
+ format="wav"
46
+ )
47
+
48
+ self.image_input = gr.Image(
49
+ label="Image Upload",
50
+ type="filepath"
51
+ )
52
+
53
+ with gr.Column(scale=1):
54
+ with gr.Group():
55
+ gr.Markdown("### Quick Actions")
56
+ self.clear_btn = gr.Button("Clear Chat")
57
+ self.emergency_btn = gr.Button(
58
+ "Emergency Help",
59
+ variant="secondary"
60
+ )
61
+
62
+ # Event handlers
63
+ self.submit_btn.click(
64
+ fn=self.process_input,
65
+ inputs=[
66
+ self.text_input,
67
+ self.audio_input,
68
+ self.image_input,
69
+ self.chatbot
70
+ ],
71
+ outputs=[self.chatbot]
72
+ )
73
+
74
+ self.clear_btn.click(
75
+ fn=self.clear_chat,
76
+ inputs=[],
77
+ outputs=[self.chatbot]
78
+ )
79
+
80
+ self.emergency_btn.click(
81
+ fn=self.emergency_help,
82
+ inputs=[],
83
+ outputs=[self.chatbot]
84
+ )
85
+
 
 
 
 
 
86
  self.logger.info("Interface setup completed successfully")
87
 
88
  except Exception as e:
 
109
  # Process the input (placeholder)
110
  response = "I understand and I'm here to help. Could you tell me more about how you're feeling?"
111
 
112
+ # Add to chat history
113
+ history = history or []
114
+ history.append([text if text else "Sent media", response])
115
 
116
  return history
117
 
118
  except Exception as e:
119
  self.logger.error(f"Error processing input: {str(e)}")
120
+ history = history or []
121
+ history.append([None, "I apologize, but I encountered an error. Please try again."])
122
+ return history
123
 
124
  def clear_chat(self):
125
  """Clear the chat history"""
126
  self.logger.info("Clearing chat history")
127
+ return None
128
 
129
  def emergency_help(self):
130
  """Provide emergency help information"""
131
  self.logger.info("Emergency help requested")
132
 
133
+ return [[None, """If you're experiencing a mental health emergency:
134
+
135
+ 🚨 Emergency Services: 911 (US)
136
+ πŸ†˜ National Crisis Hotline: 988
137
+ πŸ’­ Crisis Text Line: Text HOME to 741741
138
+
139
+ These services are available 24/7 and are staffed by trained professionals.
140
+ Your life matters, and help is available."""]]
 
 
 
 
 
 
141
 
142
  def launch(self, **kwargs):
143
  """Launch the interface"""