Spaces:
Sleeping
Sleeping
Muhammad Ahad Hassan Khan commited on
Commit ·
19b89fd
1
Parent(s): 3c40c68
corrected last commit
Browse files
app.py
CHANGED
|
@@ -25,10 +25,20 @@ async def predict_ndvi_api(file: UploadFile = File(...)):
|
|
| 25 |
norm_img = normalize_rgb(np.array(img))
|
| 26 |
pred_ndvi = predict_ndvi(model, norm_img)
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
| 31 |
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
return JSONResponse(status_code=500, content={"error": str(e)})
|
|
|
|
|
|
| 25 |
norm_img = normalize_rgb(np.array(img))
|
| 26 |
pred_ndvi = predict_ndvi(model, norm_img)
|
| 27 |
|
| 28 |
+
# Prepare visualization image
|
| 29 |
+
vis_img_io = create_visualization(norm_img, pred_ndvi)
|
| 30 |
+
vis_img_io.seek(0)
|
| 31 |
+
vis_img_base64 = base64.b64encode(vis_img_io.read()).decode("utf-8")
|
| 32 |
|
| 33 |
+
# Convert NDVI array to nested list (e.g., for JSON)
|
| 34 |
+
ndvi_list = pred_ndvi.tolist()
|
| 35 |
+
|
| 36 |
+
return JSONResponse(
|
| 37 |
+
content={
|
| 38 |
+
"ndvi_array": ndvi_list,
|
| 39 |
+
"visualization": vis_img_base64
|
| 40 |
+
}
|
| 41 |
+
)
|
| 42 |
except Exception as e:
|
| 43 |
return JSONResponse(status_code=500, content={"error": str(e)})
|
| 44 |
+
|