mirror of
https://github.com/gradio-app/gradio.git
synced 2025-04-06 12:30:29 +08:00
Example caching now works with components without a label attribute (e.g. Column) (#3123)
* add non io component support for example caching * chaneglog
This commit is contained in:
parent
a23bc03aeb
commit
a0248f26dd
@ -15,6 +15,7 @@ By [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3089](https://git
|
||||
|
||||
## Bug Fixes:
|
||||
- Fixes URL resolution on Windows by [@abidlabs](https://github.com/abidlabs) in [PR 3108](https://github.com/gradio-app/gradio/pull/3108)
|
||||
- Example caching now works with components without a label attribute (e.g. `Column`) by [@abidlabs](https://github.com/abidlabs) in [PR 3123](https://github.com/gradio-app/gradio/pull/3123)
|
||||
- Ensure the Video component correctly resets the UI state whe a new video source is loaded and reduce choppiness of UI by [@pngwn](https://github.com/abidlabs) in [PR 3117](https://github.com/gradio-app/gradio/pull/3117)
|
||||
|
||||
## Documentation Changes:
|
||||
|
@ -201,7 +201,7 @@ class CSVLogger(FlaggingCallback):
|
||||
log_filepath = Path(flagging_dir) / "log.csv"
|
||||
is_new = not Path(log_filepath).exists()
|
||||
headers = [
|
||||
component.label or f"component {idx}"
|
||||
getattr(component, "label", None) or f"component {idx}"
|
||||
for idx, component in enumerate(self.components)
|
||||
] + [
|
||||
"flag",
|
||||
@ -212,7 +212,7 @@ class CSVLogger(FlaggingCallback):
|
||||
csv_data = []
|
||||
for idx, (component, sample) in enumerate(zip(self.components, flag_data)):
|
||||
save_dir = Path(flagging_dir) / utils.strip_invalid_filename_characters(
|
||||
component.label or f"component {idx}"
|
||||
getattr(component, "label", None) or f"component {idx}"
|
||||
)
|
||||
if utils.is_update(sample):
|
||||
csv_data.append(str(sample))
|
||||
|
@ -295,6 +295,27 @@ class TestProcessExamples:
|
||||
prediction = await io.examples_handler.load_from_cache(0)
|
||||
assert prediction == ["hel", "3"]
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_caching_with_non_io_component(self):
|
||||
def predict(name):
|
||||
return name, gr.update(visible=True)
|
||||
|
||||
with gr.Blocks():
|
||||
t1 = gr.Textbox()
|
||||
with gr.Column(visible=False) as c:
|
||||
t2 = gr.Textbox()
|
||||
|
||||
examples = gr.Examples(
|
||||
[["John"], ["Mary"]],
|
||||
fn=predict,
|
||||
inputs=[t1],
|
||||
outputs=[t2, c],
|
||||
cache_examples=True,
|
||||
)
|
||||
|
||||
prediction = await examples.load_from_cache(0)
|
||||
assert prediction == ["John", {"visible": True, "__type__": "update"}]
|
||||
|
||||
def test_end_to_end(self):
|
||||
def concatenate(str1, str2):
|
||||
return str1 + str2
|
||||
|
Loading…
x
Reference in New Issue
Block a user