Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,6 @@ from torchvision.utils import make_grid
|
|
| 5 |
import gradio as gr
|
| 6 |
from fastapi import FastAPI
|
| 7 |
from fastapi.responses import JSONResponse
|
| 8 |
-
import uvicorn
|
| 9 |
|
| 10 |
# ------------------------
|
| 11 |
# CONFIG
|
|
@@ -43,10 +42,8 @@ class Generator(nn.Module):
|
|
| 43 |
def load_generator():
|
| 44 |
if not os.path.exists(GENERATOR_PATH):
|
| 45 |
raise FileNotFoundError(
|
| 46 |
-
f"Checkpoint not found: {GENERATOR_PATH}. "
|
| 47 |
-
"Make sure it exists in your Hugging Face Space."
|
| 48 |
)
|
| 49 |
-
|
| 50 |
model = Generator().to(DEVICE)
|
| 51 |
state_dict = torch.load(GENERATOR_PATH, map_location=DEVICE)
|
| 52 |
model.load_state_dict(state_dict)
|
|
@@ -124,6 +121,7 @@ app = FastAPI()
|
|
| 124 |
|
| 125 |
@app.get("/cron")
|
| 126 |
def cron():
|
|
|
|
| 127 |
return JSONResponse({
|
| 128 |
"ok": True,
|
| 129 |
"message": "KYO cron endpoint is live"
|
|
@@ -131,14 +129,14 @@ def cron():
|
|
| 131 |
|
| 132 |
@app.get("/health")
|
| 133 |
def health():
|
|
|
|
| 134 |
return JSONResponse({
|
| 135 |
"status": "healthy",
|
| 136 |
"device": DEVICE,
|
| 137 |
"model_loaded": G is not None
|
| 138 |
})
|
| 139 |
|
|
|
|
| 140 |
app = gr.mount_gradio_app(app, demo, path="/")
|
| 141 |
|
| 142 |
-
|
| 143 |
-
# Launch Gradio normally; HF Space handles ports
|
| 144 |
-
demo.launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860)))
|
|
|
|
| 5 |
import gradio as gr
|
| 6 |
from fastapi import FastAPI
|
| 7 |
from fastapi.responses import JSONResponse
|
|
|
|
| 8 |
|
| 9 |
# ------------------------
|
| 10 |
# CONFIG
|
|
|
|
| 42 |
def load_generator():
|
| 43 |
if not os.path.exists(GENERATOR_PATH):
|
| 44 |
raise FileNotFoundError(
|
| 45 |
+
f"Checkpoint not found: {GENERATOR_PATH}. Make sure it exists in your Hugging Face Space."
|
|
|
|
| 46 |
)
|
|
|
|
| 47 |
model = Generator().to(DEVICE)
|
| 48 |
state_dict = torch.load(GENERATOR_PATH, map_location=DEVICE)
|
| 49 |
model.load_state_dict(state_dict)
|
|
|
|
| 121 |
|
| 122 |
@app.get("/cron")
|
| 123 |
def cron():
|
| 124 |
+
"""Cron endpoint – just returns a message for now."""
|
| 125 |
return JSONResponse({
|
| 126 |
"ok": True,
|
| 127 |
"message": "KYO cron endpoint is live"
|
|
|
|
| 129 |
|
| 130 |
@app.get("/health")
|
| 131 |
def health():
|
| 132 |
+
"""Health check endpoint."""
|
| 133 |
return JSONResponse({
|
| 134 |
"status": "healthy",
|
| 135 |
"device": DEVICE,
|
| 136 |
"model_loaded": G is not None
|
| 137 |
})
|
| 138 |
|
| 139 |
+
# Mount Gradio app on FastAPI
|
| 140 |
app = gr.mount_gradio_app(app, demo, path="/")
|
| 141 |
|
| 142 |
+
# No uvicorn.run() needed; HF Spaces handles the server and port
|
|
|
|
|
|