Unconditionally add token, format tweaks.
Browse files
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 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
| 68 |
return f"""
|
| 69 |
#### {title}
|
| 70 |
{error}
|
| 71 |
|
| 72 |
-
|
| 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 |
-
|
|
|
|
|
|
|
| 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 |
-
|
| 317 |
-
label="
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
|
|
|
| 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
|
| 334 |
-
|
| 335 |
-
|
| 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=
|
| 363 |
queue=False,
|
| 364 |
-
scroll_to_output=
|
| 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("""
|