radames / gradio-rerun-viewer

Rerun viewer with Gradio
https://huggingface.co/spaces/radames/gradio_rerun
12 stars 1 forks source link

Examples don't work for streaming #4

Open pablovela5620 opened 1 month ago

pablovela5620 commented 1 month ago

Settings examples to True or lazy breaks things and I get the following error. You can test using this code https://github.com/pablovela5620/mini-dpvo

git clone https://github.com/pablovela5620/mini-dpvo.git
cd mini-dpvo
pixi run app

, and adding cache_examples=True here

Traceback (most recent call last):
  File "/home/pablo/0Dev/personal/mini-dpvo/tools/app.py", line 244, in <module>
    main(tyro.cli(GradioDPVOConfig))
  File "/home/pablo/0Dev/personal/mini-dpvo/tools/app.py", line 215, in main
    examples = gr.Examples(
               ^^^^^^^^^^^^
  File "/home/pablo/0Dev/personal/mini-dpvo/.pixi/envs/default/lib/python3.11/site-packages/gradio/helpers.py", line 74, in create_examples
    examples_obj.create()
  File "/home/pablo/0Dev/personal/mini-dpvo/.pixi/envs/default/lib/python3.11/site-packages/gradio/helpers.py", line 314, in create
    self._start_caching()
  File "/home/pablo/0Dev/personal/mini-dpvo/.pixi/envs/default/lib/python3.11/site-packages/gradio/helpers.py", line 365, in _start_caching
    client_utils.synchronize_async(self.cache)
  File "/home/pablo/0Dev/personal/mini-dpvo/.pixi/envs/default/lib/python3.11/site-packages/gradio_client/utils.py", line 855, in synchronize_async
    return fsspec.asyn.sync(fsspec.asyn.get_loop(), func, *args, **kwargs)  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pablo/0Dev/personal/mini-dpvo/.pixi/envs/default/lib/python3.11/site-packages/fsspec/asyn.py", line 103, in sync
    raise return_result
  File "/home/pablo/0Dev/personal/mini-dpvo/.pixi/envs/default/lib/python3.11/site-packages/fsspec/asyn.py", line 56, in _runner
    result[0] = await coro
                ^^^^^^^^^^
  File "/home/pablo/0Dev/personal/mini-dpvo/.pixi/envs/default/lib/python3.11/site-packages/gradio/helpers.py", line 487, in cache
    prediction = await Context.root_block.process_api(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pablo/0Dev/personal/mini-dpvo/.pixi/envs/default/lib/python3.11/site-packages/gradio/blocks.py", line 1938, in process_api
    data = await self.postprocess_data(block_fn, result["prediction"], state)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pablo/0Dev/personal/mini-dpvo/.pixi/envs/default/lib/python3.11/site-packages/gradio/blocks.py", line 1761, in postprocess_data
    prediction_value = block.postprocess(prediction_value)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pablo/0Dev/personal/mini-dpvo/.pixi/envs/default/lib/python3.11/site-packages/gradio_rerun/rerun.py", line 126, in postprocess
    root=[
         ^
  File "/home/pablo/0Dev/personal/mini-dpvo/.pixi/envs/default/lib/python3.11/site-packages/gradio_rerun/rerun.py", line 132, in <listcomp>
    if not is_url(file)
           ^^^^^^^^^^^^
  File "/home/pablo/0Dev/personal/mini-dpvo/.pixi/envs/default/lib/python3.11/site-packages/gradio_rerun/rerun.py", line 123, in is_url
    return input.startswith("http://") or input.startswith("https://")
           ^^^^^^^^^^^^^^^^
AttributeError: 'tuple' object has no attribute 'startswith'
jleibs commented 4 weeks ago

Oh neat! I hadn't realized Gradio could do that. Would be super nice to just cache and serve an rrd for each example.

radames commented 4 weeks ago

yes the examples should work. I need to check in case lazy mode enabled, does the backend component need anything special

radames commented 3 weeks ago

I'm working on a fix here https://github.com/radames/gradio-rerun-viewer/tree/fix-cache-examples, but still having an issue I think there must be something on the Gradio side, I've asked for help

payload = self.data_model.from_json(payload)

  File "/gradio-rerun-viewer/venv/lib/python3.10/site-packages/gradio/data_classes.py", line 186, in from_json

    return cls(root=x)

  File "/gradio-rerun-viewer/venv/lib/python3.10/site-packages/pydantic/root_model.py", line 71, in __init__

    self.__pydantic_validator__.validate_python(root, self_instance=self)

pydantic_core._pydantic_core.ValidationError: 1 validation error for RerunData

  Input should be a valid list 

    For further information visit https://errors.pydantic.dev/2.7/v/list_type
pablovela5620 commented 1 week ago

I'm working on a fix here https://github.com/radames/gradio-rerun-viewer/tree/fix-cache-examples, but still having an issue I think there must be something on the Gradio side, I've asked for help

payload = self.data_model.from_json(payload)

  File "/gradio-rerun-viewer/venv/lib/python3.10/site-packages/gradio/data_classes.py", line 186, in from_json

    return cls(root=x)

  File "/gradio-rerun-viewer/venv/lib/python3.10/site-packages/pydantic/root_model.py", line 71, in __init__

    self.__pydantic_validator__.validate_python(root, self_instance=self)

pydantic_core._pydantic_core.ValidationError: 1 validation error for RerunData

  Input should be a valid list 

    For further information visit https://errors.pydantic.dev/2.7/v/list_type

With 0.17 on the horizon, did you end up finding a fix for this?