inoki-giskard commited on
Commit
88f768f
1 Parent(s): 01942d8

Add a simple model validation

Browse files
Files changed (1) hide show
  1. app.py +30 -4
app.py CHANGED
@@ -1,11 +1,26 @@
1
  import gradio as gr
2
  import datasets
 
3
 
4
 
5
  theme = gr.themes.Soft(
6
  primary_hue="green",
7
  )
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  def check_dataset(dataset_id, dataset_config="default", dataset_split="test"):
11
  try:
@@ -30,16 +45,25 @@ def check_dataset(dataset_id, dataset_config="default", dataset_split="test"):
30
  return dataset_id, dataset_config, dataset_split
31
 
32
 
33
- def try_submit(dataset_id, dataset_config, dataset_split):
 
 
 
 
 
 
 
 
 
34
  # Validate dataset
35
  d_id, config, split = check_dataset(dataset_id=dataset_id, dataset_config=dataset_config, dataset_split=dataset_split)
36
 
37
  if d_id is None:
38
  gr.Warning(f'Dataset "{dataset_id}" is not accessible. Please set your HF_TOKEN if it is a private dataset.')
39
- if isinstance(config, list):
40
  gr.Warning(f'Dataset "{dataset_id}" does have "{dataset_config}" config. Please choose a valid config.')
41
  config = gr.Dropdown.update(choices=config, value=config[0])
42
- if isinstance(split, list):
43
  gr.Warning(f'Dataset "{dataset_id}" does have "{dataset_split}" split. Please choose a valid split.')
44
  split = gr.Dropdown.update(choices=split, value=split[0])
45
 
@@ -53,6 +77,7 @@ with gr.Blocks(theme=theme) as iface:
53
  placeholder="cardiffnlp/twitter-roberta-base-sentiment-latest",
54
  )
55
 
 
56
  model_type = gr.Dropdown(
57
  label="Hugging Face model type",
58
  choices=[
@@ -87,10 +112,11 @@ with gr.Blocks(theme=theme) as iface:
87
  )
88
 
89
  with gr.Row():
90
- run_btn = gr.Button("Validate and submit", variant="primary")
91
  run_btn.click(
92
  try_submit,
93
  inputs=[
 
94
  dataset_id_input,
95
  dataset_config_input,
96
  dataset_split_input
 
1
  import gradio as gr
2
  import datasets
3
+ import huggingface_hub
4
 
5
 
6
  theme = gr.themes.Soft(
7
  primary_hue="green",
8
  )
9
 
10
+ def check_model(model_id):
11
+ try:
12
+ task = huggingface_hub.model_info(model_id).pipeline_tag
13
+ except Exception:
14
+ return None, None
15
+
16
+ try:
17
+ from transformers import pipeline
18
+ ppl = pipeline(task=task, model=model_id)
19
+
20
+ return model_id, ppl
21
+ except Exception as e:
22
+ return model_id, e
23
+
24
 
25
  def check_dataset(dataset_id, dataset_config="default", dataset_split="test"):
26
  try:
 
45
  return dataset_id, dataset_config, dataset_split
46
 
47
 
48
+ def try_submit(model_id, dataset_id, dataset_config, dataset_split):
49
+ # Validate model
50
+ m_id, ppl = check_model(model_id=model_id)
51
+ if m_id is None:
52
+ gr.Warning(f'Model "{model_id}" is not accessible. Please set your HF_TOKEN if it is a private model.')
53
+ return dataset_config, dataset_split
54
+ if isinstance(ppl, Exception):
55
+ gr.Warning(f'Failed to load "{model_id} model": {ppl}')
56
+ return dataset_config, dataset_split
57
+
58
  # Validate dataset
59
  d_id, config, split = check_dataset(dataset_id=dataset_id, dataset_config=dataset_config, dataset_split=dataset_split)
60
 
61
  if d_id is None:
62
  gr.Warning(f'Dataset "{dataset_id}" is not accessible. Please set your HF_TOKEN if it is a private dataset.')
63
+ elif isinstance(config, list):
64
  gr.Warning(f'Dataset "{dataset_id}" does have "{dataset_config}" config. Please choose a valid config.')
65
  config = gr.Dropdown.update(choices=config, value=config[0])
66
+ elif isinstance(split, list):
67
  gr.Warning(f'Dataset "{dataset_id}" does have "{dataset_split}" split. Please choose a valid split.')
68
  split = gr.Dropdown.update(choices=split, value=split[0])
69
 
 
77
  placeholder="cardiffnlp/twitter-roberta-base-sentiment-latest",
78
  )
79
 
80
+ # TODO: Add supported model pairs: Text Classification - text-classification
81
  model_type = gr.Dropdown(
82
  label="Hugging Face model type",
83
  choices=[
 
112
  )
113
 
114
  with gr.Row():
115
+ run_btn = gr.Button("Validate and submit evaluation task", variant="primary")
116
  run_btn.click(
117
  try_submit,
118
  inputs=[
119
+ model_id_input,
120
  dataset_id_input,
121
  dataset_config_input,
122
  dataset_split_input