Spaces:
Sleeping
Sleeping
Muhammad Ahad Hassan Khan commited on
Commit ·
3c40c68
1
Parent(s): 5668a9c
image_base64 + ndvi band
Browse files
app.py
CHANGED
|
@@ -7,6 +7,7 @@ from io import BytesIO
|
|
| 7 |
import numpy as np
|
| 8 |
import io
|
| 9 |
import os
|
|
|
|
| 10 |
|
| 11 |
app = FastAPI()
|
| 12 |
model = load_model("ndvi_best_model.keras")
|
|
@@ -24,10 +25,10 @@ async def predict_ndvi_api(file: UploadFile = File(...)):
|
|
| 24 |
norm_img = normalize_rgb(np.array(img))
|
| 25 |
pred_ndvi = predict_ndvi(model, norm_img)
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
|
|
|
| 29 |
|
| 30 |
-
return
|
| 31 |
except Exception as e:
|
| 32 |
return JSONResponse(status_code=500, content={"error": str(e)})
|
| 33 |
-
|
|
|
|
| 7 |
import numpy as np
|
| 8 |
import io
|
| 9 |
import os
|
| 10 |
+
import base64
|
| 11 |
|
| 12 |
app = FastAPI()
|
| 13 |
model = load_model("ndvi_best_model.keras")
|
|
|
|
| 25 |
norm_img = normalize_rgb(np.array(img))
|
| 26 |
pred_ndvi = predict_ndvi(model, norm_img)
|
| 27 |
|
| 28 |
+
img_io = create_visualization(norm_img, pred_ndvi)
|
| 29 |
+
img_io.seek(0)
|
| 30 |
+
img_base64 = base64.b64encode(img_io.read()).decode("utf-8")
|
| 31 |
|
| 32 |
+
return JSONResponse(content={"image_base64": img_base64})
|
| 33 |
except Exception as e:
|
| 34 |
return JSONResponse(status_code=500, content={"error": str(e)})
|
|
|