Spaces:
Sleeping
Sleeping
Ric
commited on
Commit
·
b6f148b
1
Parent(s):
e17245d
Adjust Gradio launch for Spaces
Browse files
app.py
CHANGED
|
@@ -13,7 +13,9 @@ FEATURE_NAMES = [
|
|
| 13 |
|
| 14 |
CACHE_ROOT = Path(__file__).with_name(".cache")
|
| 15 |
CACHE_ROOT.mkdir(exist_ok=True)
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
os.environ.setdefault("XDG_CACHE_HOME", str(CACHE_ROOT))
|
| 18 |
|
| 19 |
import gradio as gr
|
|
@@ -274,23 +276,33 @@ with gr.Blocks(title="UNLV Study Location Predictor") as demo:
|
|
| 274 |
|
| 275 |
|
| 276 |
if __name__ == "__main__":
|
| 277 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
try:
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
|
|
|
| 285 |
)
|
| 286 |
-
|
| 287 |
-
fallback_port = int(os.environ.get("GRADIO_FALLBACK_PORT", default_port + 1111))
|
| 288 |
-
if fallback_port == default_port:
|
| 289 |
raise
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
server_port=fallback_port,
|
| 293 |
-
prevent_thread_lock=True,
|
| 294 |
-
show_error=True,
|
| 295 |
-
share=False,
|
| 296 |
-
)
|
|
|
|
| 13 |
|
| 14 |
CACHE_ROOT = Path(__file__).with_name(".cache")
|
| 15 |
CACHE_ROOT.mkdir(exist_ok=True)
|
| 16 |
+
matplotlib_cache = CACHE_ROOT / "matplotlib"
|
| 17 |
+
matplotlib_cache.mkdir(parents=True, exist_ok=True)
|
| 18 |
+
os.environ.setdefault("MPLCONFIGDIR", str(matplotlib_cache))
|
| 19 |
os.environ.setdefault("XDG_CACHE_HOME", str(CACHE_ROOT))
|
| 20 |
|
| 21 |
import gradio as gr
|
|
|
|
| 276 |
|
| 277 |
|
| 278 |
if __name__ == "__main__":
|
| 279 |
+
queued_app = demo.queue()
|
| 280 |
+
is_hf_space = bool(os.environ.get("SPACE_ID"))
|
| 281 |
+
default_port = int(
|
| 282 |
+
os.environ.get(
|
| 283 |
+
"PORT",
|
| 284 |
+
os.environ.get("GRADIO_SERVER_PORT", "7860"),
|
| 285 |
+
)
|
| 286 |
+
)
|
| 287 |
+
launch_kwargs = {
|
| 288 |
+
"server_name": os.environ.get("GRADIO_SERVER_NAME", "0.0.0.0"),
|
| 289 |
+
"server_port": default_port,
|
| 290 |
+
"show_error": True,
|
| 291 |
+
"share": os.environ.get("GRADIO_SHARE", "").lower() == "true",
|
| 292 |
+
}
|
| 293 |
+
if not is_hf_space:
|
| 294 |
+
launch_kwargs["prevent_thread_lock"] = True
|
| 295 |
+
|
| 296 |
try:
|
| 297 |
+
queued_app.launch(**launch_kwargs)
|
| 298 |
+
except OSError:
|
| 299 |
+
fallback_port = int(
|
| 300 |
+
os.environ.get(
|
| 301 |
+
"GRADIO_FALLBACK_PORT",
|
| 302 |
+
str(default_port + 1111),
|
| 303 |
+
)
|
| 304 |
)
|
| 305 |
+
if fallback_port == launch_kwargs["server_port"]:
|
|
|
|
|
|
|
| 306 |
raise
|
| 307 |
+
launch_kwargs["server_port"] = fallback_port
|
| 308 |
+
queued_app.launch(**launch_kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|