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
33.83k stars 2.57k forks source link

Issue while integrating the functions with Gradio. #7928

Closed MadhavSalunkhe closed 4 months ago

MadhavSalunkhe commented 7 months ago

Describe the bug

I wrote two function 1. One for ask User input like "Please enter your name" and

  1. Other function to ask user query, and I need to interface this with Gradio app.
  2. When I trying to run this then gradio has been launched successfully but it asks only for User input. When I give my name to the bot then again it is asking same question.
  3. It means that it is not calling to the second function.
  4. I tried with different components, but its not working.
  5. Here I attached screen shots of gradio output. Please suggest solution for that.

Have you searched existing issues? 🔎

Reproduction

import gradio as gr
import random
import time
US=""

with gr.Blocks() as demo:
    chatbot = gr.Chatbot()
    msg = gr.Textbox()
    send = gr.ClearButton([msg, chatbot])

    def user_input(UserName, chat_history):
        bot_message = "Please enter your name"
        chat_history.append([UserName, bot_message])
        US=UserName
        print("mes:" + UserName)
        print("Bot" + bot_message)
        print(f"Name:",US)
        return US, chat_history   

    def User_Query(Query, chat_history):
        bot_message = "Please enter your Query"
        chat_history.append([Query, bot_message])
        US=UserName
        print("Que:" + Query)
        print("Bot" + bot_message)
        print(f"Name:",US)
        return Query, chat_history    

    msg.submit(user_input, [msg, chatbot], [msg, chatbot], queue=False).then(User_Query)

    # msg.submit(user_input,  [msg, chatbot],[msg, chatbot], queue=False).then(User_Query, [msg, chatbot], [msg, chatbot])

    # print(f"Name:",US)
    demo.queue()
    demo.launch()

Screenshot

image

Logs

No response

System Info

Gradio Environment Information:
------------------------------
Operating System: Windows
gradio version: 4.24.0
gradio_client version: 0.14.0

------------------------------------------------
gradio dependencies in your environment:

aiofiles: 23.2.1
altair: 5.2.0
fastapi: 0.110.0
ffmpy: 0.3.2
gradio-client==0.14.0 is not installed.
httpx: 0.27.0
huggingface-hub: 0.20.3
importlib-resources: 6.1.2
jinja2: 3.1.3
markupsafe: 2.1.5
matplotlib: 3.8.3
numpy: 1.26.4
orjson: 3.9.15
packaging: 23.2
pandas: 2.2.1
pillow: 10.2.0
pydantic: 2.6.4
pydub: 0.25.1
python-multipart: 0.0.9
pyyaml: 6.0.1
ruff: 0.3.4
semantic-version: 2.10.0
tomlkit==0.12.0 is not installed.
typer: 0.9.0
typing-extensions: 4.9.0
uvicorn: 0.20.0
authlib; extra == 'oauth' is not installed.
itsdangerous; extra == 'oauth' is not installed.

gradio_client dependencies in your environment:

fsspec: 2024.2.0
httpx: 0.27.0
huggingface-hub: 0.20.3
packaging: 23.2
typing-extensions: 4.9.0
websockets: 10.4

Severity

I can work around it

abidlabs commented 4 months ago

Hi @MadhavSalunkhe for general questions like this (that are not feature requests or bug reports), please ask in our Discord server. (I'll close this issue)