ZeroCommand commited on
Commit
a8753de
1 Parent(s): 79d57ff

change space ui and loading dynamically

Browse files
Files changed (1) hide show
  1. app.py +84 -49
app.py CHANGED
@@ -31,7 +31,7 @@ def check_model(model_id):
31
  try:
32
  from transformers import pipeline
33
  ppl = pipeline(task=task, model=model_id)
34
-
35
  return model_id, ppl
36
  except Exception as e:
37
  return model_id, e
@@ -59,7 +59,6 @@ def check_dataset(dataset_id, dataset_config="default", dataset_split="test"):
59
  return dataset_id, None, None
60
  return dataset_id, dataset_config, dataset_split
61
 
62
-
63
  def try_validate(model_id, dataset_id, dataset_config, dataset_split, column_mapping):
64
  # Validate model
65
  m_id, ppl = check_model(model_id=model_id)
@@ -144,7 +143,8 @@ def try_validate(model_id, dataset_id, dataset_config, dataset_split, column_map
144
  gr.Info("Model and dataset validations passed. Your can submit the evaluation task.")
145
 
146
  return (
147
- config, split,
 
148
  gr.update(interactive=True), # Submit button
149
  gr.update(value=prediction_result, visible=True), # Model prediction preview
150
  gr.update(value=id2label_df, visible=True), # Label mapping preview
@@ -199,52 +199,86 @@ def try_submit(m_id, d_id, config, split, column_mappings, local):
199
 
200
 
201
  with gr.Blocks(theme=theme) as iface:
202
- with gr.Row():
203
- with gr.Column():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  model_id_input = gr.Textbox(
205
  label="Hugging Face model id",
206
- placeholder="e.g.: cardiffnlp/twitter-roberta-base-sentiment-latest",
207
  )
208
 
209
- # TODO: Add supported model pairs: Text Classification - text-classification
210
- model_type = gr.Dropdown(
211
- label="Hugging Face model type",
212
- choices=[
213
- ("Auto-detect", 0),
214
- ("Text Classification", 1),
215
- ],
216
- value=0,
217
- )
218
- example_labels = gr.Label(label='Model prediction result', visible=False)
219
-
220
- id2label_mapping_dataframe = gr.DataFrame(
221
- label="Preview of label mapping",
222
- visible=False,
223
- )
224
-
225
- with gr.Column():
226
  dataset_id_input = gr.Textbox(
227
- label="Hugging Face dataset id",
228
- placeholder="e.g.: tweet_eval",
229
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230
 
231
- dataset_config_input = gr.Dropdown(
232
- label="Hugging Face dataset subset",
233
- choices=[
234
- "default",
235
- ],
236
- allow_custom_value=True,
237
- value="default",
238
- )
 
239
 
240
- dataset_split_input = gr.Dropdown(
241
- label="Hugging Face dataset split",
242
- choices=[
243
- "test",
244
- ],
245
- allow_custom_value=True,
246
- value="test",
247
- )
248
 
249
  with gr.Accordion("Advance", open=False):
250
  run_local = gr.Checkbox(value=True, label="Run in this Space")
@@ -259,10 +293,8 @@ with gr.Blocks(theme=theme) as iface:
259
  '}',
260
  )
261
 
262
- with gr.Row():
263
- validate_btn = gr.Button("Validate model and dataset", variant="primary")
264
  run_btn = gr.Button(
265
- "Submit evaluation task",
266
  variant="primary",
267
  interactive=False,
268
  )
@@ -273,17 +305,17 @@ with gr.Blocks(theme=theme) as iface:
273
  dataset_id_input,
274
  dataset_config_input,
275
  dataset_split_input,
276
- column_mapping_input,
277
  ],
278
  outputs=[
279
- dataset_config_input,
280
- dataset_split_input,
281
  run_btn,
282
  example_labels,
283
  id2label_mapping_dataframe,
284
  column_mapping_input,
285
  ],
286
  )
 
287
  run_btn.click(
288
  try_submit,
289
  inputs=[
@@ -299,5 +331,8 @@ with gr.Blocks(theme=theme) as iface:
299
  ],
300
  )
301
 
302
- iface.queue(max_size=20)
303
- iface.launch()
 
 
 
 
31
  try:
32
  from transformers import pipeline
33
  ppl = pipeline(task=task, model=model_id)
34
+
35
  return model_id, ppl
36
  except Exception as e:
37
  return model_id, e
 
59
  return dataset_id, None, None
60
  return dataset_id, dataset_config, dataset_split
61
 
 
62
  def try_validate(model_id, dataset_id, dataset_config, dataset_split, column_mapping):
63
  # Validate model
64
  m_id, ppl = check_model(model_id=model_id)
 
143
  gr.Info("Model and dataset validations passed. Your can submit the evaluation task.")
144
 
