Spaces:
Sleeping
Sleeping
Megha Panicker commited on
Commit ·
405bea4
1
Parent(s): 2d8abbc
Use multi-port launch logic in app.py to avoid 7860 conflicts
Browse files
app.py
CHANGED
|
@@ -2,7 +2,41 @@
|
|
| 2 |
Entrypoint for Hugging Face Spaces. Gradio looks for app.py by default.
|
| 3 |
Set GROQ_API_KEY and NEON_DATABASE_URL in Space Settings → Repository secrets.
|
| 4 |
"""
|
|
|
|
|
|
|
| 5 |
from app_gradio import build_ui, THEME, CSS
|
| 6 |
|
| 7 |
demo = build_ui()
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
Entrypoint for Hugging Face Spaces. Gradio looks for app.py by default.
|
| 3 |
Set GROQ_API_KEY and NEON_DATABASE_URL in Space Settings → Repository secrets.
|
| 4 |
"""
|
| 5 |
+
import gradio as gr
|
| 6 |
+
|
| 7 |
from app_gradio import build_ui, THEME, CSS
|
| 8 |
|
| 9 |
demo = build_ui()
|
| 10 |
+
|
| 11 |
+
# For local runs you can still do: python app.py
|
| 12 |
+
if __name__ == "__main__":
|
| 13 |
+
# Gradio 3.x has no theme/css in launch(); Gradio 6 does. Try ports 7860-7870 if one is in use.
|
| 14 |
+
use_theme = hasattr(gr, "__version__") and not str(getattr(gr, "__version__", "")).startswith("3.")
|
| 15 |
+
last_err = None
|
| 16 |
+
for port in range(7860, 7871):
|
| 17 |
+
try:
|
| 18 |
+
if use_theme:
|
| 19 |
+
demo.launch(server_name="0.0.0.0", server_port=port, show_api=False, theme=THEME, css=CSS)
|
| 20 |
+
else:
|
| 21 |
+
demo.launch(server_name="0.0.0.0", server_port=port, show_api=False)
|
| 22 |
+
except TypeError:
|
| 23 |
+
# Older Gradio: retry without theme/css
|
| 24 |
+
use_theme = False
|
| 25 |
+
try:
|
| 26 |
+
demo.launch(server_name="0.0.0.0", server_port=port, show_api=False)
|
| 27 |
+
except OSError as e:
|
| 28 |
+
last_err = e
|
| 29 |
+
if "address already in use" in str(e).lower() or "48" in str(e) or "empty port" in str(e).lower():
|
| 30 |
+
continue
|
| 31 |
+
raise
|
| 32 |
+
except OSError as e:
|
| 33 |
+
last_err = e
|
| 34 |
+
if "address already in use" in str(e).lower() or "48" in str(e) or "empty port" in str(e).lower():
|
| 35 |
+
continue
|
| 36 |
+
raise
|
| 37 |
+
# If launch() returns without exception, break the loop
|
| 38 |
+
break
|
| 39 |
+
if last_err is not None:
|
| 40 |
+
raise OSError(
|
| 41 |
+
"Ports 7860-7870 are in use. Stop the other Gradio process or use a different port."
|
| 42 |
+
) from last_err
|