pcuenq HF staff commited on
Commit
d217d18
·
1 Parent(s): a29c37c

Unconditionally add token, format tweaks.

Browse files
Files changed (1) hide show
  1. app.py +37 -31
app.py CHANGED
@@ -48,28 +48,31 @@ push_mapping = {
48
  }
49
  push_labels = list(push_mapping.keys())
50
 
51
- def error_str(error, title="Error", model=None, task=None, framework=None, compute_units=None, precision=None, tolerance=None, destination=None):
52
  if not error: return ""
53
 
54
- issue_title = urllib.parse.quote(f"Error converting {model}")
55
- issue_description = urllib.parse.quote(f"""Conversion Settings:
56
-
57
- Model: {model}
58
- Task: {task}
59
- Framework: {framework}
60
- Compute Units: {compute_units}
61
- Precision: {precision}
62
- Tolerance: {tolerance}
63
- Push to: {destination}
64
-
65
- Error: {error}
66
- """)
67
- issue_url = f"https://huggingface.co/spaces/pcuenq/transformers-to-coreml/discussions/new?title={issue_title}&description={issue_description}"
 
 
 
68
  return f"""
69
  #### {title}
70
  {error}
71
 
72
- It could be that the model is not yet compatible with the Core ML exporter. Please, open a discussion on the [Hugging Face Hub]({issue_url}) to report this issue.
73
  """
74
 
75
  def url_to_model_id(model_id_str):
@@ -194,7 +197,9 @@ def convert(model_id, task,
194
  push_destination = push_mapping[push_destination]
195
  if push_destination == "pr":
196
  destination_model = model_id
197
- token = None
 
 
198
 
199
  # TODO: support legacy format
200
  base = Path("exported")/model_id
@@ -284,6 +289,7 @@ with gr.Blocks() as demo:
284
  max_lines=1,
285
  label="Model name or URL, such as apple/mobilevit-small",
286
  placeholder="pcuenq/distilbert-base-uncased",
 
287
  )
288
  btn_get_tasks = gr.Button("Load")
289
  with gr.Column(scale=3):
@@ -313,26 +319,26 @@ with gr.Blocks() as demo:
313
  value=tolerance_labels[0],
314
  )
315
 
316
- radio_push = gr.Radio(
317
- label="Destination Model",
318
- choices=push_labels,
319
- value=push_labels[0],
320
- )
321
- with gr.Row(visible=False) as row_destination:
 
322
  # TODO: public/private
323
- text_destination = gr.Textbox(label="Destination model name", value="")
324
- text_token = gr.Textbox(label="Token (write permissions)", value="")
325
 
326
- btn_convert = gr.Button("Convert")
327
  gr.Markdown("Conversion will take a few minutes.")
328
 
329
 
330
  error_output = gr.Markdown(label="Output")
331
 
332
  # Clear output
333
- btn_get_tasks.click(lambda x: gr.update(value=''), [], [error_output])
334
- btn_convert.click(lambda x: gr.update(value=''), [], [error_output])
335
- input_model.submit(lambda x: gr.update(value=''), [],[error_output])
336
 
337
  input_model.submit(
338
  fn=on_model_change,
@@ -359,9 +365,9 @@ with gr.Blocks() as demo:
359
  radio_push.change(
360
  lambda x: gr.update(visible=x == "Create a new repo"),
361
  inputs=radio_push,
362
- outputs=row_destination,
363
  queue=False,
364
- scroll_to_output=True
365
  )
366
 
367
  gr.HTML("""
 
48
  }
49
  push_labels = list(push_mapping.keys())
50
 
51
+ def error_str(error, title="Error", model=None, task=None, framework=None, compute_units=None, precision=None, tolerance=None, destination=None, open_discussion=True):
52
  if not error: return ""
53
 
54
+ discussion_text = ""
55
+ if open_discussion:
56
+ issue_title = urllib.parse.quote(f"Error converting {model}")
57
+ issue_description = urllib.parse.quote(f"""Conversion Settings:
58
+
59
+ Model: {model}
60
+ Task: {task}
61
+ Framework: {framework}
62
+ Compute Units: {compute_units}
63
+ Precision: {precision}
64
+ Tolerance: {tolerance}
65
+ Push to: {destination}
66
+
67
+ Error: {error}
68
+ """)
69
+ issue_url = f"https://huggingface.co/spaces/pcuenq/transformers-to-coreml/discussions/new?title={issue_title}&description={issue_description}"
70
+ discussion_text = f"It could be that the model is not yet compatible with the Core ML exporter. Please, open a discussion on the [Hugging Face Hub]({issue_url}) to report this issue."
71
  return f"""
72
  #### {title}
73
  {error}
74
 
75
+ {discussion_text}
76
  """
77
 
78
  def url_to_model_id(model_id_str):
 
197
  push_destination = push_mapping[push_destination]
198
  if push_destination == "pr":
199
  destination_model = model_id
200
+
201
+ if token is None or token == "":
202
+ return error_str("Please provide a token to push to the Hub.", open_discussion=False)
203
 
204
  # TODO: support legacy format
205
  base = Path("exported")/model_id
 
289
  max_lines=1,
290
  label="Model name or URL, such as apple/mobilevit-small",
291
  placeholder="pcuenq/distilbert-base-uncased",
292
+ value="pcuenq/distilbert-base-uncased",
293
  )
294
  btn_get_tasks = gr.Button("Load")
295
  with gr.Column(scale=3):
 
319
  value=tolerance_labels[0],
320
  )
321
 
322
+ with gr.Group():
323
+ text_token = gr.Textbox(label="Hugging Face Token", placeholder="hf_xxxx", value="")
324
+ radio_push = gr.Radio(
325
+ label="Destination Model",
326
+ choices=push_labels,
327
+ value=push_labels[0],
328
+ )
329
  # TODO: public/private
330
+ text_destination = gr.Textbox(visible=False, label="Destination model name", value="")
 
331
 
332
+ btn_convert = gr.Button("Convert & Push")
333
  gr.Markdown("Conversion will take a few minutes.")
334
 
335
 
336
  error_output = gr.Markdown(label="Output")
337
 
338
  # Clear output
339
+ btn_get_tasks.click(lambda _: gr.update(value=''), None, error_output)
340
+ input_model.submit(lambda _: gr.update(value=''), None, error_output)
341
+ btn_convert.click(lambda _: gr.update(value=''), None, error_output)
342
 
343
  input_model.submit(
344
  fn=on_model_change,
 
365
  radio_push.change(
366
  lambda x: gr.update(visible=x == "Create a new repo"),
367
  inputs=radio_push,
368
+ outputs=text_destination,
369
  queue=False,
370
+ scroll_to_output=False
371
  )
372
 
373
  gr.HTML("""