File size: 907 Bytes
16e1aa7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""
Entry point for Hugging Face Spaces running the **Gradio SDK** (free CPU
basic tier, no Docker needed).

Why this file exists instead of just `app.py`: the project already has a
package called `app/` (all the FastAPI/business logic lives there). Python
can't have a module `app.py` and a package `app/` in the same directory, so
this file is named `server.py` instead, and the Space is configured (via the
`app_file: server.py` line in README.md's metadata block) to run this file.

It imports the fully-wired FastAPI app (with the Gradio UI already mounted
onto it in app/main.py) and serves it with uvicorn on port 7860, which is
the port Hugging Face Spaces expects regardless of which SDK you pick.
"""
import os

import uvicorn

from app.main import app as fastapi_app

if __name__ == "__main__":
    port = int(os.environ.get("PORT", 7860))
    uvicorn.run(fastapi_app, host="0.0.0.0", port=port)