I’ve tested on
- Gradio 3.x on local machine (success)
- Gradio 4.x on local machine (success)
- Gradio 3.x on HuggingFace public space (success)
- Gradio 3.x on HuggingFace private space with proper token space (success)
- Gradio 4.x on HuggingFace public space (success)
- Gradio 4.x on HuggingFace private space with proper token ( bug!)
with gradio_client (python)
Server side app.py
:
import gradio as gr
def greet(name):
return "Hello " + name + "!!"
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
iface.launch( show_error=True, server_name='0.0.0.0' , share=True)
Client side code:
#!/usr/bin/python3.11
from gradio_client import Client
import time
def call():
client=Client('myusername/test', \
hf_token='hf_xxxxxxxxxxxxxxxxxxxxxxxxx' \
)
client.view_api() # success
r = client.predict('john', fn_index=0, api_name="/predict") # fail
return r
r = call()
print(r)
I got result:
Loaded as API: https://myusername-test.hf.space ✔
Client.predict() Usage Info
---------------------------
Named API endpoints: 1
- predict(name, api_name="/predict") -> output
Parameters:
- [Textbox] name: str
Returns:
- [Textbox] output: str
Traceback (most recent call last):
File "/tmp/gclient.py", line 16, in <module>
r = call("sdf")
^^^^^^^^^^^
File "/tmp/gclient.py", line 13, in call
r = client.predict('sss', fn_index=0, api_name="/predict")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/john/.local/lib/python3.11/site-packages/gradio_client/client.py", line 305, in predict
return self.submit(*args, api_name=api_name, fn_index=fn_index).result()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/john/.local/lib/python3.11/site-packages/gradio_client/client.py", line 1456, in result
return super().result(timeout=timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.11/concurrent/futures/_base.py", line 456, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "/usr/lib64/python3.11/concurrent/futures/_base.py", line 401, in __get_result
raise self._exception
File "/usr/lib64/python3.11/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/john/.local/lib/python3.11/site-packages/gradio_client/client.py", line 869, in _inner
predictions = _predict(*data)
^^^^^^^^^^^^^^^
File "/home/john/.local/lib/python3.11/site-packages/gradio_client/client.py", line 894, in _predict
result = utils.synchronize_async(self._sse_fn, data, hash_data, helper)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/john/.local/lib/python3.11/site-packages/gradio_client/utils.py", line 664, in synchronize_async
return fsspec.asyn.sync(fsspec.asyn.get_loop(), func, *args, **kwargs) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/fsspec/asyn.py", line 103, in sync
raise return_result
File "/usr/lib/python3.11/site-packages/fsspec/asyn.py", line 56, in _runner
result[0] = await coro
^^^^^^^^^^
File "/home/john/.local/lib/python3.11/site-packages/gradio_client/client.py", line 1075, in _sse_fn
return await utils.get_pred_from_sse(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/john/.local/lib/python3.11/site-packages/gradio_client/utils.py", line 341, in get_pred_from_sse
return task.result()
^^^^^^^^^^^^^
File "/home/john/.local/lib/python3.11/site-packages/gradio_client/utils.py", line 410, in stream_sse
raise ValueError(f"Unexpected message: {line}")
ValueError: Unexpected message: <!DOCTYPE html>
<html class="">
<head>
<meta property="og:type" content="website"/>
<title>Hugging Face – The AI community building the future.</title>
.........
.........
.........
</head>
<body> <main> <img src="https://huggingface.co/front/assets/huggingface_logo.svg" alt="" /> <div>
<h1>404</h1>
<p>Sorry, we can’t find the page you are looking for.</p>
</div> </main> </body> </html>
The view_api()
successfully got API usage,
which means I got the access to my private space.
But predict()
can’t work.