我正在尝试调用我用Gradio库创建的聊天机器人的API。当我在gradio-client中查看API文档时,它显示:
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)
我对第二个参数感到困惑(# str表示'parameter_11' Chatbot组件中JSON文件的filepath)。Gradio Chatbot的JSON文件是什么样子的?我可以通过API获得使用Gradio聊天机器人的示例吗?下面是在Gradio文档中生成聊天机器人的代码:
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)
我试过密码了
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)
得到了错误
---------------------------------------------------------------------------
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
1条答案
按热度按时间beq87vna1#
面对这个Gradio API调用错误:File“/home/user/.local/lib/python3.10/site-packages/gradio_client/client.py”,line 824,in _predict raise ValueError(result[“error”])ValueError:没有一