mirror of
https://github.com/gradio-app/gradio.git
synced 2025-04-06 12:30:29 +08:00
Fix loading interface with examples (#2640)
* fix examples * Fix test * Add unit test * Add CHANGELOG * Add unit test where load external * fix for older demos * Add comment
This commit is contained in:
parent
a8f961ec7e
commit
ebb65eb9ee
@ -5,6 +5,7 @@ No changes to highlight.
|
||||
|
||||
## Bug Fixes:
|
||||
* Updated the minimum FastApi used in tests to version 0.87 [@freddyaboulton](https://github.com/freddyaboulton) in [PR 2647](https://github.com/gradio-app/gradio/pull/2647)
|
||||
* Fixed bug where interfaces with examples could not be loaded with `gr.Interface.load` by [@freddyaboulton](https://github.com/freddyaboulton) [PR 2640](https://github.com/gradio-app/gradio/pull/2640)
|
||||
|
||||
## Documentation Changes:
|
||||
No changes to highlight.
|
||||
|
@ -622,6 +622,13 @@ class Blocks(BlockContext):
|
||||
|
||||
# add the event triggers
|
||||
for dependency, fn in zip(config["dependencies"], fns):
|
||||
# We used to add a "fake_event" to the config to cache examples
|
||||
# without removing it. This was causing bugs in calling gr.Interface.load
|
||||
# We fixed the issue by removing "fake_event" from the config in examples.py
|
||||
# but we still need to skip these events when loading the config to support
|
||||
# older demos
|
||||
if dependency["trigger"] == "fake_event":
|
||||
continue
|
||||
targets = dependency.pop("targets")
|
||||
trigger = dependency.pop("trigger")
|
||||
dependency.pop("backend_fn")
|
||||
|
@ -296,6 +296,9 @@ class Examples:
|
||||
if self.batch:
|
||||
output = [value[0] for value in output]
|
||||
cache_logger.flag(output)
|
||||
# Remove the "fake_event" to prevent bugs in loading interfaces from spaces
|
||||
Context.root_block.dependencies.remove(dependency)
|
||||
Context.root_block.fns.pop(fn_index)
|
||||
|
||||
async def load_from_cache(self, example_id: int) -> List[Any]:
|
||||
"""Loads a particular cached example for the interface.
|
||||
|
@ -179,6 +179,7 @@ class TestProcessExamples:
|
||||
)
|
||||
prediction = await io.examples_handler.load_from_cache(0)
|
||||
assert prediction == [{"lines": 4, "__type__": "update"}, {"label": "lion"}]
|
||||
assert not any(d["trigger"] == "fake_event" for d in io.config["dependencies"])
|
||||
|
||||
def test_raise_helpful_error_message_if_providing_partial_examples(self, tmp_path):
|
||||
def foo(a, b):
|
||||
|
@ -274,6 +274,15 @@ class TestLoadInterfaceWithExamples:
|
||||
]
|
||||
)
|
||||
|
||||
def test_interface_with_examples(self):
|
||||
# This demo has the "fake_event" correctly removed
|
||||
demo = gr.Interface.load("spaces/freddyaboulton/calculator")
|
||||
assert demo(2, "add", 3) == 5
|
||||
|
||||
# This demo still has the "fake_event". both should work
|
||||
demo = gr.Interface.load("spaces/abidlabs/test-calculator-2")
|
||||
assert demo(2, "add", 4) == 6
|
||||
|
||||
|
||||
def test_get_tabular_examples_replaces_nan_with_str_nan():
|
||||
readme = """
|
||||
|
Loading…
x
Reference in New Issue
Block a user