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

Fix Gradio 5.8.0 chatbot format and launch parameters

Browse files
Files changed (2) hide show
  1. app.py +25 -13
  2. interface/app.py +14 -5
app.py CHANGED
@@ -1,21 +1,33 @@
1
- import gradio as gr
2
  from interface.app import WellnessInterface
3
  from config.config import load_config
 
 
4
 
5
  def main():
6
- # Load configuration
7
- config = load_config()
 
 
8
 
9
- # Initialize interface
10
- interface = WellnessInterface(config)
11
-
12
- # Launch the application
13
- interface.launch(
14
- share=True,
15
- enable_queue=True,
16
- server_name="0.0.0.0",
17
- server_port=7860
18
- )
 
 
 
 
 
 
 
 
 
19
 
20
  if __name__ == "__main__":
21
  main()
 
 
1
  from interface.app import WellnessInterface
2
  from config.config import load_config
3
+ import logging
4
+ from utils.log_manager import LogManager
5
 
6
  def main():
7
+ # Initialize logging
8
+ log_manager = LogManager()
9
+ logger = log_manager.get_agent_logger("main")
10
+ logger.info("Starting Mental Wellness Platform")
11
 
12
+ try:
13
+ # Load configuration
14
+ config = load_config()
15
+ logger.info("Configuration loaded successfully")
16
+
17
+ # Initialize interface
18
+ interface = WellnessInterface(config)
19
+ logger.info("Interface initialized")
20
+
21
+ # Launch the application with updated parameters
22
+ interface.launch(
23
+ share=True,
24
+ server_name="0.0.0.0",
25
+ server_port=7860
26
+ )
27
+
28
+ except Exception as e:
29
+ logger.error(f"Error starting application: {str(e)}")
30
+ raise
31
 
32
  if __name__ == "__main__":
33
  main()
interface/app.py CHANGED
@@ -26,6 +26,7 @@ class WellnessInterface:
26
  label="Mental Wellness Assistant",
27
  height=400,
28
  value=[],
 
29
  elem_id="wellness_chat"
30
  )
31
 
@@ -109,16 +110,20 @@ class WellnessInterface:
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):
@@ -130,16 +135,20 @@ class WellnessInterface:
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"""
144
  self.logger.info("Launching interface")
 
145
  self.interface.launch(**kwargs)
 
26
  label="Mental Wellness Assistant",
27
  height=400,
28
  value=[],
29
+ type="messages",
30
  elem_id="wellness_chat"
31
  )
32
 
 
110
  # Process the input (placeholder)
111
  response = "I understand and I'm here to help. Could you tell me more about how you're feeling?"
112
 
113
+ # Add to chat history using message format
114
  history = history or []
115
+ history.append({"role": "user", "content": text if text else "Sent media"})
116
+ history.append({"role": "assistant", "content": response})
117
 
118
  return history
119
 
120
  except Exception as e:
121
  self.logger.error(f"Error processing input: {str(e)}")
122
  history = history or []
123
+ history.append({
124
+ "role": "assistant",
125
+ "content": "I apologize, but I encountered an error. Please try again."
126
+ })
127
  return history
128
 
129
  def clear_chat(self):
 
135
  """Provide emergency help information"""
136
  self.logger.info("Emergency help requested")
137
 
138
+ return [{
139
+ "role": "assistant",
140
+ "content": """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
  def launch(self, **kwargs):
151
  """Launch the interface"""
152
  self.logger.info("Launching interface")
153
+ kwargs.pop('enable_queue', None)
154
  self.interface.launch(**kwargs)