I'm trying to call the API to a chatbot I've created with Gradio library. When I check the API documents in gradio-client, it shows that:
from gradio_client import Client
client = Client("https://c88f6cc8edfb2f573b.gradio.live/")
result = client.predict(
"Howdy!", # str representing string value in 'parameter_12' Textbox component
"null", # str representing filepath to JSON file in 'parameter_11' Chatbot component
api_name="/chat"
)
print(result)
I'm confused about the second parameter (# str representing filepath to JSON file in 'parameter_11' Chatbot component). What does the JSON file of Gradio Chatbot look like? Can I get an example of using Gradio Chatbot through API?. Here is the code to generate chatbot in Gradio documents:
import gradio as gr
import random
import time
with gr.Blocks() as demo:
chatbot = gr.Chatbot()
msg = gr.Textbox()
clear = gr.Button("Clear")
def user(user_message, history):
return "", history + [[user_message, None]]
def bot(history):
bot_message = random.choice(["Yes", "No"])
history[-1][1] = bot_message
time.sleep(1)
return history
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False, api_name="chat").then(
bot, chatbot, chatbot
)
clear.click(lambda: None, None, chatbot, queue=False, api_name="clear")
if __name__ == "__main__":
demo.launch(share=True)
I've tried the code
from gradio_client import Client
client = Client("https://c88f6cc8edfb2f573b.gradio.live/")
result = client.predict(
"hello", # str representing string value in 'parameter_2' Textbox component
"/content/chatbot.json", # str representing filepath to JSON file in 'parameter_1' Chatbot component
api_name="/chat"
)
print(result)
and got the error
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
/usr/local/lib/python3.9/dist-packages/gradio_client/client.py in _predict(*data)
633 try:
--> 634 output = result["data"]
635 except KeyError:
KeyError: 'data'
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
7 frames
/usr/local/lib/python3.9/dist-packages/gradio_client/client.py in _predict(*data)
638 and not huggingface_hub.space_info(self.client.space_id).private
639 )
--> 640 if "error" in result and "429" in result["error"] and is_public_space:
641 raise utils.TooManyRequestsError(
642 f"Too many requests to the API, please try again later. To avoid being rate-limited, please duplicate the Space using Client.duplicate({self.client.space_id}) and pass in your Hugging Face token."
TypeError: argument of type 'NoneType' is not iterable