Spaces:
Sleeping
Sleeping
Create app/app.py
Browse files- app/app.py +19 -0
app/app.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, File, UploadFile
|
| 2 |
+
from fastapi.responses import JSONResponse
|
| 3 |
+
from app.model import analyze_image
|
| 4 |
+
from app.utils import load_image
|
| 5 |
+
import uvicorn
|
| 6 |
+
|
| 7 |
+
app = FastAPI(title="Image Analyzer", version="1.0.0")
|
| 8 |
+
|
| 9 |
+
@app.post("/analyze")
|
| 10 |
+
async def analyze(file: UploadFile = File(...)):
|
| 11 |
+
try:
|
| 12 |
+
image = await load_image(file)
|
| 13 |
+
results = analyze_image(image)
|
| 14 |
+
return JSONResponse(content={"results": results})
|
| 15 |
+
except Exception as e:
|
| 16 |
+
return JSONResponse(status_code=500, content={"error": str(e)})
|
| 17 |
+
|
| 18 |
+
if __name__ == "__main__":
|
| 19 |
+
uvicorn.run("app.app:app", host="0.0.0.0", port=7860)
|