Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: type object 'Dropdown' has no attribute 'update' #6862

Closed
1 task done
gautamsabba opened this issue Dec 21, 2023 · 4 comments
Closed
1 task done

AttributeError: type object 'Dropdown' has no attribute 'update' #6862

gautamsabba opened this issue Dec 21, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@gautamsabba
Copy link

Describe the bug

Looks like update() on components is broken in 4.11.0

Have you searched existing issues? 馃攷

  • I have searched and found no existing issues

Reproduction

import gradio as gr

categories = ['Long-Short Equity', 'Long Government', 'Multisector Bond', 'Emerging Markets Bond', 'Corporate Bond', 'Intermediate Government', 'Inflation-Protected Bond', 'Intermediate-Term Bond', 'Muni National Long', 'Unknown', 'High Yield Muni', 'Long-Term Bond', 'Muni California Long', 'Muni National Interm', 'Nontraditional Bond', 'World Bond', 'Short Government', 'Muni National Short', 'Short-Term Bond', 'Preferred Stock', 'Ultrashort Bond', 'High Yield Bond', 'Muni New York Long', 'Emerging-Markets Local-Currency Bond', 'Miscellaneous Region', 'Bank Loan', 'Commodities Broad Basket', 'Japan Stock', 'World Allocation', 'Tactical Allocation', 'Large Value', 'Foreign Large Growth', 'Energy Limited Partnership', 'Foreign Small/Mid Blend', 'Foreign Large Value', 'Foreign Large Blend', 'Europe Stock', 'Allocation--50% to 70% Equity', 'Financial', 'Diversified Emerging Mkts', 'Industrials', 'Mid-Cap Blend', 'Large Growth', 'Communications', 'Diversified Pacific/Asia', 'Foreign Small/Mid Value', 'Convertibles', 'Small Value', 'Latin America Stock', 'Equity Energy', 'Natural Resources', 'Real Estate', 'Large Blend', 'Small Blend', 'Consumer Cyclical']

def update_symbols(category):
    symbols =  ['FFIU', 'IGEB', 'VCIT', 'FCOR', 'SKOR', 'KORP', 'LQDI']
    return gr.Dropdown.update(choices=symbols)

# Create the Gradio interface
with gr.Blocks() as demo:
    gr.Markdown("### Dropdown Tester")
    with gr.Row():
        category_dropdown = gr.Dropdown(choices=categories, label="Category")
        symbol_dropdown = gr.Dropdown(label="Symbols", choices=[])

    # Update the symbols dropdown when the category changes
    category_dropdown.select(update_symbols, inputs=[category_dropdown], outputs=[symbol_dropdown])

demo.launch()

### Screenshot

_No response_

### Logs

