Spaces:
Running on Zero
Running on Zero
Commit ·
4176fc6
1
Parent(s): 6986444
Switch off Gradio's SSR front end so the API paths reach the server
Browse files
app.py
CHANGED
|
@@ -29,6 +29,8 @@ os.environ.setdefault("AFRICA_TTS_DEVICE", "cpu")
|
|
| 29 |
# One request is spoken at a time; the rest queue.
|
| 30 |
os.environ.setdefault("AFRICA_TTS_WORKERS", "1")
|
| 31 |
os.environ.setdefault("AFRICA_TTS_MAX_CHARS", "1000")
|
|
|
|
|
|
|
| 32 |
|
| 33 |
import asyncio # noqa: E402
|
| 34 |
|
|
@@ -58,7 +60,8 @@ with gr.Blocks(title="Africa TTS API") as page:
|
|
| 58 |
|
| 59 |
if __name__ == "__main__":
|
| 60 |
# Gradio picks the host and port the Space expects.
|
| 61 |
-
server, _, _ = page.launch(server_name="0.0.0.0", prevent_thread_lock=True)
|
| 62 |
# First in line, so none of Gradio's own routes can answer for the API.
|
| 63 |
server.router.routes.insert(0, Mount(API_PATH, app=api))
|
|
|
|
| 64 |
page.block_thread()
|
|
|
|
| 29 |
# One request is spoken at a time; the rest queue.
|
| 30 |
os.environ.setdefault("AFRICA_TTS_WORKERS", "1")
|
| 31 |
os.environ.setdefault("AFRICA_TTS_MAX_CHARS", "1000")
|
| 32 |
+
# Gradio's Node front end (SSR) answers unknown paths with the web page, hiding the API.
|
| 33 |
+
os.environ["GRADIO_SSR_MODE"] = "false"
|
| 34 |
|
| 35 |
import asyncio # noqa: E402
|
| 36 |
|
|
|
|
| 60 |
|
| 61 |
if __name__ == "__main__":
|
| 62 |
# Gradio picks the host and port the Space expects.
|
| 63 |
+
server, _, _ = page.launch(server_name="0.0.0.0", prevent_thread_lock=True, ssr_mode=False)
|
| 64 |
# First in line, so none of Gradio's own routes can answer for the API.
|
| 65 |
server.router.routes.insert(0, Mount(API_PATH, app=api))
|
| 66 |
+
print(f"Africa TTS API attached at {API_PATH}", flush=True)
|
| 67 |
page.block_thread()
|