mirror of
https://github.com/gradio-app/gradio.git
synced 2025-04-06 12:30:29 +08:00
Allow displaying gr.Code examples by their filename if value is a tuple (#7912)
* Add code * add changeset * add changeset * Only display filename --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
parent
867ff16cd4
commit
a4782f7a09
5
.changeset/fast-walls-drop.md
Normal file
5
.changeset/fast-walls-drop.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"gradio": patch
|
||||
---
|
||||
|
||||
feat:Allow displaying gr.Code examples by their filename if value is a tuple
|
@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Any, Callable, Literal
|
||||
|
||||
from gradio_client.documentation import document
|
||||
@ -163,3 +164,8 @@ class Code(Component):
|
||||
|
||||
def example_value(self) -> Any:
|
||||
return "print('Hello World')"
|
||||
|
||||
def process_example(self, value: str | tuple[str] | None) -> str | None:
|
||||
if isinstance(value, tuple):
|
||||
return Path(value[0]).name
|
||||
return super().process_example(value)
|
||||
|
@ -2935,6 +2935,15 @@ class TestCode:
|
||||
"_selectable": False,
|
||||
}
|
||||
|
||||
def test_process_example(self):
|
||||
code = gr.Code()
|
||||
assert (
|
||||
code.process_example("def fn(a):\n return a") == "def fn(a):\n return a"
|
||||
)
|
||||
assert code.process_example(None) is None
|
||||
filename = str(Path("test/test_files/test_label_json.json"))
|
||||
assert code.process_example((filename,)) == "test_label_json.json"
|
||||
|
||||
|
||||
class TestFileExplorer:
|
||||
def test_component_functions(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user