how can I use the gradio API?

#7
by mcj123 - opened

Great work! I saw the API usage of the demo page, how can I call Qwen VL max to analyze video/image?

Hi, please refer to this document: https://www.alibabacloud.com/help/en/model-studio/developer-reference/qwen-vl-api

I see in this space below there is a "通过API使用" option, but when I open the link I don't know how to input and use it to make queries, can you help me?

if you would like to use the gradio API, there is an API recorder:
image.png

enable the recorder and use the space as usual, then you can see the API used and you can modify the results based on that

however, this is far less stable than creating your own API by local deployment or cloud providers.

if you would like to use the gradio API, there is an API recorder:
image.png

enable the recorder and use the space as usual, then you can see the API used and you can modify the results based on that

however, this is far less stable than creating your own API by local deployment or cloud providers.

Can you tell me how to upload file and do prediction ? I called add text and add file api and try to predict, but I got apperror, how to set the input value of predict api? Thank you

Hello, I use api recorder to record API usage and write following code, but when I run that code I got error, can you help me?

Recorded call using recorder:

from gradio_client import Client, file

client = Client("Qwen/Qwen2-VL")

client.predict(
history=[],
file=[],
api_name="/add_file"
)

client.predict(
history=[[{"file":handle_file('https://qwen-qwen2-vl.hf.space/file=/tmp/gradio/1cfdfd55eb81c25993390b0b280339a9d706e4e7a072ea569c7ce30f9651e9c0/accvid_5.mp4'),"alt_text":None},None]],
text=None,
api_name="/add_text"
)

client.predict(
api_name="/reset_user_input"
)

client.predict(
_chatbot=[[{"file":handle_file('https://qwen-qwen2-vl.hf.space/file=/tmp/gradio/1cfdfd55eb81c25993390b0b280339a9d706e4e7a072ea569c7ce30f9651e9c0/accvid_5.mp4'),"alt_text":None},None],["what happens in this video?",None]],
api_name="/predict"
)

Here is the updated inference code from my side:

client = Client("Qwen/Qwen2-VL")
client.predict(
api_name="/reset_state"
)
print("add file")
history1 = []
history1 = client.predict(
history=[],
file=handle_file('/media/test/DATA/accident_detection_folder/accident_vid/accvid1_5.mp4'),
api_name="/add_file"
)

link = history1[-1][0]['file']
print(str(link))

print("addtext")
print('https://qwen-qwen2-vl.hf.space/file='+str(link))
chatbot1 = client.predict(
history=[[{"file":handle_file('https://qwen-qwen2-vl.hf.space/file='+str(link)),"alt_text":None},None]],
text=None,
api_name="/add_text"
)
print(chatbot1)
client.predict(
api_name="/reset_user_input"
)
print("predict")
client.predict(
_chatbot= chatbot1,
api_name="/predict"
)

add file api works, but when I try addtext api and predict, following error happens:

Traceback (most recent call last):
File "/media/test/DATA/114514/ori_inference_qwen72b.py", line 34, in
client.predict(
File "/home/test/miniforge3/lib/python3.10/site-packages/gradio_client/client.py", line 476, in predict
).result()
File "/home/test/miniforge3/lib/python3.10/site-packages/gradio_client/client.py", line 1509, in result
return super().result(timeout=timeout)
File "/home/test/miniforge3/lib/python3.10/concurrent/futures/_base.py", line 458, in result
return self.__get_result()
File "/home/test/miniforge3/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
raise self._exception
File "/home/test/miniforge3/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/home/test/miniforge3/lib/python3.10/site-packages/gradio_client/client.py", line 1128, in _inner
predictions = _predict(*data)
File "/home/test/miniforge3/lib/python3.10/site-packages/gradio_client/client.py", line 1240, in _predict
raise AppError(
gradio_client.exceptions.AppError: The upstream Gradio app has raised an exception but has not enabled verbose error reporting. To enable, set show_error=True in launch().

Sign up or log in to comment