Yehor commited on
Commit
255552e
·
verified ·
1 Parent(s): e8c34ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -11
app.py CHANGED
@@ -101,7 +101,7 @@ def clean_value(x):
101
  return s
102
 
103
 
104
- def inference(file_name, _clear_punctuation, _show_chars, _batch_mode):
105
  if not file_name:
106
  raise gr.Error("Please paste your JSON file.")
107
 
@@ -143,19 +143,25 @@ def inference(file_name, _clear_punctuation, _show_chars, _batch_mode):
143
  references_batch = df["references"]
144
  predictions_batch = df["predictions"]
145
 
 
 
 
 
 
 
 
 
 
 
146
  predictions = []
147
  for prediction in predictions_batch:
148
- if _clear_punctuation:
149
  prediction = prediction.map_elements(
150
  clean_value, return_dtype=pl.String
151
  )
152
  predictions.extend(prediction)
153
  else:
154
  predictions.extend(prediction)
155
-
156
- references = []
157
- for reference in references_batch:
158
- references.extend(reference)
159
  else:
160
  if not all(col in df.columns for col in required_columns):
161
  raise gr.Error(
@@ -166,9 +172,14 @@ def inference(file_name, _clear_punctuation, _show_chars, _batch_mode):
166
 
167
  rtf = inference_seconds / duration_seconds
168
 
169
- references = df["reference"]
 
 
 
 
 
170
 
171
- if _clear_punctuation:
172
  predictions = df["prediction"].map_elements(
173
  clean_value, return_dtype=pl.String
174
  )
@@ -238,8 +249,11 @@ with demo:
238
  with gr.Column():
239
  jsonl_file = gr.File(label="A JSONL file")
240
 
241
- clear_punctuation = gr.Checkbox(
242
- label="Clear punctuation, some chars and convert to lowercase",
 
 
 
243
  )
244
  show_chars = gr.Checkbox(
245
  label="Show chars in predictions",
@@ -257,7 +271,7 @@ with demo:
257
  gr.Button("Calculate").click(
258
  inference,
259
  concurrency_limit=concurrency_limit,
260
- inputs=[jsonl_file, clear_punctuation, show_chars, batch_mode],
261
  outputs=metrics,
262
  )
263
 
 
101
  return s
102
 
103
 
104
+ def inference(file_name, _clear_punctuation_references, _clear_punctuation_predictions, _show_chars, _batch_mode):
105
  if not file_name:
106
  raise gr.Error("Please paste your JSON file.")
107
 
 
143
  references_batch = df["references"]
144
  predictions_batch = df["predictions"]
145
 
146
+ references = []
147
+ for reference in references_batch:
148
+ if _clear_punctuation_references:
149
+ reference = reference.map_elements(
150
+ clean_value, return_dtype=pl.String
151
+ )
152
+ references.extend(reference)
153
+ else:
154
+ references.extend(reference)
155
+
156
  predictions = []
157
  for prediction in predictions_batch:
158
+ if _clear_punctuation_predictions:
159
  prediction = prediction.map_elements(
160
  clean_value, return_dtype=pl.String
161
  )
162
  predictions.extend(prediction)
163
  else:
164
  predictions.extend(prediction)
 
 
 
 
165
  else:
166
  if not all(col in df.columns for col in required_columns):
167
  raise gr.Error(
 
172
 
173
  rtf = inference_seconds / duration_seconds
174
 
175
+ if _clear_punctuation_references:
176
+ references = df["references"].map_elements(
177
+ clean_value, return_dtype=pl.String
178
+ )
179
+ else:
180
+ references = df["reference"]
181
 
182
+ if _clear_punctuation_predictions:
183
  predictions = df["prediction"].map_elements(
184
  clean_value, return_dtype=pl.String
185
  )
 
249
  with gr.Column():
250
  jsonl_file = gr.File(label="A JSONL file")
251
 
252
+ clear_punctuation_references = gr.Checkbox(
253
+ label="Clear punctuation (in references), some chars and convert to lowercase",
254
+ )
255
+ clear_punctuation_predictions = gr.Checkbox(
256
+ label="Clear punctuation (in predictions), some chars and convert to lowercase",
257
  )
258
  show_chars = gr.Checkbox(
259
  label="Show chars in predictions",
 
271
  gr.Button("Calculate").click(
272
  inference,
273
  concurrency_limit=concurrency_limit,
274
+ inputs=[jsonl_file, clear_punctuation_references, clear_punctuation_predictions, show_chars, batch_mode],
275
  outputs=metrics,
276
  )
277