sileod commited on
Commit
bcd7e20
Β·
verified Β·
1 Parent(s): 66a71cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -12
app.py CHANGED
@@ -9,10 +9,10 @@ def sent_tokenize(text):
9
  return [s.strip() for s in sentences if s.strip()]
10
 
11
  # Initialize the classifiers
12
- zero_shot_classifier = pipeline("zero-shot-classification", model="tasksource/ModernBERT-base-nli")
13
- nli_classifier = pipeline("text-classification", model="tasksource/ModernBERT-base-nli")
14
 
15
- # Define examples (including new long context example)
16
  zero_shot_examples = [
17
  ["I absolutely love this product, it's amazing!", "positive, negative, neutral"],
18
  ["I need to buy groceries", "shopping, urgent tasks, leisure, philosophy"],
@@ -131,7 +131,43 @@ def process_input(text_input, labels_or_premise, mode):
131
  analysis_html = create_analysis_html(sentence_results, global_label)
132
  return global_results, analysis_html
133
 
134
- # [Previous interface code remains the same until the outputs definition]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  with gr.Blocks() as demo:
136
  gr.Markdown("""
137
  # tasksource/ModernBERT-nli demonstration
@@ -167,7 +203,7 @@ with gr.Blocks() as demo:
167
 
168
  outputs = [
169
  gr.Label(label="πŸ“Š Results"),
170
- gr.HTML(label="πŸ“ˆ Sentence Analysis") # Changed from Markdown to HTML
171
  ]
172
 
173
  with gr.Column(variant="panel") as zero_shot_examples_panel:
@@ -191,13 +227,6 @@ with gr.Blocks() as demo:
191
  label="Long Context NLI Examples",
192
  )
193
 
194
- def update_visibility(mode):
195
- return (
196
- gr.update(visible=(mode == "Zero-Shot Classification")),
197
- gr.update(visible=(mode == "Natural Language Inference")),
198
- gr.update(visible=(mode == "Long Context NLI"))
199
- )
200
-
201
  mode.change(
202
  fn=update_interface,
203
  inputs=[mode],
 
9
  return [s.strip() for s in sentences if s.strip()]
10
 
11
  # Initialize the classifiers
12
+ zero_shot_classifier = pipeline("zero-shot-classification", model="tasksource/ModernBERT-base-nli", device="cpu")
13
+ nli_classifier = pipeline("text-classification", model="tasksource/ModernBERT-base-nli", device="cpu")
14
 
15
+ # [Previous example definitions remain the same]
16
  zero_shot_examples = [
17
  ["I absolutely love this product, it's amazing!", "positive, negative, neutral"],
18
  ["I need to buy groceries", "shopping, urgent tasks, leisure, philosophy"],
 
131
  analysis_html = create_analysis_html(sentence_results, global_label)
132
  return global_results, analysis_html
133
 
134
+ def update_interface(mode):
135
+ if mode == "Zero-Shot Classification":
136
+ return (
137
+ gr.update(
138
+ label="🏷️ Categories",
139
+ placeholder="Enter comma-separated categories...",
140
+ value=zero_shot_examples[0][1]
141
+ ),
142
+ gr.update(value=zero_shot_examples[0][0])
143
+ )
144
+ elif mode == "Natural Language Inference":
145
+ return (
146
+ gr.update(
147
+ label="πŸ”Ž Hypothesis",
148
+ placeholder="Enter a hypothesis to compare with the premise...",
149
+ value=nli_examples[0][1]
150
+ ),
151
+ gr.update(value=nli_examples[0][0])
152
+ )
153
+ else: # Long Context NLI
154
+ return (
155
+ gr.update(
156
+ label="πŸ”Ž Global Hypothesis",
157
+ placeholder="Enter a hypothesis to test against the full context...",
158
+ value=long_context_examples[0][1]
159
+ ),
160
+ gr.update(value=long_context_examples[0][0])
161
+ )
162
+
163
+ def update_visibility(mode):
164
+ return (
165
+ gr.update(visible=(mode == "Zero-Shot Classification")),
166
+ gr.update(visible=(mode == "Natural Language Inference")),
167
+ gr.update(visible=(mode == "Long Context NLI"))
168
+ )
169
+
170
+ # Now define the Blocks interface
171
  with gr.Blocks() as demo:
172
  gr.Markdown("""
173
  # tasksource/ModernBERT-nli demonstration
 
203
 
204
  outputs = [
205
  gr.Label(label="πŸ“Š Results"),
206
+ gr.HTML(label="πŸ“ˆ Sentence Analysis")
207
  ]
208
 
209
  with gr.Column(variant="panel") as zero_shot_examples_panel:
 
227
  label="Long Context NLI Examples",
228
  )
229
 
 
 
 
 
 
 
 
230
  mode.change(
231
  fn=update_interface,
232
  inputs=[mode],