Spaces:
Sleeping
Sleeping
IZERE HIRWA Roger
commited on
Commit
·
cdcf202
1
Parent(s):
cbb1938
vop
Browse files- app.py +10 -3
- result.png +1 -5
app.py
CHANGED
@@ -71,16 +71,23 @@ def segment_endpoint():
|
|
71 |
return {"error": "image file and prompt are required."}, 400
|
72 |
|
73 |
prompt = request.form["prompt"]
|
74 |
-
image =
|
|
|
|
|
|
|
|
|
75 |
|
76 |
try:
|
77 |
-
|
|
|
78 |
except ValueError as e:
|
79 |
return {"error": str(e)}, 422
|
|
|
|
|
80 |
|
81 |
overlay = request.args.get("overlay", "false").lower() == "true"
|
82 |
if overlay:
|
83 |
-
colored = np.array(
|
84 |
colored[mask] = [255, 0, 0] # red overlay
|
85 |
out_img = Image.fromarray(colored)
|
86 |
else:
|
|
|
71 |
return {"error": "image file and prompt are required."}, 400
|
72 |
|
73 |
prompt = request.form["prompt"]
|
74 |
+
image = request.files["image"]
|
75 |
+
|
76 |
+
# Check for unsupported file types
|
77 |
+
if not image.content_type.startswith("image/"):
|
78 |
+
return {"error": "unsupported file type. Only image files are allowed."}, 415
|
79 |
|
80 |
try:
|
81 |
+
image_pil = Image.open(image.stream).convert("RGB")
|
82 |
+
mask = segment(image_pil, prompt)
|
83 |
except ValueError as e:
|
84 |
return {"error": str(e)}, 422
|
85 |
+
except Exception as e:
|
86 |
+
return {"error": "not supported"}, 500
|
87 |
|
88 |
overlay = request.args.get("overlay", "false").lower() == "true"
|
89 |
if overlay:
|
90 |
+
colored = np.array(image_pil).copy()
|
91 |
colored[mask] = [255, 0, 0] # red overlay
|
92 |
out_img = Image.fromarray(colored)
|
93 |
else:
|
result.png
CHANGED
![]() |
![]() |