samwell Claude commited on
Commit
79ed555
·
1 Parent(s): f901e76

Fix Gradio messages format for updated HF Spaces

Browse files

- HF Spaces now uses newer Gradio requiring messages format
- Added try/except for type="messages" parameter with fallback
- Changed chat history to dict format with role/content keys
- Fixes: "Data incompatible with messages format" error

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -170,7 +170,12 @@ def chat(message, history):
170
  with gr.Blocks() as demo:
171
  gr.Markdown(f"# MedRAX2 - Medical AI Assistant\n**Device:** {device} | **Tools:** {len(tools)} loaded | **Orchestrator:** Gemini 2.0 Flash")
172
 
173
- chatbot = gr.Chatbot()
 
 
 
 
 
174
  viz_output = gr.Image(label="Grounding Visualization", visible=True)
175
 
176
  msg = gr.MultimodalTextbox(
@@ -189,11 +194,13 @@ with gr.Blocks() as demo:
189
  else:
190
  text = message
191
 
192
- # Add to chat history - use list of pairs format for older Gradio
193
  if chat_history is None:
194
  chat_history = []
195
 
196
- chat_history.append([text, bot_message])
 
 
197
 
198
  return "", chat_history, viz_image
199
 
 
170
  with gr.Blocks() as demo:
171
  gr.Markdown(f"# MedRAX2 - Medical AI Assistant\n**Device:** {device} | **Tools:** {len(tools)} loaded | **Orchestrator:** Gemini 2.0 Flash")
172
 
173
+ # Use type="messages" for newer Gradio versions on HF Spaces
174
+ try:
175
+ chatbot = gr.Chatbot(type="messages")
176
+ except TypeError:
177
+ # Fallback for older Gradio versions
178
+ chatbot = gr.Chatbot()
179
  viz_output = gr.Image(label="Grounding Visualization", visible=True)
180
 
181
  msg = gr.MultimodalTextbox(
 
194
  else:
195
  text = message
196
 
197
+ # Add to chat history - use messages format for newer Gradio
198
  if chat_history is None:
199
  chat_history = []
200
 
201
+ # Use dict format with role/content for messages type chatbot
202
+ chat_history.append({"role": "user", "content": text})
203
+ chat_history.append({"role": "assistant", "content": bot_message})
204
 
205
  return "", chat_history, viz_image
206