Benjamin Bossan commited on
Commit
6e9ab9b
1 Parent(s): f1e583c

Improve messages when inputs are missing

Browse files
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -123,10 +123,6 @@ def _parse_metrics(metrics):
123
 
124
 
125
  def _create_model_card():
126
- if model is None or data is None:
127
- st.text("*some data is missing to render the model card*")
128
- return
129
-
130
  init_repo()
131
  metadata = card.metadata_from_config(hf_repo)
132
  model_card = card.Card(model=model, metadata=metadata)
@@ -217,8 +213,7 @@ def _process_card_for_rendering(rendered: str) -> tuple[str, str]:
217
  return metadata, rendered_with_img
218
 
219
 
220
- def display_model_card():
221
- model_card = _create_model_card()
222
  if not model_card:
223
  return
224
 
@@ -235,8 +230,7 @@ def display_model_card():
235
  st.markdown(rendered, unsafe_allow_html=True)
236
 
237
 
238
- def download_model_card():
239
- model_card = _create_model_card()
240
  if model_card is not None:
241
  return model_card.render()
242
  return ""
@@ -380,9 +374,17 @@ with left_col:
380
 
381
 
382
  with right_col:
 
 
 
 
 
 
 
 
383
  # this contains the rendered model card
384
- rendered = download_model_card()
385
  if rendered:
386
  st.download_button(label="Download model card (markdown format)", data=rendered)
387
 
388
- display_model_card()
 
123
 
124
 
125
  def _create_model_card():
 
 
 
 
126
  init_repo()
127
  metadata = card.metadata_from_config(hf_repo)
128
  model_card = card.Card(model=model, metadata=metadata)
 
213
  return metadata, rendered_with_img
214
 
215
 
216
+ def display_model_card(model_card):
 
217
  if not model_card:
218
  return
219
 
 
230
  st.markdown(rendered, unsafe_allow_html=True)
231
 
232
 
233
+ def download_model_card(model_card):
 
234
  if model_card is not None:
235
  return model_card.render()
236
  return ""
 
374
 
375
 
376
  with right_col:
377
+ model_card = None
378
+ if model is None:
379
+ st.text("*add a model to render the model card*")
380
+ if data is None:
381
+ st.text("*add data to render the model card")
382
+ if (model is not None) and (data is not None):
383
+ model_card = _create_model_card()
384
+
385
  # this contains the rendered model card
386
+ rendered = download_model_card(model_card)
387
  if rendered:
388
  st.download_button(label="Download model card (markdown format)", data=rendered)
389
 
390
+ display_model_card(model_card)