Spaces:
Running
Running
Create main.py
Browse files
main.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException
|
| 2 |
+
from fastapi.responses import FileResponse
|
| 3 |
+
from fastapi.responses import JSONResponse
|
| 4 |
+
import os
|
| 5 |
+
import uvicorn
|
| 6 |
+
|
| 7 |
+
app = FastAPI()
|
| 8 |
+
|
| 9 |
+
# Directory where model files are stored
|
| 10 |
+
MODEL_DIRECTORY = "models"
|
| 11 |
+
|
| 12 |
+
@app.get("/health")
|
| 13 |
+
async def api_health_check():
|
| 14 |
+
return JSONResponse(content={"status": "Service is running"})
|
| 15 |
+
|
| 16 |
+
@app.get("/download/{plant_name}")
|
| 17 |
+
async def download_model(plant_name: str):
|
| 18 |
+
filename = f"{plant_name}_model.keras"
|
| 19 |
+
file_path = os.path.join(MODEL_DIRECTORY, filename)
|
| 20 |
+
|
| 21 |
+
# Check if file exists
|
| 22 |
+
if not os.path.isfile(file_path):
|
| 23 |
+
raise HTTPException(status_code=404, detail=f"Model file '{filename}' not found")
|
| 24 |
+
|
| 25 |
+
return FileResponse(file_path, filename=filename, media_type="application/octet-stream")
|
| 26 |
+
if __name__ == "__main__":
|
| 27 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|