```shell
Traceback (most recent call last):
  File "C:\Users\gauta\AppData\Roaming\Python\Python311\site-packages\gradio\queueing.py", line 489, in call_prediction
    output = await route_utils.call_process_api(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\gauta\AppData\Roaming\Python\Python311\site-packages\gradio\route_utils.py", line 232, in call_process_api
    output = await app.get_blocks().process_api(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\gauta\AppData\Roaming\Python\Python311\site-packages\gradio\blocks.py", line 1533, in process_api
    result = await self.call_function(
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\gauta\AppData\Roaming\Python\Python311\site-packages\gradio\blocks.py", line 1151, in call_function
    prediction = await anyio.to_thread.run_sync(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\gauta\AppData\Roaming\Python\Python311\site-packages\anyio\to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\gauta\AppData\Roaming\Python\Python311\site-packages\anyio\_backends\_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
           ^^^^^^^^^^^^
  File "C:\Users\gauta\AppData\Roaming\Python\Python311\site-packages\anyio\_backends\_asyncio.py", line 807, in run
    result = context.run(func, *args)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\gauta\AppData\Roaming\Python\Python311\site-packages\gradio\utils.py", line 678, in wrapper
    response = f(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^
  File "L:\My Drive\GPT3Demo\src\family_office\app.py", line 19, in update_symbols
    return gr.Dropdown.update(choices=symbols)
           ^^^^^^^^^^^^^^^^^^
AttributeError: type object 'Dropdown' has no attribute 'update'

System Info

Gradio Environment Information:
------------------------------
Operating System: Windows
gradio version: 4.11.0
gradio_client version: 0.7.3

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

aiofiles: 23.2.1
altair: 5.1.1
fastapi: 0.103.1
ffmpy: 0.3.1
gradio-client==0.7.3 is not installed.
httpx: 0.25.0
huggingface-hub: 0.19.4
importlib-resources: 6.0.1
jinja2: 3.1.2
markupsafe: 2.1.3
matplotlib: 3.8.0
numpy: 1.26.0
orjson: 3.9.7
packaging: 23.1
pandas: 2.1.0
pillow: 10.0.1
pydantic: 2.5.1
pydub: 0.25.1
python-multipart: 0.0.6
pyyaml: 6.0.1
semantic-version: 2.10.0
tomlkit==0.12.0 is not installed.
typer: 0.9.0
typing-extensions: 4.8.0
uvicorn: 0.23.2
authlib; extra == 'oauth' is not installed.
itsdangerous; extra == 'oauth' is not installed.


gradio_client dependencies in your environment:

fsspec: 2023.9.1
httpx: 0.25.0
huggingface-hub: 0.19.4
packaging: 23.1
typing-extensions: 4.8.0
websockets: 11.0.3

Severity

Blocking usage of gradio

@gautamsabba gautamsabba added the bug Something isn't working label Dec 21, 2023
@gautamsabba
Copy link
Author

These don't work either. However, the label gets updated correctly.

return gr.update(label="New Symbols", choices=['A','B'])

return gr.Dropdown(label="New Symbols", choices=['A','B'])

@abidlabs
Copy link
Member

Hi @gautamsabba there are two issues here:

  1. Yes, in Gradio 4.x the .update() method of components has been deprecated, now you can simply return the component itself

  2. You'll want to make sure the output Dropdown component is interactive so that you can click on it and look through the options. By default, Gradio sets output components to be non-interactive, but you can change that by passing in interactive=True

This is a working version of your app:

import gradio as gr

categories = ['Long-Short Equity', 'Long Government', 'Multisector Bond', 'Emerging Markets Bond', 'Corporate Bond', 'Intermediate Government', 'Inflation-Protected Bond', 'Intermediate-Term Bond', 'Muni National Long', 'Unknown', 'High Yield Muni', 'Long-Term Bond', 'Muni California Long', 'Muni National Interm', 'Nontraditional Bond', 'World Bond', 'Short Government', 'Muni National Short', 'Short-Term Bond', 'Preferred Stock', 'Ultrashort Bond', 'High Yield Bond', 'Muni New York Long', 'Emerging-Markets Local-Currency Bond', 'Miscellaneous Region', 'Bank Loan', 'Commodities Broad Basket', 'Japan Stock', 'World Allocation', 'Tactical Allocation', 'Large Value', 'Foreign Large Growth', 'Energy Limited Partnership', 'Foreign Small/Mid Blend', 'Foreign Large Value', 'Foreign Large Blend', 'Europe Stock', 'Allocation--50% to 70% Equity', 'Financial', 'Diversified Emerging Mkts', 'Industrials', 'Mid-Cap Blend', 'Large Growth', 'Communications', 'Diversified Pacific/Asia', 'Foreign Small/Mid Value', 'Convertibles', 'Small Value', 'Latin America Stock', 'Equity Energy', 'Natural Resources', 'Real Estate', 'Large Blend', 'Small Blend', 'Consumer Cyclical']

def update_symbols(category):
    symbols =  ['FFIU', 'IGEB', 'VCIT', 'FCOR', 'SKOR', 'KORP', 'LQDI']
    return gr.Dropdown(choices=symbols, interactive=True)

# Create the Gradio interface
with gr.Blocks() as demo:
    gr.Markdown("### Dropdown Tester")
    with gr.Row():
        category_dropdown = gr.Dropdown(choices=categories, label="Category")
        symbol_dropdown = gr.Dropdown(label="Symbols", choices=[])

    # Update the symbols dropdown when the category changes
    category_dropdown.change(update_symbols, inputs=[category_dropdown], outputs=[symbol_dropdown])

demo.launch()

@gautamsabba
Copy link
Author

Thank you.

@Akhil-VSSG
Copy link

Akhil-VSSG commented Apr 4, 2024

when i remove the options from the first drop down iam getting undefined for the options i selected in the dropdown_2 instead of giving me an empty drop_down
Screenshot 2024-04-04 at 5 41 16鈥疨M
Screenshot 2024-04-04 at 5 41 26鈥疨M

please tell me how to remove this bug @abidlabs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants