Update app.py
Browse files
app.py
CHANGED
|
@@ -32,8 +32,9 @@ def process_input(text_input, labels_or_premise, mode):
|
|
| 32 |
results = {label: score for label, score in zip(prediction['labels'], prediction['scores'])}
|
| 33 |
return results, ''
|
| 34 |
else: # NLI mode
|
| 35 |
-
pred
|
| 36 |
-
results
|
|
|
|
| 37 |
return results, ''
|
| 38 |
|
| 39 |
def update_interface(mode):
|
|
@@ -41,17 +42,19 @@ def update_interface(mode):
|
|
| 41 |
return (
|
| 42 |
gr.update(
|
| 43 |
label="π·οΈ Categories",
|
| 44 |
-
placeholder="Enter comma-separated categories..."
|
|
|
|
| 45 |
),
|
| 46 |
-
gr.update()
|
| 47 |
)
|
| 48 |
else:
|
| 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:
|
|
@@ -75,14 +78,14 @@ with gr.Blocks() as demo:
|
|
| 75 |
label="βοΈ Input Text",
|
| 76 |
placeholder="Enter your text...",
|
| 77 |
lines=3,
|
| 78 |
-
value=zero_shot_examples[0][0]
|
| 79 |
)
|
| 80 |
|
| 81 |
labels_or_premise = gr.Textbox(
|
| 82 |
label="π·οΈ Categories",
|
| 83 |
placeholder="Enter comma-separated categories...",
|
| 84 |
lines=2,
|
| 85 |
-
value=zero_shot_examples[0][1]
|
| 86 |
)
|
| 87 |
|
| 88 |
submit_btn = gr.Button("Submit")
|
|
@@ -92,15 +95,11 @@ with gr.Blocks() as demo:
|
|
| 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:
|
|
@@ -108,8 +107,7 @@ with gr.Blocks() as demo:
|
|
| 108 |
examples=nli_examples,
|
| 109 |
inputs=[text_input, labels_or_premise],
|
| 110 |
label="Natural Language Inference Examples",
|
| 111 |
-
|
| 112 |
-
)
|
| 113 |
|
| 114 |
def update_visibility(mode):
|
| 115 |
return (
|
|
@@ -117,7 +115,6 @@ with gr.Blocks() as demo:
|
|
| 117 |
gr.update(visible=(mode == "Natural Language Inference"))
|
| 118 |
)
|
| 119 |
|
| 120 |
-
# Update interface on mode change
|
| 121 |
mode.change(
|
| 122 |
fn=update_interface,
|
| 123 |
inputs=[mode],
|
|
@@ -130,13 +127,6 @@ with gr.Blocks() as demo:
|
|
| 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(
|
| 141 |
fn=process_input,
|
| 142 |
inputs=[text_input, labels_or_premise, mode],
|
|
|
|
| 32 |
results = {label: score for label, score in zip(prediction['labels'], prediction['scores'])}
|
| 33 |
return results, ''
|
| 34 |
else: # NLI mode
|
| 35 |
+
pred= nli_classifier([{"text": text_input, "text_pair": labels_or_premise}],return_all_scores=True)[0]
|
| 36 |
+
results= {pred['label']:pred['score'] for pred in pred}
|
| 37 |
+
|
| 38 |
return results, ''
|
| 39 |
|
| 40 |
def update_interface(mode):
|
|
|
|
| 42 |
return (
|
| 43 |
gr.update(
|
| 44 |
label="π·οΈ Categories",
|
| 45 |
+
placeholder="Enter comma-separated categories...",
|
| 46 |
+
value=zero_shot_examples[0][1]
|
| 47 |
),
|
| 48 |
+
gr.update(value=zero_shot_examples[0][0])
|
| 49 |
)
|
| 50 |
else:
|
| 51 |
return (
|
| 52 |
gr.update(
|
| 53 |
label="π Hypothesis",
|
| 54 |
+
placeholder="Enter a hypothesis to compare with the premise...",
|
| 55 |
+
value=nli_examples[0][1]
|
| 56 |
),
|
| 57 |
+
gr.update(value=nli_examples[0][0])
|
| 58 |
)
|
| 59 |
|
| 60 |
with gr.Blocks() as demo:
|
|
|
|
| 78 |
label="βοΈ Input Text",
|
| 79 |
placeholder="Enter your text...",
|
| 80 |
lines=3,
|
| 81 |
+
value=zero_shot_examples[0][0] # Initial value
|
| 82 |
)
|
| 83 |
|
| 84 |
labels_or_premise = gr.Textbox(
|
| 85 |
label="π·οΈ Categories",
|
| 86 |
placeholder="Enter comma-separated categories...",
|
| 87 |
lines=2,
|
| 88 |
+
value=zero_shot_examples[0][1] # Initial value
|
| 89 |
)
|
| 90 |
|
| 91 |
submit_btn = gr.Button("Submit")
|
|
|
|
| 95 |
gr.Markdown(label="π Analysis", visible=False)
|
| 96 |
]
|
| 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 |
)
|
| 104 |
|
| 105 |
with gr.Column(variant="panel") as nli_examples_panel:
|
|
|
|
| 107 |
examples=nli_examples,
|
| 108 |
inputs=[text_input, labels_or_premise],
|
| 109 |
label="Natural Language Inference Examples",
|
| 110 |
+
)
|
|
|
|
| 111 |
|
| 112 |
def update_visibility(mode):
|
| 113 |
return (
|
|
|
|
| 115 |
gr.update(visible=(mode == "Natural Language Inference"))
|
| 116 |
)
|
| 117 |
|
|
|
|
| 118 |
mode.change(
|
| 119 |
fn=update_interface,
|
| 120 |
inputs=[mode],
|
|
|
|
| 127 |
outputs=[zero_shot_examples_panel, nli_examples_panel]
|
| 128 |
)
|
| 129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
submit_btn.click(
|
| 131 |
fn=process_input,
|
| 132 |
inputs=[text_input, labels_or_premise, mode],
|