Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -23,14 +23,13 @@ repo: Optional[Repository] = None
|
|
23 |
# if HF_TOKEN:
|
24 |
# repo = Repository(local_dir=DATADIR, clone_from=DATASET_REPO_URL, token=HF_TOKEN)
|
25 |
|
26 |
-
|
27 |
def neuron_export(model_id: str, task: str) -> str:
|
28 |
if not model_id:
|
29 |
return f"### Invalid input π Please specify a model name, got {model_id}"
|
30 |
|
31 |
try:
|
32 |
-
api = HfApi(token=HF_TOKEN)
|
33 |
-
token = HF_TOKEN
|
34 |
|
35 |
error, commit_info = convert(api=api, model_id=model_id, task=task, token=token)
|
36 |
if error != "0":
|
@@ -61,6 +60,24 @@ def neuron_export(model_id: str, task: str) -> str:
|
|
61 |
except Exception as e:
|
62 |
return f"#### Error: {e}"
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
TITLE_IMAGE = """
|
66 |
<div style="display: block; margin-left: auto; margin-right: auto; width: 50%;">
|
@@ -78,17 +95,16 @@ TITLE = """
|
|
78 |
|
79 |
DESCRIPTION = """
|
80 |
Export π€ Transformers models hosted on the Hugging Face Hub to AWS Neuron-optimized format for Inferentia/Trainium acceleration.
|
81 |
-
|
82 |
*Features:*
|
83 |
- Automatically opens PR with Neuron-optimized model
|
84 |
- Preserves original model weights
|
85 |
- Adds proper tags to model card
|
86 |
-
|
87 |
*Note:*
|
88 |
- PR creation requires the Space owner to have a valid write token set via HF_WRITE_TOKEN
|
89 |
"""
|
90 |
|
91 |
with gr.Blocks() as demo:
|
|
|
92 |
gr.HTML(TITLE_IMAGE)
|
93 |
gr.HTML(TITLE)
|
94 |
|
@@ -101,6 +117,7 @@ with gr.Blocks() as demo:
|
|
101 |
label="Hub model ID",
|
102 |
placeholder="Search for model ID on the hub",
|
103 |
search_type="model",
|
|
|
104 |
)
|
105 |
input_task = gr.Textbox(
|
106 |
value="auto",
|
@@ -116,7 +133,6 @@ with gr.Blocks() as demo:
|
|
116 |
outputs=output,
|
117 |
)
|
118 |
|
119 |
-
|
120 |
if __name__ == "__main__":
|
121 |
def restart_space():
|
122 |
if HF_TOKEN:
|
|
|
23 |
# if HF_TOKEN:
|
24 |
# repo = Repository(local_dir=DATADIR, clone_from=DATASET_REPO_URL, token=HF_TOKEN)
|
25 |
|
|
|
26 |
def neuron_export(model_id: str, task: str) -> str:
|
27 |
if not model_id:
|
28 |
return f"### Invalid input π Please specify a model name, got {model_id}"
|
29 |
|
30 |
try:
|
31 |
+
api = HfApi(token=HF_TOKEN)
|
32 |
+
token = HF_TOKEN
|
33 |
|
34 |
error, commit_info = convert(api=api, model_id=model_id, task=task, token=token)
|
35 |
if error != "0":
|
|
|
60 |
except Exception as e:
|
61 |
return f"#### Error: {e}"
|
62 |
|
63 |
+
# --- Custom CSS for dark/light mode fix ---
|
64 |
+
CUSTOM_CSS = """
|
65 |
+
<style>
|
66 |
+
/* Default light mode style */
|
67 |
+
input.hub-search-input {
|
68 |
+
color: black !important;
|
69 |
+
background-color: white !important;
|
70 |
+
}
|
71 |
+
|
72 |
+
/* Dark mode overrides */
|
73 |
+
@media (prefers-color-scheme: dark) {
|
74 |
+
input.hub-search-input {
|
75 |
+
color: white !important;
|
76 |
+
background-color: #1f1f1f !important;
|
77 |
+
}
|
78 |
+
}
|
79 |
+
</style>
|
80 |
+
"""
|
81 |
|
82 |
TITLE_IMAGE = """
|
83 |
<div style="display: block; margin-left: auto; margin-right: auto; width: 50%;">
|
|
|
95 |
|
96 |
DESCRIPTION = """
|
97 |
Export π€ Transformers models hosted on the Hugging Face Hub to AWS Neuron-optimized format for Inferentia/Trainium acceleration.
|
|
|
98 |
*Features:*
|
99 |
- Automatically opens PR with Neuron-optimized model
|
100 |
- Preserves original model weights
|
101 |
- Adds proper tags to model card
|
|
|
102 |
*Note:*
|
103 |
- PR creation requires the Space owner to have a valid write token set via HF_WRITE_TOKEN
|
104 |
"""
|
105 |
|
106 |
with gr.Blocks() as demo:
|
107 |
+
gr.HTML(CUSTOM_CSS)
|
108 |
gr.HTML(TITLE_IMAGE)
|
109 |
gr.HTML(TITLE)
|
110 |
|
|
|
117 |
label="Hub model ID",
|
118 |
placeholder="Search for model ID on the hub",
|
119 |
search_type="model",
|
120 |
+
elem_classes=["hub-search-input"]
|
121 |
)
|
122 |
input_task = gr.Textbox(
|
123 |
value="auto",
|
|
|
133 |
outputs=output,
|
134 |
)
|
135 |
|
|
|
136 |
if __name__ == "__main__":
|
137 |
def restart_space():
|
138 |
if HF_TOKEN:
|