Fix image rendering in GradioUI and avoid forced share=True on Hugging Face Spaces

#583
No description provided.

This PR fixes two issues in GradioUI that affect Hugging Face Spaces users and image-generating agents:

  1. AgentImage outputs were displayed as Python object strings
    * (FinalAnswerStep(final_answer=<AgentImage ...>)) instead of rendering as images.
  2. share=True was always enabled, which is unnecessary (and sometimes harmful) on Hugging Face Spaces where the app is already publicly exposed.

Problem Details

  1. 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
  2. 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
Ready to merge
This branch is ready to get merged automatically.

Sign up or log in to comment