API endpoint doesn't work
I tried to call the API of a space from a different space. This is the recommended use:from gradio_client import Clientclient = Client(“https://my-private-space.hf.space/”)result = client.predict(“Howdy!”,	# str  in ‘parameter_2’ Textbox component“null”,	# str (filepath to JSON file) in ‘parameter_1’ Chatbot componentfn_index=2)print(result)So I called as follows:_, _ = client.predict(‘ok’, ‘ok’, fn_index=2)But got an error: Any ideas?Traceback (most recent call last):File “/home/user/.local/lib/python3.9/site-packages/gradio/routes.py”, line 437, in run_predictoutput = await app.get_blocks().process_api(File “/home/user/.local/lib/python3.9/site-packages/gradio/blocks.py”, line 1352, in process_apiresult = await self.call_function(File “/home/user/.local/lib/python3.9/site-packages/gradio/blocks.py”, line 1077, in call_functionprediction = await anyio.to_thread.run_sync(File “/home/user/.local/lib/python3.9/site-packages/anyio/to_thread.py”, line 33, in run_syncreturn await get_asynclib().run_sync_in_worker_thread(File “/home/user/.local/lib/python3.9/site-packages/anyio/_backends/_asyncio.py”, line 877, in run_sync_in_worker_threadreturn await futureFile “/home/user/.local/lib/python3.9/site-packages/anyio/_backends/_asyncio.py”, line 807, in runresult = context.run(func, *args)File “/home/user/app/app.py”, line 34, in respondchat_history = ask_question(message, chat_history)File “/home/user/app/app.py”, line 10, in ask_question_, _ = client.predict(“ok”, “ok”, fn_index=2)File “/home/user/.local/lib/python3.9/site-packages/gradio_client/client.py”, line 272, in predictreturn self.submit(*args, api_name=api_name, fn_index=fn_index).result()File “/home/user/.local/lib/python3.9/site-packages/gradio_client/client.py”, line 973, in resultreturn super().result(timeout=timeout)File “/usr/local/lib/python3.9/concurrent/futures/_base.py”, line 446, in resultreturn self.__get_result()File “/usr/local/lib/python3.9/concurrent/futures/_base.py”, line 391, in __get_resultraise self._exceptionFile “/usr/local/lib/python3.9/concurrent/futures/thread.py”, line 58, in runresult = self.fn(*self.args, **self.kwargs)File “/home/user/.local/lib/python3.9/site-packages/gradio_client/client.py”, line 629, in _innerdata = self.serialize(*data)File “/home/user/.local/lib/python3.9/site-packages/gradio_client/client.py”, line 799, in serializeo = tuple([s.serialize(d) for s, d in zip(self.serializers, data)])File “/home/user/.local/lib/python3.9/site-packages/gradio_client/client.py”, line 799, ino = tuple([s.serialize(d) for s, d in zip(self.serializers, data)])File “/home/user/.local/lib/python3.9/site-packages/gradio_client/serializing.py”, line 420, in serializereturn utils.file_to_json(Path(load_dir) / x)File “/home/user/.local/lib/python3.9/site-packages/gradio_client/utils.py”, line 430, in file_to_jsonwith open(file_path) as f:FileNotFoundError: [Errno 2] No such file or directory: ‘ok’
2023-06-23T04:02:44Z
hi@JingpuShi,Have you tried passing your hftoken? since it lookes like it’s a private, unpublised Space? you could also try theserializeoptionclient = Client("https://my-private-space.hf.space/",REDACTED_TOKEN="hf...", serialize=False)
2023-06-23T06:00:51Z
serialize=False fixed it. Thanks a lot for your help@radames!!!