|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import gradio |
|
from gradio import components |
|
from gradio.components.base import Component |
|
from gradio.data_classes import ( |
|
GradioModel, |
|
GradioRootModel, |
|
) |
|
|
|
from gradio.blocks import BlockContext |
|
|
|
|
|
def patched_postprocess_update_dict( |
|
block: Component | BlockContext, update_dict: dict, postprocess: bool = True |
|
): |
|
""" |
|
This is a patched version of the original function where 'pop' is replaced with 'get' in the first line. |
|
The key will no longer be removed but can still be accessed safely. |
|
This fixed gradio.Radio component persisting the value selection through gradio.Examples. |
|
""" |
|
value = update_dict.get("value", components._Keywords.NO_VALUE) |
|
|
|
|
|
update_dict = {k: getattr(block, k) for k in update_dict if hasattr(block, k)} |
|
if value is not components._Keywords.NO_VALUE: |
|
if postprocess: |
|
update_dict["value"] = block.postprocess(value) |
|
if isinstance(update_dict["value"], (GradioModel, GradioRootModel)): |
|
update_dict["value"] = update_dict["value"].model_dump() |
|
else: |
|
update_dict["value"] = value |
|
update_dict["__type__"] = "update" |
|
return update_dict |
|
|
|
|
|
gradio.blocks.postprocess_update_dict = patched_postprocess_update_dict |
|
|
|
from gradio.events import Dependency |
|
|
|
class Radio(gradio.Radio): |
|
pass |
|
from typing import Callable, Literal, Sequence, Any, TYPE_CHECKING |
|
from gradio.blocks import Block |
|
if TYPE_CHECKING: |
|
from gradio.components import Timer |