Closed guodage closed 1 year ago
This isn't supported at the moment. However, you can get the index of the selected value (instead of the full value) in the dropdown by setting the type
of the Dropdown
to be index
(e.g. gr.Dropdown(type="index")
) and then map the index to anything else. Does that work for you?
I agree this is very nice to have since you won't have to make modifications to the event callback functions just to map between values
Thanks for your opinion, index is a good way in some respects and I alse noted that in the Dropdown
’s doc.
The reason I didn't use index is my project is StableDiffusion WebUI that based on Gradio, I need change the event logic in the source code, like space-nuko said.
I agree this is very nice to have since you won't have to make modifications to the event callback functions just to map between values
Yes, this is my lazy point, hah :) Maybe I could learn to coding a PR for this.
I wonder if it would make sense to allow the choices
parameter in Dropdown
to also accept a list of tuples (text
, value
), WDYT @aliabid94 @freddyaboulton?
good idea, if the backward compatibility could be taked into consideration.
@freddyaboulton @pngwn I'm going to reclassify this as a "new component" since I think this would be a good example of a custom component that has the same frontend as an existing component (Dropdown) but a modified backend / preprocessing logic.
As https://github.com/gradio-app/gradio/issues/5033 was closed in favour of this one, I'd like to suggest expanding this issue to all components with choices
(not only dropdown)
And also I'd suggest this to be retrocompatible instead of a new component (an API suggestion to keep both is in #5033)
Thanks @apolinario, agreed
Todo: we need to fix #3703 as well while doing implementing this
fyi we have a separate issue for the other components that have choices
(radio button and checkboxgroup) here: https://github.com/gradio-app/gradio/issues/4754
Is your feature request related to a problem? Please describe.
My case is a DropDown contains a modle file list, which path is really long~~~ eg. a/b/c/d/x.ckpt, so I want to change text to shorter x.ckpt, and maintain the original value.
Describe the solution you'd like
DropDown support a text handle fn, the param is the original value.
Additional context
a small question: I've not seen any issue or doc about this, it's my problem?