gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
32.35k stars 2.42k forks source link

gradio app for chatbot expects prompts multiple times #5084

Closed nav1402 closed 1 year ago

nav1402 commented 1 year ago

Describe the bug

Sometimes chat question doesn't provide any response and come out immediately and I need to reenter the question again. Is there a existing fix for this problem?

Have you searched existing issues? 🔎

Reproduction

text_input = gr.Textbox( label='Chatbot Assistant', placeholder="Enter your message here" )

        txt_msg = text_input.submit(user, [text_input, chatbot], [text_input, chatbot], queue=False).then(
            callingfunction, chatbot, chatbot
        )

        txt_msg.then(
            lambda: gr.update(
            value="",
            interactive=True,
            placeholder="Enter your question",
            show_label=True,
            label="Enter your question",
        ),
        None,
        text_input,
        queue=False,

)

Screenshot

No response

Logs

No response

System Info

gradio==3.39.0

Severity

Blocking usage of gradio

abidlabs commented 1 year ago

Hi @nav1402 can you please provide a full, self-contained example we can test to reproduce this issue?

nav1402 commented 1 year ago

We used the code mentioned. Callingfunction has some raw text and text is sent to open ai LLM API. However in this it doesn’t even call the calling function as it doesn’t print any print statements inside calling function . This usually happen when there is time gap between 2 questions in the chatbot. Not sure if there is timeout issue here. This is causing user experience issues.

@abidlabs

abidlabs commented 1 year ago

The code here is incomplete. For example, chatbot is not defined.

nav1402 commented 1 year ago

Test_image I did put complete code previously but somehow it got cropped. Attached shows how we need to reenter the prompt twice.

def addText(user_message, history):
    return "", history + [[user_message, None]]

def callingfunction(history):
    return "Test"

with gr.Blocks() as demo:

    gr.Markdown("##Chatbot")

    with gr.Tabs():
        # Generating Code
        with gr.TabItem("Testing"):
            chatbot = gr.Chatbot()

            text_input_3 = gr.Textbox(
                label='Chatbot Assistant',
                placeholder="Enter your message here"
            )

            clear = gr.Button("Clear")

            txt_msg = text_input_3.submit(addText, [text_input_3, chatbot], [text_input_3, chatbot], queue=False).then(
                callingfunction, chatbot, chatbot
            )

            txt_msg.then(
                lambda: gr.update(
                value="",
                interactive=True,
                placeholder="Enter your question",
                show_label=True,
                label="Enter your question",
            ),
            None,
            text_input_3,
            queue=False,
            )

    clear.click(lambda: None, None, chatbot, queue=False)
demo.launch()

@abidlabs

abidlabs commented 1 year ago

Hi @nav1402 this is still incomplete code. For example, the method user() is not defined. Can you please provide the complete code so that I can run it on my end?

nav1402 commented 1 year ago

I have updated the code. Complete code has lot of custom logic.

@abidlabs

abidlabs commented 1 year ago

Complete code has lot of custom logic

I understand. But we will need some sort of self-contained example we can run on our own end to investigate the bug. Right now, getting:

NameError: name 'chatgpt' is not defined

Can you please ensure that your code actually fully runs?

The other thing I will recommend to you is to check out the ChatInterface class, which provides a clean abstraction over a lot of this code, and might solve the issue you are facing. The ChatInterface is described here: https://www.gradio.app/guides/creating-a-chatbot-fast

abidlabs commented 1 year ago

Closing for lack of follow up