Using HF spaces via http request?

I want to use a gradio space hosted on HF with a http request. I am very much aware of the super simple python, js and bash integration, however I am not working in these languages.

Is this possible, or am I stuck with having to use one of these other options?

1 Like

I heard that curl can be used, but isn’t it more difficult than Python?
The get/post request contents of the Python code that uses the requests library are mostly raw, so I think it can be used for curl as well.

It is more difficult than python, but when not working in these specific languages, one must go with the slightly more difficult alternative.
In other words, I am willing to give up ease of use to not use python.

I see. If you want to use it in a compiled language, for example, you can handle it in a more complicated way.

For HF, the easiest way is to use InferenceClient with Python or JS, but if that’s not possible, the next best thing is an API that returns JSON.
I heard that everyone used this before InferenceClient was developed, so there should be a lot that can be done, but because of that history, there is a lot of pre-2023 information. Well, it’s still in use inside old Gradio and so on, and it should work.

I am also struggling with the same issue. i have created a space on HF and created a chat app which works but then i am struggling to use curl to get a response, i posted this HuggingFaceH4/zephyr-7b-beta · Getting NULL response using curl or PHP for help. hope a response here or on my post will help. Not sure there is anyone here who knows the solution, especially due to lack of docs and support. :frowning:

1 Like

There is a document for now.

1 Like

trying to get this to work for the final step of Stable Fast 3D - a Hugging Face Space by stabilityai

curl -N https://stabilityai-stable-fast-3d.hf.space/call/run_button/[insert event_id]

the results seems to always be

event: error
data: null

any insight appreciated!

1 Like

If everything didn’t work, I would understand, but it seems that some of it works. It’s a strange behavior.

from gradio_client import Client, handle_file

client = Client("stabilityai/stable-fast-3d")
result = client.predict( # it works.
		image=handle_file('https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png'),
		fr=0.85,
		api_name="/requires_bg_remove"
)
print(result)

result = client.predict( # it fails.
		input_image=handle_file('https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png'),
		foreground_ratio=0.85,
		remesh_option="None",
		vertex_count=-1,
		texture_size=1024,
		api_name="/run_button"
)
print(result)