Spaces:
Runtime error
Runtime error
xcurvnubaim
commited on
Commit
·
d9a9d0e
1
Parent(s):
473bf51
fix: fix image not found
Browse files
main.py
CHANGED
@@ -118,19 +118,22 @@ def plot_detected_rectangles(image, detections, output_path):
|
|
118 |
|
119 |
@app.post("/predict/v2")
|
120 |
async def predict_v2(file: UploadFile = File(...)):
|
121 |
-
timestamp = datetime.now().strftime("%Y%m%d_%H%M%
|
122 |
filename = timestamp + file.filename
|
123 |
contents = await file.read()
|
124 |
image = Image.open(BytesIO(contents))
|
125 |
image.save("input/" + filename)
|
126 |
detections = animal_detect_and_classify("input/" + filename)
|
127 |
plot_detected_rectangles(cv2.imread("input/" + filename), detections, "output/" + filename)
|
128 |
-
return {
|
|
|
|
|
|
|
129 |
|
130 |
@app.get("/image/")
|
131 |
async def get_image(image_name: str):
|
132 |
# Assume the images are stored in a directory named "images"
|
133 |
-
image_path = f"
|
134 |
return FileResponse(image_path)
|
135 |
|
136 |
@app.post("/predict")
|
|
|
118 |
|
119 |
@app.post("/predict/v2")
|
120 |
async def predict_v2(file: UploadFile = File(...)):
|
121 |
+
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S_")
|
122 |
filename = timestamp + file.filename
|
123 |
contents = await file.read()
|
124 |
image = Image.open(BytesIO(contents))
|
125 |
image.save("input/" + filename)
|
126 |
detections = animal_detect_and_classify("input/" + filename)
|
127 |
plot_detected_rectangles(cv2.imread("input/" + filename), detections, "output/" + filename)
|
128 |
+
return {
|
129 |
+
"message": "Detection and classification completed successfully",
|
130 |
+
"data": "output/" + filename
|
131 |
+
}
|
132 |
|
133 |
@app.get("/image/")
|
134 |
async def get_image(image_name: str):
|
135 |
# Assume the images are stored in a directory named "images"
|
136 |
+
image_path = f"output/{image_name}"
|
137 |
return FileResponse(image_path)
|
138 |
|
139 |
@app.post("/predict")
|