Add image examples using Gradio "API mode"

Hi!

I am playing with an App that loads a model from the Hugging Face hub, but I find problems when I add some image examples to the app during the building. I tried uploading the images to the repository and downloading them from another place, but the error continued.

Is there some behaviour to process image example when using Gradio in API mode that can trigger the error?

Best,
Cristóbal

--2022-08-02 22:11:04--  https://huggingface.co/alkzar90/croupier-creature-classifier/resolve/main/examples/crusader_peco_peco.png
Resolving huggingface.co (huggingface.co)... 52.2.34.29, 34.231.117.252, 2600:1f18:147f:e850:d57d:d46a:df34:61ee, ...
Connecting to huggingface.co (huggingface.co)|52.2.34.29|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3648 (3.6K) [image/png]
Saving to: ‘crusader_peco_peco.png’

     0K ...                                                   100%  168M=0s

2022-08-02 22:11:04 (168 MB/s) - ‘crusader_peco_peco.png’ saved [3648/3648]

--2022-08-02 22:11:05--  https://huggingface.co/alkzar90/croupier-creature-classifier/resolve/main/examples/goblin_wow.png
Resolving huggingface.co (huggingface.co)... 52.2.34.29, 34.231.117.252, 2600:1f18:147f:e850:d57d:d46a:df34:61ee, ...
Connecting to huggingface.co (huggingface.co)|52.2.34.29|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 109057 (107K) [image/png]
Saving to: ‘goblin_wow.png’

     0K .......... .......... .......... .......... .......... 46% 51.1M 0s
    50K .......... .......... .......... .......... .......... 93% 81.0M 0s
   100K ......                                                100% 21.4M=0.002s

2022-08-02 22:11:05 (56.0 MB/s) - ‘goblin_wow.png’ saved [109057/109057]

Fetching model from: https://huggingface.co/alkzar90/croupier-creature-classifier
/home/user/.local/lib/python3.8/site-packages/gradio/interface.py:313: UserWarning: Currently, only the 'default' theme is supported.
  warnings.warn("Currently, only the 'default' theme is supported.")
Caching examples at: '/home/user/app/gradio_cached_examples/51/log.csv'
Traceback (most recent call last):
  File "app.py", line 7, in <module>
    iface = gr.Interface.load('alkzar90/croupier-creature-classifier',
  File "/home/user/.local/lib/python3.8/site-packages/gradio/interface.py", line 108, in load
    return super().load(name=name, src=src, api_key=api_key, alias=alias, **kwargs)
  File "/home/user/.local/lib/python3.8/site-packages/gradio/blocks.py", line 744, in load
    return external.load_blocks_from_repo(name, src, api_key, alias, **kwargs)
  File "/home/user/.local/lib/python3.8/site-packages/gradio/external.py", line 40, in load_blocks_from_repo
    blocks: gradio.Blocks = factory_methods[src](name, api_key, alias, **kwargs)
  File "/home/user/.local/lib/python3.8/site-packages/gradio/external.py", line 294, in get_models_interface
    interface = gradio.Interface(**kwargs)
  File "/home/user/.local/lib/python3.8/site-packages/gradio/interface.py", line 599, in __init__
    self.examples_handler = Examples(
  File "/home/user/.local/lib/python3.8/site-packages/gradio/examples.py", line 154, in __init__
    self.cache_interface_examples()
  File "/home/user/.local/lib/python3.8/site-packages/gradio/examples.py", line 189, in cache_interface_examples
    raise e
  File "/home/user/.local/lib/python3.8/site-packages/gradio/examples.py", line 185, in cache_interface_examples
    prediction = self.process_example(example_id)
  File "/home/user/.local/lib/python3.8/site-packages/gradio/examples.py", line 205, in process_example
    predictions = self.fn(*processed_input)
  File "/home/user/.local/lib/python3.8/site-packages/gradio/external.py", line 259, in query_huggingface_api
    data = pipeline["preprocess"](*params)
  File "/home/user/.local/lib/python3.8/site-packages/gradio/external.py", line 131, in <lambda>
    i.split(",")[1]
IndexError: list index out of range

Hi @alkzar90,

Can you please try with cache_examples=False?

I think this is the same problem as this issue (https://github.com/gradio-app/gradio/issues/1643). Good news is that I’m planning on fixing the underlying issue by the end of the week!

Also, you can store the example images in the repo with git as opposed to pulling them in the app file.

Hi @freddyaboulton,

it works with cache_examples=False, thanks for the suggestion!
Now I will move the images into the repo instead of downloading them from the app file, it was. a desperate move trying to fix the problem hahaha,

Best!