Update app.py
Browse files
app.py
CHANGED
@@ -41,7 +41,7 @@ def update_interface(mode):
|
|
41 |
return (
|
42 |
gr.update(
|
43 |
label="π·οΈ Categories",
|
44 |
-
placeholder="Enter comma-separated categories..."
|
45 |
),
|
46 |
gr.update()
|
47 |
)
|
@@ -49,18 +49,11 @@ def update_interface(mode):
|
|
49 |
return (
|
50 |
gr.update(
|
51 |
label="π Hypothesis",
|
52 |
-
placeholder="Enter a hypothesis to compare with the premise..."
|
53 |
),
|
54 |
gr.update()
|
55 |
)
|
56 |
|
57 |
-
def handle_example_selection(evt: gr.SelectData, mode):
|
58 |
-
# Return the appropriate label based on the current mode
|
59 |
-
if mode == "Zero-Shot Classification":
|
60 |
-
return gr.update(label="π·οΈ Categories")
|
61 |
-
else:
|
62 |
-
return gr.update(label="π Hypothesis")
|
63 |
-
|
64 |
with gr.Blocks() as demo:
|
65 |
gr.Markdown("""
|
66 |
# tasksource/ModernBERT-nli demonstration
|
@@ -99,18 +92,23 @@ with gr.Blocks() as demo:
|
|
99 |
gr.Markdown(label="π Analysis", visible=False)
|
100 |
]
|
101 |
|
|
|
|
|
|
|
102 |
with gr.Column(variant="panel") as zero_shot_examples_panel:
|
103 |
-
|
104 |
examples=zero_shot_examples,
|
105 |
inputs=[text_input, labels_or_premise],
|
106 |
label="Zero-Shot Classification Examples",
|
|
|
107 |
)
|
108 |
|
109 |
with gr.Column(variant="panel") as nli_examples_panel:
|
110 |
-
|
111 |
examples=nli_examples,
|
112 |
inputs=[text_input, labels_or_premise],
|
113 |
label="Natural Language Inference Examples",
|
|
|
114 |
)
|
115 |
|
116 |
def update_visibility(mode):
|
@@ -132,17 +130,11 @@ with gr.Blocks() as demo:
|
|
132 |
outputs=[zero_shot_examples_panel, nli_examples_panel]
|
133 |
)
|
134 |
|
135 |
-
#
|
136 |
-
|
137 |
-
fn=
|
138 |
-
inputs=[mode],
|
139 |
-
outputs=[labels_or_premise]
|
140 |
-
)
|
141 |
-
|
142 |
-
examples_nli.select(
|
143 |
-
fn=handle_example_selection,
|
144 |
inputs=[mode],
|
145 |
-
outputs=[labels_or_premise]
|
146 |
)
|
147 |
|
148 |
submit_btn.click(
|
|
|
41 |
return (
|
42 |
gr.update(
|
43 |
label="π·οΈ Categories",
|
44 |
+
placeholder="Enter comma-separated categories..."
|
45 |
),
|
46 |
gr.update()
|
47 |
)
|
|
|
49 |
return (
|
50 |
gr.update(
|
51 |
label="π Hypothesis",
|
52 |
+
placeholder="Enter a hypothesis to compare with the premise..."
|
53 |
),
|
54 |
gr.update()
|
55 |
)
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
with gr.Blocks() as demo:
|
58 |
gr.Markdown("""
|
59 |
# tasksource/ModernBERT-nli demonstration
|
|
|
92 |
gr.Markdown(label="π Analysis", visible=False)
|
93 |
]
|
94 |
|
95 |
+
# Create a dummy textbox to trigger updates when examples are selected
|
96 |
+
example_trigger = gr.Textbox(visible=False)
|
97 |
+
|
98 |
with gr.Column(variant="panel") as zero_shot_examples_panel:
|
99 |
+
gr.Examples(
|
100 |
examples=zero_shot_examples,
|
101 |
inputs=[text_input, labels_or_premise],
|
102 |
label="Zero-Shot Classification Examples",
|
103 |
+
outputs=example_trigger
|
104 |
)
|
105 |
|
106 |
with gr.Column(variant="panel") as nli_examples_panel:
|
107 |
+
gr.Examples(
|
108 |
examples=nli_examples,
|
109 |
inputs=[text_input, labels_or_premise],
|
110 |
label="Natural Language Inference Examples",
|
111 |
+
outputs=example_trigger
|
112 |
)
|
113 |
|
114 |
def update_visibility(mode):
|
|
|
130 |
outputs=[zero_shot_examples_panel, nli_examples_panel]
|
131 |
)
|
132 |
|
133 |
+
# Update the label whenever an example is selected
|
134 |
+
example_trigger.change(
|
135 |
+
fn=update_interface,
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
inputs=[mode],
|
137 |
+
outputs=[labels_or_premise, text_input]
|
138 |
)
|
139 |
|
140 |
submit_btn.click(
|