Spaces:
Runtime error
Runtime error
invincible-jha
commited on
Commit
Β·
8e60da3
1
Parent(s):
5a6069c
Fix Gradio 5.8.0 compatibility issues
Browse files- 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 |
-
|
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 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
self.
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
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
|
118 |
-
history
|
119 |
-
history.append(
|
120 |
|
121 |
return history
|
122 |
|
123 |
except Exception as e:
|
124 |
self.logger.error(f"Error processing input: {str(e)}")
|
125 |
-
|
126 |
-
|
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 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
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"""
|