Spaces:
Runtime error
Error None using Python API
I hope you can read the code:
from gradio_client import Client, file
Initialize the Gradio client with your model's API token
client = Client("han1997/cobra")
#print(client.view_api())
Define the image path (replace with your image URL)
image_url = "https://www.ikea.com/nl/en/images/products/stefan-chair-brown-black__0727320_pe735593_s5.jpg"
image_file = image_url #tried file(image_url) as well
Create the message dictionary containing the input data
message = {
"files": [image_file],
"text": "Say what product it is"
}
Parameters for model prediction
temperature_val = 0.2
top_k_val = 1.0
max_new_tokens_val = 256
Make prediction using the model hosted on Hugging Face Model Hub
result = client.predict(message, temperature_val, top_k_val, max_new_tokens_val, api_name="/chat")
Print the result
print(result)
ERROR:
Loaded as API: https://han1997-cobra.hf.space โ
/usr/local/lib/python3.10/dist-packages/gradio_client/client.py:1222: UserWarning: The Client is treating: "https://www.ikea.com/nl/en/images/products/stefan-chair-brown-black__0727320_pe735593_s5.jpg" as a file path. In future versions, this behavior will not happen automatically.
Instead, please provide file path or URLs like this: gradio_client.file("https://www.ikea.com/nl/en/images/products/stefan-chair-brown-black__0727320_pe735593_s5.jpg").
Note: to stop treating strings as filepaths unless file() is used, set upload_files=False in Client().
warnings.warn(
ValueError Traceback (most recent call last)
in <cell line: 22>()
20
21 # Make prediction using the model hosted on Hugging Face Model Hub
---> 22 result = client.predict(message, temperature_val, top_k_val, max_new_tokens_val, api_name="/chat")
23
24 # Print the result
6 frames
/usr/local/lib/python3.10/dist-packages/gradio_client/client.py in _predict(*data)
1133
1134 if "error" in result:
-> 1135 raise ValueError(result["error"])
1136
1137 try:
ValueError: None