File size: 860 Bytes
6f556e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from fastapi import FastAPI, HTTPException
from fastapi.responses import FileResponse
from fastapi.responses import JSONResponse
import os
import uvicorn

app = FastAPI()

# Directory where model files are stored
MODEL_DIRECTORY = "models"

@app.get("/health")
async def api_health_check():
    return JSONResponse(content={"status": "Service is running"})

@app.get("/download/{plant_name}")
async def download_model(plant_name: str):
    filename = f"{plant_name}_model.keras"
    file_path = os.path.join(MODEL_DIRECTORY, filename)

    # Check if file exists
    if not os.path.isfile(file_path):
        raise HTTPException(status_code=404, detail=f"Model file '{filename}' not found")

    return FileResponse(file_path, filename=filename, media_type="application/octet-stream")
if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=7860)