The Gradio API is not working

the gradio throws error: Traceback (most recent call last):
File “C:\Users\danya\PycharmProjects\DiDefBackend\DiDef\SentenceTransformer.py”, line 45, in
client = Client(
File “C:\Users\danya\AppData\Local\Programs\Python\Python39\lib\site-packages\gradio_client\client.py”, line 171, in init
self._info = self._get_api_info()
File “C:\Users\danya\AppData\Local\Programs\Python\Python39\lib\site-packages\gradio_client\client.py”, line 564, in get_api_info
info = r.json()
File “C:\Users\danya\AppData\Local\Programs\Python\Python39\lib\site-packages\httpx_models.py”, line 764, in json
return jsonlib.loads(self.content, **kwargs)
File "C:\Users\danya\AppData\Local\Programs\Python\Python39\lib\json_init
.py", line 346, in loads
return _default_decoder.decode(s)
File “C:\Users\danya\AppData\Local\Programs\Python\Python39\lib\json\decoder.py”, line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “C:\Users\danya\AppData\Local\Programs\Python\Python39\lib\json\decoder.py”, line 355, in raw_decode
raise JSONDecodeError(“Expecting value”, s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

why? My code is very simple:

from gradio_client import Client

client = Client(
src = “GoldDany/DiDefBackend”, #my Space is public
)
result = client.predict(
text=“Hello!!”,
api_name=“/predict”,
)
print(result)

1 Like

Python39

I think this is probably the culprit this time.

Gradio 5 only works with Python 3.10 or later on both the server and client, so I think the error is occurring because the versions are different between the client and server.
I don’t know if this error can be potentially resolved…

The simplest solution is to use Python 3.10 or later.:sweat_smile:

# pip install -U gradio_client (in Python 3.9 environment)
import subprocess
subprocess.run("pip show gradio_client", shell=True) # Version: 1.3.0 (Release date: 2024.08.08)
from gradio_client import Client

client = Client(src="John6666/apitest1") # Gradio 4.41.0
result = client.predict(text="Hello!!", api_name="/predict")
print(result) # [0.010964062064886093, 0.02713009901344776, -0.024556249380111694, 0.01713254489004612, 0.04088324308395386, -0.005583592690527439, 0.015990763902664185,...

client = Client(src="GoldDany/DiDefBackend") # Gradio 5.42.0
result = client.predict(text="Hello!!", api_name="/predict")
print(result) # error

Thanks) But I may have to use an even lower version python, because integrating it :skull_and_crossbones: . But downgrading the version of Gradio works))

1 Like

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.