Spaces:
Running
Running
feat: add progress indicator while compiling is running (#2)
Browse files- feat: add progress indicator while compiling is running (123e2d3d8d39202b366455f848e32424604d6394)
Co-authored-by: Alvaro Moran <tengomucho@users.noreply.huggingface.co>
app.py
CHANGED
|
@@ -147,13 +147,13 @@ def neuron_export(model_id: str, model_type: str, pipeline_name: str, task_or_pi
|
|
| 147 |
pr_destinations: List[str], custom_repo_id: str, custom_cache_repo: str, oauth_token: gr.OAuthToken):
|
| 148 |
|
| 149 |
log_buffer = ""
|
| 150 |
-
def log(msg):
|
| 151 |
nonlocal log_buffer
|
| 152 |
# Handle cases where the message from the backend is not a string
|
| 153 |
if not isinstance(msg, str):
|
| 154 |
msg = str(msg)
|
| 155 |
log_buffer += msg + "\n"
|
| 156 |
-
return log_buffer
|
| 157 |
|
| 158 |
if oauth_token.token is None:
|
| 159 |
yield log("You must be logged in to use this space")
|
|
@@ -169,14 +169,14 @@ def neuron_export(model_id: str, model_type: str, pipeline_name: str, task_or_pi
|
|
| 169 |
if custom_cache_repo:
|
| 170 |
os.environ['CUSTOM_CACHE_REPO'] = custom_cache_repo.strip()
|
| 171 |
|
| 172 |
-
yield log(
|
| 173 |
try:
|
| 174 |
api.model_info(model_id, token=oauth_token.token)
|
| 175 |
except Exception as e:
|
| 176 |
yield log(f"❌ Could not access model `{model_id}`: {e}")
|
| 177 |
return
|
| 178 |
|
| 179 |
-
yield log(f"✅ Model `{model_id}` is accessible. Starting Neuron export...")
|
| 180 |
|
| 181 |
# UPDATED: Build pr_options with new structure
|
| 182 |
pr_options = {
|
|
@@ -193,7 +193,7 @@ def neuron_export(model_id: str, model_type: str, pipeline_name: str, task_or_pi
|
|
| 193 |
pipeline_name=pipeline_name if model_type == "diffusers (soon)" else None
|
| 194 |
):
|
| 195 |
if isinstance(message, str):
|
| 196 |
-
yield log(message)
|
| 197 |
else: # It's the final result dictionary
|
| 198 |
final_message = "🎉 Process finished.\n"
|
| 199 |
if message.get("neuron_repo"):
|
|
@@ -284,9 +284,31 @@ button.gradio-button.lg.primary {
|
|
| 284 |
#login-button:hover::after {
|
| 285 |
left: 100%;
|
| 286 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
|
| 288 |
"""
|
| 289 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
with gr.Blocks(css=CUSTOM_CSS, theme=gr.themes.Soft()) as demo:
|
| 291 |
gr.Markdown("**You must be logged in to use this space**")
|
| 292 |
gr.LoginButton(elem_id="login-button", elem_classes="center-button", min_width=250)
|
|
@@ -343,6 +365,8 @@ with gr.Blocks(css=CUSTOM_CSS, theme=gr.themes.Soft()) as demo:
|
|
| 343 |
)
|
| 344 |
|
| 345 |
btn = gr.Button("Export to Neuron", size="lg", variant="primary")
|
|
|
|
|
|
|
| 346 |
|
| 347 |
log_box = gr.Textbox(label="Logs", lines=20, interactive=False, show_copy_button=True)
|
| 348 |
|
|
@@ -376,7 +400,7 @@ with gr.Blocks(css=CUSTOM_CSS, theme=gr.themes.Soft()) as demo:
|
|
| 376 |
custom_repo_id_textbox,
|
| 377 |
custom_cache_repo_textbox
|
| 378 |
],
|
| 379 |
-
outputs=log_box,
|
| 380 |
)
|
| 381 |
|
| 382 |
with gr.Tab("Get Started"):
|
|
|
|
| 147 |
pr_destinations: List[str], custom_repo_id: str, custom_cache_repo: str, oauth_token: gr.OAuthToken):
|
| 148 |
|
| 149 |
log_buffer = ""
|
| 150 |
+
def log(msg, in_progress: bool = False):
|
| 151 |
nonlocal log_buffer
|
| 152 |
# Handle cases where the message from the backend is not a string
|
| 153 |
if not isinstance(msg, str):
|
| 154 |
msg = str(msg)
|
| 155 |
log_buffer += msg + "\n"
|
| 156 |
+
return log_buffer, gr.update(visible=in_progress)
|
| 157 |
|
| 158 |
if oauth_token.token is None:
|
| 159 |
yield log("You must be logged in to use this space")
|
|
|
|
| 169 |
if custom_cache_repo:
|
| 170 |
os.environ['CUSTOM_CACHE_REPO'] = custom_cache_repo.strip()
|
| 171 |
|
| 172 |
+
yield log("🔑 Logging in ...", in_progress=True)
|
| 173 |
try:
|
| 174 |
api.model_info(model_id, token=oauth_token.token)
|
| 175 |
except Exception as e:
|
| 176 |
yield log(f"❌ Could not access model `{model_id}`: {e}")
|
| 177 |
return
|
| 178 |
|
| 179 |
+
yield log(f"✅ Model `{model_id}` is accessible. Starting Neuron export...", in_progress=True)
|
| 180 |
|
| 181 |
# UPDATED: Build pr_options with new structure
|
| 182 |
pr_options = {
|
|
|
|
| 193 |
pipeline_name=pipeline_name if model_type == "diffusers (soon)" else None
|
| 194 |
):
|
| 195 |
if isinstance(message, str):
|
| 196 |
+
yield log(message, in_progress=True)
|
| 197 |
else: # It's the final result dictionary
|
| 198 |
final_message = "🎉 Process finished.\n"
|
| 199 |
if message.get("neuron_repo"):
|
|
|
|
| 284 |
#login-button:hover::after {
|
| 285 |
left: 100%;
|
| 286 |
}
|
| 287 |
+
.loader {
|
| 288 |
+
width: 20px;
|
| 289 |
+
height: 20px;
|
| 290 |
+
border: 5px solid #d7d7d7;
|
| 291 |
+
border-bottom-color: transparent;
|
| 292 |
+
border-radius: 50%;
|
| 293 |
+
display: inline-block;
|
| 294 |
+
box-sizing: border-box;
|
| 295 |
+
animation: rotation 1s linear infinite;
|
| 296 |
+
}
|
| 297 |
+
@keyframes rotation {
|
| 298 |
+
0% {
|
| 299 |
+
transform: rotate(0deg);
|
| 300 |
+
}
|
| 301 |
+
100% {
|
| 302 |
+
transform: rotate(360deg);
|
| 303 |
+
}
|
| 304 |
+
}
|
| 305 |
|
| 306 |
"""
|
| 307 |
|
| 308 |
+
LOADING_MESSAGE = """
|
| 309 |
+
<div id="in_progress"><span class="loader"> </span> Model export in progress...</div>
|
| 310 |
+
"""
|
| 311 |
+
|
| 312 |
with gr.Blocks(css=CUSTOM_CSS, theme=gr.themes.Soft()) as demo:
|
| 313 |
gr.Markdown("**You must be logged in to use this space**")
|
| 314 |
gr.LoginButton(elem_id="login-button", elem_classes="center-button", min_width=250)
|
|
|
|
| 365 |
)
|
| 366 |
|
| 367 |
btn = gr.Button("Export to Neuron", size="lg", variant="primary")
|
| 368 |
+
|
| 369 |
+
loading_message = gr.HTML(LOADING_MESSAGE, visible=False, elem_id="loaging_message")
|
| 370 |
|
| 371 |
log_box = gr.Textbox(label="Logs", lines=20, interactive=False, show_copy_button=True)
|
| 372 |
|
|
|
|
| 400 |
custom_repo_id_textbox,
|
| 401 |
custom_cache_repo_textbox
|
| 402 |
],
|
| 403 |
+
outputs=[log_box, loading_message],
|
| 404 |
)
|
| 405 |
|
| 406 |
with gr.Tab("Get Started"):
|