Spaces:
Sleeping
Sleeping
Commit ·
edea085
1
Parent(s): 2b6502c
fix(app): resolve model cache bug and Gradio 6 launch warnings
Browse filesDeclare global _loaded_large in get_model to fix UnboundLocalError when
loading models from examples. Move theme and css to launch() for Gradio 6.
app.py
CHANGED
|
@@ -103,6 +103,7 @@ def _unload_large_model() -> None:
|
|
| 103 |
|
| 104 |
def get_model(name: str) -> Pipeline:
|
| 105 |
"""Load models on demand. Small models stay cached; only one large model in memory."""
|
|
|
|
| 106 |
if name not in MODELS:
|
| 107 |
raise ValueError(f"Unknown model: {name}")
|
| 108 |
|
|
@@ -200,9 +201,7 @@ APP_CSS = """
|
|
| 200 |
|
| 201 |
def build_demo() -> gr.Blocks:
|
| 202 |
with gr.Blocks(
|
| 203 |
-
theme=gr.themes.Soft(),
|
| 204 |
title="Sustainable Development Goals (SDG) Text Classifier App",
|
| 205 |
-
css=APP_CSS,
|
| 206 |
elem_id="sdg-app-container",
|
| 207 |
) as demo:
|
| 208 |
gr.Markdown(
|
|
@@ -328,6 +327,18 @@ def build_demo() -> gr.Blocks:
|
|
| 328 |
demo = build_demo()
|
| 329 |
demo.queue(default_concurrency_limit=1)
|
| 330 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 331 |
if __name__ == "__main__":
|
| 332 |
logger.info("Gradio version: %s", gr.__version__)
|
| 333 |
demo.launch()
|
|
|
|
| 103 |
|
| 104 |
def get_model(name: str) -> Pipeline:
|
| 105 |
"""Load models on demand. Small models stay cached; only one large model in memory."""
|
| 106 |
+
global _loaded_large
|
| 107 |
if name not in MODELS:
|
| 108 |
raise ValueError(f"Unknown model: {name}")
|
| 109 |
|
|
|
|
| 201 |
|
| 202 |
def build_demo() -> gr.Blocks:
|
| 203 |
with gr.Blocks(
|
|
|
|
| 204 |
title="Sustainable Development Goals (SDG) Text Classifier App",
|
|
|
|
| 205 |
elem_id="sdg-app-container",
|
| 206 |
) as demo:
|
| 207 |
gr.Markdown(
|
|
|
|
| 327 |
demo = build_demo()
|
| 328 |
demo.queue(default_concurrency_limit=1)
|
| 329 |
|
| 330 |
+
_APP_THEME = gr.themes.Soft()
|
| 331 |
+
_ORIGINAL_LAUNCH = demo.launch
|
| 332 |
+
|
| 333 |
+
|
| 334 |
+
def launch(**kwargs):
|
| 335 |
+
kwargs.setdefault("theme", _APP_THEME)
|
| 336 |
+
kwargs.setdefault("css", APP_CSS)
|
| 337 |
+
return _ORIGINAL_LAUNCH(**kwargs)
|
| 338 |
+
|
| 339 |
+
|
| 340 |
+
demo.launch = launch
|
| 341 |
+
|
| 342 |
if __name__ == "__main__":
|
| 343 |
logger.info("Gradio version: %s", gr.__version__)
|
| 344 |
demo.launch()
|