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

Calling component via gradio python client doesn't work #6

Open
pablovela5620 opened this issue Jul 13, 2024 · 1 comment
Open

Calling component via gradio python client doesn't work #6

pablovela5620 opened this issue Jul 13, 2024 · 1 comment

Comments

@pablovela5620
Copy link
Contributor

pablovela5620 commented Jul 13, 2024

Loaded as API: http://127.0.0.1:7862/
/Users/pablovela/0Dev/personal/inference-hf-spaces/.pixi/envs/default/lib/python3.12/site-packages/gradio_client/utils.py:1097: UserWarning: file() is deprecated and will be removed in a future version. Use handle_file() instead.
warnings.warn(
Traceback (most recent call last):
File "/Users/pablovela/0Dev/personal/inference-hf-spaces/main.py", line 4, in
result = client.predict(
^^^^^^^^^^^^^^^
File "/Users/pablovela/0Dev/personal/inference-hf-spaces/.pixi/envs/default/lib/python3.12/site-packages/gradio_client/client.py", line 463, in predict
).result()
^^^^^^^^
File "/Users/pablovela/0Dev/personal/inference-hf-spaces/.pixi/envs/default/lib/python3.12/site-packages/gradio_client/client.py", line 1485, in result
return super().result(timeout=timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pablovela/0Dev/personal/inference-hf-spaces/.pixi/envs/default/lib/python3.12/concurrent/futures/_base.py", line 456, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "/Users/pablovela/0Dev/personal/inference-hf-spaces/.pixi/envs/default/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
raise self.exception
File "/Users/pablovela/0Dev/personal/inference-hf-spaces/.pixi/envs/default/lib/python3.12/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pablovela/0Dev/personal/inference-hf-spaces/.pixi/envs/default/lib/python3.12/site-packages/gradio_client/client.py", line 1113, in inner
predictions = self.process_predictions(*predictions)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pablovela/0Dev/personal/inference-hf-spaces/.pixi/envs/default/lib/python3.12/site-packages/gradio_client/client.py", line 1278, in process_predictions
predictions = self.download_files(*predictions)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pablovela/0Dev/personal/inference-hf-spaces/.pixi/envs/default/lib/python3.12/site-packages/gradio_client/client.py", line 1291, in download_files
data
= utils.traverse(data
, self._download_file, utils.is_file_obj)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pablovela/0Dev/personal/inference-hf-spaces/.pixi/envs/default/lib/python3.12/site-packages/gradio_client/utils.py", line 984, in traverse
new_obj.append(traverse(item, func, is_root))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pablovela/0Dev/personal/inference-hf-spaces/.pixi/envs/default/lib/python3.12/site-packages/gradio_client/utils.py", line 975, in traverse
return func(json_obj)
^^^^^^^^^^^^^^
File "/Users/pablovela/0Dev/personal/inference-hf-spaces/.pixi/envs/default/lib/python3.12/site-packages/gradio_client/client.py", line 1369, in _download_file
response.raise_for_status()
File "/Users/pablovela/0Dev/personal/inference-hf-spaces/.pixi/envs/default/lib/python3.12/site-packages/httpx/_models.py", line 761, in raise_for_status
raise HTTPStatusError(message, request=request, response=self)
httpx.HTTPStatusError: Client error '403 Forbidden' for url 'http://127.0.0.1:7862/file=6f7c8fd3-3c02-4b2b-95c3-d31966b2d4ea/138970045808400/16'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403

I'm guessing its because its providing back a URL from the rerun rrd file that isn't accessible?

with gr.Blocks() as demo:
    with gr.Tab("Streaming"):
        with gr.Row():
            img = gr.Image(interactive=True, label="Image", type="filepath")
            with gr.Tab(label="Settings"):
                with gr.Column():
                    warp_img_btn = gr.Button("Warp Images")
                    num_iters = gr.Radio(
                        choices=[2, 25, 50, 100],
                        value=2,
                        label="Number of iterations",
                        type="value",
                    )
                    cam_direction = gr.Radio(
                        choices=["left", "right"],
                        value="left",
                        label="Camera direction",
                        type="value",
                    )
                    degrees_per_frame = gr.Slider(
                        minimum=0.25,
                        maximum=1.0,
                        step=0.05,
                        value=0.3,
                        label="Degrees per frame",
                    )
            with gr.Tab(label="Outputs"):
                video_output = gr.Video(interactive=False)
                image_files_output = gr.File(interactive=False, file_count="multiple")

    # Rerun 0.16 has issues when embedded in a Gradio tab, so we share a viewer between all the tabs.
    # In 0.17 we can instead scope each viewer to its own tab to clean up these examples further.
    with gr.Row():
        viewer = Rerun(
            streaming=True,
        )

    warp_img_btn.click(
        gradio_warped_image,
        inputs=[img, num_iters, cam_direction, degrees_per_frame],
        outputs=[viewer, video_output, image_files_output],
    )

    gr.Examples(
        [
            [
                "/home/pablo/0Dev/docker/.per/repos/NVS_Solver/example_imgs/single/000001.jpg",
            ],
        ],
        fn=warp_img_btn,
        inputs=[img, num_iters, cam_direction, degrees_per_frame],
        outputs=[viewer, video_output, image_files_output],
    )


if __name__ == "__main__":
    demo.queue().launch(share=True)

This is what the current gradio UI looks like, I'm using yield + generator and I think that's probably part of the issue? if I do the same thing with https://huggingface.co/spaces/pablovela5620/mini-dust3r and it works fine if I run, but this is with gradio_rerun==0.0.1 and is not using yield but returning the rrd file

from gradio_client import Client, file

client = Client("pablovela5620/mini-dust3r")
result = client.predict(
		image_name_list=file('https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png'),
		api_name="/predict"
)
print(result)
@pablovela5620
Copy link
Contributor Author

Another example where it fails is the official example https://huggingface.co/spaces/radames/gradio_rerun

from gradio_client import Client, file

client = Client("radames/gradio_rerun")
result = client.predict(
		img=file('https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png'),
		api_name="/streaming_repeated_blur"
)
print(result)

the version that provides the rrd without yield/streaming works fine

from gradio_client import Client

client = Client("radames/gradio_rerun")
result = client.predict(
		x=5,
		y=5,
		z=5,
		api_name="/create_cube_rrd"
)
print(result)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant