Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexError when creating a pure API endpoint #10217

Open
1 task done
jeberger opened this issue Dec 17, 2024 · 2 comments
Open
1 task done

IndexError when creating a pure API endpoint #10217

jeberger opened this issue Dec 17, 2024 · 2 comments
Assignees
Labels
bug Something isn't working needs designing The proposed feature needs to be discussed and designed before being implemented

Comments

@jeberger
Copy link

Describe the bug

For unit testing purposes, I wanted to create a pure API endpoint, i.e. a function that could be called from gradio_client but wouldn't show in the UI. So I tried:

gr.on ([], fn = test, show_api = False)

but this throws an IndexError in set_event_trigger.

Note: this is similar to #6730 but slightly different: in #6730, passing None is expected to trigger on all changes. Here I'm attempting to never trigger from the UI and only be able to call the function with an explicit REST request.

Have you searched existing issues? 🔎

  • I have searched and found no existing issues

Reproduction

import gradio as gr
import gradio_client as gc

def test():
    print ("Test!")
    return []

with gr.Blocks() as demo:
    gr.on ([], fn = test, show_api = False)
    demo.launch (prevent_thread_lock = True, server_port = 7860)

client = gc.Client ("http://127.0.0.1:7860")
client.predict (api_name = "/test")

Screenshot

No response

Logs

Traceback (most recent call last):
  File "test_gradio.py", line 9, in <module>
    gr.on ([], fn = test, show_api = False)
  File ".venv/lib/python3.11/site-packages/gradio/events.py", line 820, in on
    dep, dep_index = root_block.set_event_trigger(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.11/site-packages/gradio/blocks.py", line 784, in set_event_trigger
    if _targets[0][1] in ["change", "key_up"] and trigger_mode is None:
       ~~~~~~~~^^^
IndexError: list index out of range

System Info

Gradio Environment Information:
------------------------------
Operating System: Linux
gradio version: 5.9.1
gradio_client version: 1.5.2

------------------------------------------------
gradio dependencies in your environment:

aiofiles: 23.2.1
anyio: 4.6.2.post1
audioop-lts is not installed.
fastapi: 0.115.6
ffmpy: 0.4.0
gradio-client==1.5.2 is not installed.
httpx: 0.28.0
huggingface-hub: 0.26.3
jinja2: 3.1.4
markupsafe: 2.1.5
numpy: 2.1.3
orjson: 3.10.12
packaging: 24.2
pandas: 2.2.3
pillow: 10.4.0
pydantic: 2.10.3
pydub: 0.25.1
python-multipart: 0.0.19
pyyaml: 6.0.2
ruff: 0.8.1
safehttpx: 0.1.6
semantic-version: 2.10.0
starlette: 0.41.3
tomlkit: 0.12.0
typer: 0.15.0
typing-extensions: 4.12.2
urllib3: 2.2.3
uvicorn: 0.32.1
authlib; extra == 'oauth' is not installed.
itsdangerous; extra == 'oauth' is not installed.


gradio_client dependencies in your environment:

fsspec: 2024.10.0
httpx: 0.28.0
huggingface-hub: 0.26.3
packaging: 24.2
typing-extensions: 4.12.2
websockets: 12.0

Severity

I can work around it

@jeberger jeberger added the bug Something isn't working label Dec 17, 2024
@jeberger
Copy link
Author

As a workaround, I'm currently using a hidden inactive button as a trigger:

gr.on (gr.Button (render = False).click, fn = test, show_api = False)

@abidlabs
Copy link
Member

We're thinking about how to make this exact use case easier, stay tuned.

@abidlabs abidlabs added the needs designing The proposed feature needs to be discussed and designed before being implemented label Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs designing The proposed feature needs to be discussed and designed before being implemented
Projects
None yet
Development

No branches or pull requests

3 participants