I’m very new to both huggingface and Gradio, so forgive me if this is a trivial issue, and I’m just a fool.
I’m using a Blocks object to implement a very basic chatbot, and I’d like to essentially clear the input textbox after the user presses enter or presses the submit button.
with gr.Blocks() as test:
outp = gr.Chatbot(label="Reply", )
inp = gr.Textbox(label="Chat with AI")
inp.submit(chatbot, [outp, inp], outp)
inp.update(lambda: None, inp)
btn = gr.Button("Submit")
btn.click(fn=chatbot, inputs=inp, outputs=outp)
My code looks like this currently.
I simply wish to clear the input textbox after the input is submitted.
Hi @alexjedi
I came across the same issue.
In my scenario, I am using the chatbot UI from Gradio.
with gr.Blocks() as demo:
chatbot = gr.Chatbot()
msg = gr.Textbox()
clear = gr.Button("Clear")
chat_history = []
print(msg)
def user(user_message, history):
print("User message:", user_message)
print("Chat history:", history)
# Get response from QA chain
response = qa({"question": user_message, "chat_history": history})
# Append user message and response to chat history
history.append((user_message, response["answer"]))
print("Updated chat history:", history)
# Clear the message box
msg = ""
print(msg)
# Return response to chatbot
return response["answer"], history
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False)
clear.click(lambda: None, None, chatbot, queue=False)
I have the same problem that we I submit the query, the Textbox doesn’t get cleared, but also get filled up with the response from the model. (The response also shows up in the chat window, so the same text gets displayed twice!)
How can I modify the code so as soon as the model returns the response, the text box will also get cleared?
@radames
I just did and I got this error
UserWarning: Expected at least 1 arguments for function <function at 0x0000016A157749D0>, received 0
Note: It cleared the Textbox (thank you for that) when I send it works but I get this error on my ide
UserWarning: Unexpected argument. Filling with None.
warnings.warn(“Unexpected argument. Filling with None.”)
please help
Hi please I have the same problem using the blocks in Gradio
def chatgpt_clone(input, history):
history = history or
s = list(sum(history, ()))
s.append(input)
inp = ’ '.join(s)
output = openai_create(inp)
history.append((input, output))
return history, history