Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -39,6 +39,33 @@ class PredictionOutput(BaseModel):
|
|
39 |
t3: List[float]
|
40 |
prediction: List[float]
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
@app.post("/predict/", response_model=PredictionOutput)
|
43 |
async def predict(file: UploadFile = File(...)):
|
44 |
# Read the uploaded file
|
|
|
39 |
t3: List[float]
|
40 |
prediction: List[float]
|
41 |
|
42 |
+
# Define the inference function
|
43 |
+
def inference_on_file(file_path, model, custom_test_pipeline):
|
44 |
+
with rasterio.open(file_path) as src:
|
45 |
+
img = src.read()
|
46 |
+
|
47 |
+
# Apply preprocessing using the custom pipeline
|
48 |
+
processed_img = apply_pipeline(custom_test_pipeline, img)
|
49 |
+
|
50 |
+
# Run inference
|
51 |
+
output = model.inference(processed_img)
|
52 |
+
|
53 |
+
# Post-process the output to get the RGB and prediction images
|
54 |
+
rgb1 = postprocess_output(output[0])
|
55 |
+
rgb2 = postprocess_output(output[1])
|
56 |
+
rgb3 = postprocess_output(output[2])
|
57 |
+
|
58 |
+
return rgb1, rgb2, rgb3, output
|
59 |
+
|
60 |
+
def apply_pipeline(pipeline, img):
|
61 |
+
# Implement your custom pipeline processing here
|
62 |
+
# This could include normalization, resizing, etc.
|
63 |
+
return img
|
64 |
+
|
65 |
+
def postprocess_output(output):
|
66 |
+
# Convert the model's output into an RGB image or other formats as needed
|
67 |
+
return output
|
68 |
+
|
69 |
@app.post("/predict/", response_model=PredictionOutput)
|
70 |
async def predict(file: UploadFile = File(...)):
|
71 |
# Read the uploaded file
|