Fix image rendering in GradioUI and avoid forced share=True on Hugging Face Spaces
#583
by
DheerajParkash
- opened
No description provided.
This PR fixes two issues in GradioUI that affect Hugging Face Spaces users and image-generating agents:
- AgentImage outputs were displayed as Python object strings
* (FinalAnswerStep(final_answer=<AgentImage ...>)) instead of rendering as images. - share=True was always enabled, which is unnecessary (and sometimes harmful) on Hugging Face Spaces where the app is already publicly exposed.
Problem Details
Image outputs not rendered
- The agent’s final step is often wrapped in a FinalAnswerStep.
- However, stream_to_gradio() was passing the entire step into handle_agent_output_types() instead of unwrapping the actual final_answer.
- As a result:
- AgentImage outputs were not detected
- Gradio fell back to displaying the object’s string representation
Forced share=True GradioUI.launch() always sets share=True, which:
- Prints misleading instructions on Spaces
- Can cause unnecessary tunnel creation attempts
- Is not recommended for Hugging Face Spaces
Solution
Fix 1: Properly unwrap FinalAnswerStep
* We extract the underlying final_answer before calling handle_agent_output_types().
Fix 2: Remove forced share=True
* Let the environment (local vs Spaces) control sharing behavior.
DheerajParkash
changed pull request status to
open