I think I set up correctly my API on HuggingFace.
What I don’t understand is: am I supposed to be able to run it in the course notebook?
I copied the following:
from gradio_client import Client, handle_file
client = Client("aledesa/blip-image-captioning")
result = client.predict(
input=handle_file('https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png'),
api_name="/predict"
)
print(result)
And got the following:
ImportError: cannot import name 'handle_file' from 'gradio_client' (/usr/local/lib/python3.9/site-packages/gradio_client/__init__.py)
I see that the command is different from what provided in the course notebook which is:
from gradio_client import Client
client = Client("eddyS/blip-image-captioning-2")
result = client.predict(
"https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png", # filepath in 'input' Image component
api_name="/predict"
)
print(result)
However, I tried to run this:
from gradio_client import Client #, handle_file
client = Client("aledesa/blip-image-captioning")
result = client.predict(
# input=handle_file('https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png'),
'https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png',
api_name="/predict"
)
print(result)
And after the first check I got the following error:
Loaded as API: https://aledesa-blip-image-captioning.hf.space ✔
---------------------------------------------------------------------------
JSONDecodeError Traceback (most recent call last)
Cell In[13], line 3
1 from gradio_client import Client #, handle_file
----> 3 client = Client("aledesa/blip-image-captioning")
4 result = client.predict(
5 # input=handle_file('https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png'),
6 'https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png',
7 api_name="/predict"
8 )
9 print(result)
File /usr/local/lib/python3.9/site-packages/gradio_client/client.py:149, in Client.__init__(self, src, hf_token, max_workers, serialize, output_dir, verbose, auth)
147 self.reset_url = urllib.parse.urljoin(self.src, utils.RESET_URL)
148 self.app_version = version.parse(self.config.get("version", "2.0"))
--> 149 self._info = self._get_api_info()
150 self.session_hash = str(uuid.uuid4())
152 endpoint_class = (
153 Endpoint if self.protocol.startswith("sse") else EndpointV3Compatibility
154 )
File /usr/local/lib/python3.9/site-packages/gradio_client/client.py:467, in Client._get_api_info(self)
465 r = httpx.get(api_info_url, headers=self.headers, cookies=self.cookies)
466 if r.is_success:
--> 467 info = r.json()
468 else:
469 raise ValueError(f"Could not fetch api info for {self.src}: {r.text}")
File /usr/local/lib/python3.9/site-packages/httpx/_models.py:762, in Response.json(self, **kwargs)
761 def json(self, **kwargs: typing.Any) -> typing.Any:
--> 762 return jsonlib.loads(self.content, **kwargs)
File /usr/local/lib/python3.9/json/__init__.py:346, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
341 s = s.decode(detect_encoding(s), 'surrogatepass')
343 if (cls is None and object_hook is None and
344 parse_int is None and parse_float is None and
345 parse_constant is None and object_pairs_hook is None and not kw):
--> 346 return _default_decoder.decode(s)
347 if cls is None:
348 cls = JSONDecoder
File /usr/local/lib/python3.9/json/decoder.py:337, in JSONDecoder.decode(self, s, _w)
332 def decode(self, s, _w=WHITESPACE.match):
333 """Return the Python representation of ``s`` (a ``str`` instance
334 containing a JSON document).
335
336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
338 end = _w(s, end).end()
339 if end != len(s):
File /usr/local/lib/python3.9/json/decoder.py:355, in JSONDecoder.raw_decode(self, s, idx)
353 obj, end = self.scan_once(s, idx)
354 except StopIteration as err:
--> 355 raise JSONDecodeError("Expecting value", s, err.value) from None
356 return obj, end
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Also, at 5:54 the video refers to a temporary link that I can’t see in my space.
I thank you in advance.