NimaBoscarino commited on
Commit
349e976
β€’
1 Parent(s): ac5d892

Auto-run checks on card loading

Browse files
Files changed (1) hide show
  1. app.py +14 -7
app.py CHANGED
@@ -21,6 +21,11 @@ def status_emoji(status: bool):
21
  return "βœ…" if status else "πŸ›‘"
22
 
23
 
 
 
 
 
 
24
  def run_compliance_check(model_card: str):
25
  results = suite.run(model_card)
26
 
@@ -42,9 +47,10 @@ def compliance_result(compliance_check: ComplianceCheck):
42
  return accordion, description
43
 
44
 
45
- def read_file(file_obj):
46
  with open(file_obj.name) as f:
47
- return f.read()
 
48
 
49
 
50
  model_card_box = gr.TextArea(label="Model Card")
@@ -81,7 +87,7 @@ code {
81
  "Upload a Markdown file".
82
  - Paste your model card's text directly into the "Model Card" text area.
83
 
84
- Once your card is loaded, click "Run validation checks" to receive your results.
85
  """)
86
 
87
  with gr.Row():
@@ -105,10 +111,11 @@ code {
105
 
106
  with gr.Tab(label="Upload your own card"):
107
  file = gr.UploadButton(label="Upload a Markdown file", elem_id="file-upload")
 
108
  file.upload(
109
- fn=read_file,
110
  inputs=[file],
111
- outputs=[model_card_box]
112
  )
113
 
114
  model_card_box.render()
@@ -122,9 +129,9 @@ code {
122
  d.render()
123
 
124
  submit_model_search.click(
125
- fn=lambda x: ModelCard.load(repo_id_or_path=x).content,
126
  inputs=[model_id_search],
127
- outputs=[model_card_box]
128
  )
129
 
130
  submit_markdown.click(
 
21
  return "βœ…" if status else "πŸ›‘"
22
 
23
 
24
+ def load_model_card_and_run_check(model_id):
25
+ card = ModelCard.load(repo_id_or_path=model_id).content
26
+ return card, *run_compliance_check(card)
27
+
28
+
29
  def run_compliance_check(model_card: str):
30
  results = suite.run(model_card)
31
 
 
47
  return accordion, description
48
 
49
 
50
+ def read_file_and_run_checks(file_obj):
51
  with open(file_obj.name) as f:
52
+ model_card = f.read()
53
+ return model_card, *run_compliance_check(model_card=model_card)
54
 
55
 
56
  model_card_box = gr.TextArea(label="Model Card")
 
87
  "Upload a Markdown file".
88
  - Paste your model card's text directly into the "Model Card" text area.
89
 
90
+ Once your card is loaded, the checks will run automatically. Edit the text content and click "Run validation checks" to receive new results.
91
  """)
92
 
93
  with gr.Row():
 
111
 
112
  with gr.Tab(label="Upload your own card"):
113
  file = gr.UploadButton(label="Upload a Markdown file", elem_id="file-upload")
114
+ # TODO: Bug – uploading more than once doesn't trigger the function? Gradio bug?
115
  file.upload(
116
+ fn=read_file_and_run_checks,
117
  inputs=[file],
118
+ outputs=[model_card_box, *compliance_accordions, *compliance_descriptions]
119
  )
120
 
121
  model_card_box.render()
 
129
  d.render()
130
 
131
  submit_model_search.click(
132
+ fn=load_model_card_and_run_check,
133
  inputs=[model_id_search],
134
+ outputs=[model_card_box, *compliance_accordions, *compliance_descriptions]
135
  )
136
 
137
  submit_markdown.click(