145
  return (
146
+ gr.update(visible=False), # Loading row
147
+ gr.update(visible=True), # Preview row
148
  gr.update(interactive=True), # Submit button
149
  gr.update(value=prediction_result, visible=True), # Model prediction preview
150
  gr.update(value=id2label_df, visible=True), # Label mapping preview
 
199
 
200
 
201
  with gr.Blocks(theme=theme) as iface:
202
+ with gr.Tab("Text Classification"):
203
+ global_ds_id = gr.State('ds')
204
+
205
+ def check_dataset_and_get_config(dataset_id):
206
+ global_ds_id.value = dataset_id
207
+ try:
208
+ configs = datasets.get_dataset_config_names(dataset_id)
209
+ print(configs)
210
+ return gr.Dropdown(configs, value=configs[0], visible=True)
211
+ except Exception:
212
+ # Dataset may not exist
213
+ pass
214
+
215
+ def check_dataset_and_get_split(choice):
216
+ print('choice: ',choice, global_ds_id.value)
217
+ try:
218
+ splits = list(datasets.load_dataset(global_ds_id.value, choice).keys())
219
+ print('splits: ',splits)
220
+ return gr.Dropdown(splits, value=splits[0], visible=True)
221
+ except Exception as e:
222
+ # Dataset may not exist
223
+ print(e)
224
+ pass
225
+
226
+ def gate_validate_btn(model_id, dataset_id, dataset_config, dataset_split):
227
+ print('model_id: ',model_id)
228
+ if model_id and dataset_id and dataset_config and dataset_split:
229
+ return gr.update(interactive=True)
230
+ else:
231
+ return gr.update(interactive=False)
232
+
233
+ with gr.Row():
234
  model_id_input = gr.Textbox(
235
  label="Hugging Face model id",
236
+ placeholder="cardiffnlp/twitter-roberta-base-sentiment-latest",
237
  )
238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  dataset_id_input = gr.Textbox(
240
+ label="Hugging Face Dataset id",
241
+ placeholder="tweet_eval",
242
  )
243
+ with gr.Row():
244
+ dataset_config_input = gr.Dropdown(['default'], value=['default'], label='Dataset Config', visible=False)
245
+ dataset_split_input = gr.Dropdown(['default'], value=['default'], label='Dataset Split', visible=False)
246
+
247
+ dataset_id_input.change(check_dataset_and_get_config, dataset_id_input, dataset_config_input)
248
+ dataset_config_input.change(check_dataset_and_get_split, dataset_config_input, dataset_split_input)
249
+
250
+ with gr.Row():
251
+ validate_btn = gr.Button("Validate Model and Dataset", variant="primary", interactive=False)
252
+ model_id_input.change(gate_validate_btn,
253
+ inputs=[model_id_input, dataset_id_input, dataset_config_input, dataset_split_input],
254
+ outputs=[validate_btn])
255
+ dataset_id_input.change(gate_validate_btn,
256
+ inputs=[model_id_input, dataset_id_input, dataset_config_input, dataset_split_input],
257
+ outputs=[validate_btn])
258
+ dataset_config_input.change(gate_validate_btn,
259
+ inputs=[model_id_input, dataset_id_input, dataset_config_input, dataset_split_input],
260
+ outputs=[validate_btn])
261
+ dataset_split_input.change(gate_validate_btn,
262
+ inputs=[model_id_input, dataset_id_input, dataset_config_input, dataset_split_input],
263
+ outputs=[validate_btn])
264
+
265
+ with gr.Row(visible=True) as loading_row:
266
+ gr.Markdown('''
267
+ <h1 style="text-align: center;">
268
+ Please validate your model and dataset first...
269
+ </h1>
270
+ ''')
271
 
272
+ with gr.Row(visible=False) as preview_row:
273
+ with gr.Column():
274
+ id2label_mapping_dataframe = gr.DataFrame(label="Preview of label mapping")
275
+
276
+ gr.Markdown('''
277
+ <span style="background-color:#5fc269; color:white">Does this look right? If not, Check and update your feature mapping -></span>
278
+ ''')
279
+
280
+ example_labels = gr.Label(label='Model Prediction Sample')
281
 
 
 
 
 
 
 
 
 
282
 
283
  with gr.Accordion("Advance", open=False):
284
  run_local = gr.Checkbox(value=True, label="Run in this Space")
 
293
  '}',
294
  )
295
 
 
 
296
  run_btn = gr.Button(
297
+ "Get Evaluation Result",
298
  variant="primary",
299
  interactive=False,
300
  )
 
305
  dataset_id_input,
306
  dataset_config_input,
307
  dataset_split_input,
 
308
  ],
309
  outputs=[
310
+ loading_row,
311
+ preview_row,
312
  run_btn,
313
  example_labels,
314
  id2label_mapping_dataframe,
315
  column_mapping_input,
316
  ],
317
  )
318
+
319
  run_btn.click(
320
  try_submit,
321
  inputs=[
 
331
  ],
332
  )
333
 
334
+ with gr.Tab("More"):
335
+ pass
336
+
337
+ if __name__ == "__main__":
338
+ iface.queue(max_size=20).launch()