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
34.21k stars 2.6k forks source link

`TabbedInterface` bug: Second Tab Running Logic of First Tab #8620

Closed amanmibra closed 5 months ago

amanmibra commented 5 months ago

Describe the bug

I have a gradio app with two functions for seperate purposes. When running the Interfaces in isolation, they work as expected. When I put them in the TabbedInterface, which ever tab is put first works fine, but the second one always begins running the logic of the first. Again, this happens no matter which of the interfaces I put first, the second tab always runs the others logic.

Have you searched existing issues? 🔎

Reproduction

# slightly edited from original source code
import gradio as gr

def a(audio):
  # not sharing source code
  print('foo')

def b(audio):
  print('bar')

a_demo = gr.Interface(
   a,
    "audio",
    "audio",
)

b_demo = gr.Interface(
    b,
    "audio",
    [gr.Number(label="Watermark Score (0-1)"), gr.Textbox(label="Watermark Message")],

)

demo = gr.TabbedInterface(
    [a_demo, b_demo],
    ["A Demo", "B Demo"],
)

def get_args():
    parser = argparse.ArgumentParser(description="Run the watermarking application")
    parser.add_argument(
        "--a", action="store_true", help="Launch only the watermark demo"
    )
    parser.add_argument(
        "--b", action="store_true", help="Launch only the check watermark demo"
    )
    parser.add_argument(
        "--port",
        type=int,
        default=7860,
        help="Specify the port number for the server to run on",
    )
    return parser.parse_args()

def main():
    args = get_args()
    if args.a:
        a_demo.launch(
            show_error=True, debug=True, server_port=args.port, share=True
        )
    elif args.b:
       b_demo.launch(
            show_error=True, debug=True, server_port=args.port, share=True
        )
    else:
        demo.launch(show_error=True, server_port=args.port)

Screenshot

No response

Logs

No response

System Info

Gradio Environment Information:
------------------------------
Operating System: Darwin
gradio version: 4.33.0
gradio_client version: 0.17.0

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

aiofiles: 23.2.1
altair: 5.3.0
fastapi: 0.111.0
ffmpy: 0.3.2
gradio-client==0.17.0 is not installed.
httpx: 0.27.0
huggingface-hub: 0.23.2
importlib-resources: 6.4.0
jinja2: 3.1.4
markupsafe: 2.1.5
matplotlib: 3.9.0
numpy: 1.26.4
orjson: 3.10.3
packaging: 24.0
pandas: 2.2.2
pillow: 10.3.0
pydantic: 2.7.3
pydub: 0.25.1
python-multipart: 0.0.9
pyyaml: 6.0.1
ruff: 0.4.7
semantic-version: 2.10.0
tomlkit==0.12.0 is not installed.
typer: 0.12.3
typing-extensions: 4.12.1
urllib3: 2.2.1
uvicorn: 0.30.1
authlib; extra == 'oauth' is not installed.
itsdangerous; extra == 'oauth' is not installed.

gradio_client dependencies in your environment:

fsspec: 2024.6.0
httpx: 0.27.0
huggingface-hub: 0.23.2
packaging: 24.0
typing-extensions: 4.12.1
websockets: 11.0.3


### Severity

I can work around it
abidlabs commented 5 months ago

Hi @amanmibra this issue has been fixed in the latest version of gradio -- can you please upgrade to 4.37.1?