-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
109 lines (83 loc) · 3.17 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
from wrap_gradio.application import Application
from wrap_gradio.layouts import RowLayout, TabLayout, ColumnLayout
from gradio import Textbox
from typing import Dict, Literal
from gradio.blocks import Block
def change_text(new_str: str):
return Textbox(value=new_str)
class RowExample(RowLayout):
def __init__(
self,
*,
name: str,
variant: Literal["default", "panel", "compact"] = "default",
visible: bool = True,
elem_id: str | None = None,
elem_classes: list[str] | str | None = None,
equal_height: bool = True
) -> None:
super().__init__(
name=name,
variant=variant,
visible=visible,
elem_id=elem_id,
elem_classes=elem_classes,
equal_height=equal_height,
)
self.left_textbox = Textbox(
value="Left Textbox", interactive=True, render=False
)
self.right_textbox = Textbox(value="Right Textbox", render=False)
self.add_component("left_textbox", self.left_textbox)
self.add_component("right_textbox", self.right_textbox)
def attach_event(self, block_dict: Dict[str, Block]) -> None:
self.left_textbox.change(
change_text,
inputs=self.left_textbox,
outputs=self.right_textbox,
)
class FirstTab(TabLayout):
def __init__(
self,
name: str,
visible: bool = True,
interactive: bool = True,
id: int | str | None = None,
elem_id: str | None = None,
elem_classes: list[str] | str | None = None,
) -> None:
super().__init__(name, visible, interactive, id, elem_id, elem_classes)
self.row = RowExample(name="first tab row layout")
self.add_layout(self.row)
def attach_event(self, block_dict: Dict[str, Block]) -> None:
self.row.attach_event(block_dict)
class SecondTab(TabLayout):
def __init__(
self,
name: str,
visible: bool = True,
interactive: bool = True,
id: int | str | None = None,
elem_id: str | None = None,
elem_classes: list[str] | str | None = None,
) -> None:
super().__init__(name, visible, interactive, id, elem_id, elem_classes)
self.column = ColumnLayout(name="second tab column layout")
self.top_textbox = Textbox(value="Top Textbox", interactive=True)
self.bottom_textbox = Textbox(value="Bottom Textbox")
self.column.add_component("top_textbox", self.top_textbox)
self.column.add_component("bottom_textbox", self.bottom_textbox)
self.add_layout(self.column)
def attach_event(self, block_dict: Dict[str, Block]) -> None:
block_dict["left_textbox"].change(
change_text,
inputs=block_dict["left_textbox"],
outputs=self.bottom_textbox,
)
if __name__ == "__main__":
gui = Application(title="Wrap Gradio")
first_tab = FirstTab(name="First Tab")
second_tab = SecondTab(name="Second Tab")
gui.add(first_tab)
gui.add(second_tab)
gui.launch()