Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -20,16 +20,6 @@ model_dir = snapshot_download(
|
|
20 |
repo_id="srijaydeshpande/spadesegresnet"
|
21 |
)
|
22 |
|
23 |
-
def superimpose_images(image1, image2, alpha=0.5):
|
24 |
-
if image1 is None or image2 is None:
|
25 |
-
return "Please upload both images."
|
26 |
-
try:
|
27 |
-
image1 = image1.resize(image2.size)
|
28 |
-
blended = Image.blend(image1, image2, alpha)
|
29 |
-
return blended
|
30 |
-
except Exception as e:
|
31 |
-
return f"Error superimposing images: {str(e)}"
|
32 |
-
|
33 |
class SPADE(nn.Module):
|
34 |
def __init__(self, norm_nc, label_nc, norm):
|
35 |
super().__init__()
|
@@ -276,7 +266,20 @@ def segment_image(image):
|
|
276 |
|
277 |
legend = Image.open('legend.png')
|
278 |
|
279 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
280 |
|
281 |
model_path = os.path.join(model_dir, 'spaderesnet.pt')
|
282 |
model = SPADEResNet(input_nc=3, output_nc=6)
|
@@ -287,50 +290,13 @@ examples = [
|
|
287 |
["sample1.png"],
|
288 |
["sample2.png"]
|
289 |
]
|
290 |
-
|
291 |
-
input1 = gr.Image()
|
292 |
-
output1 = gr.Image()
|
293 |
-
output2 = gr.Image()
|
294 |
-
output3 = gr.Image()
|
295 |
-
|
296 |
-
with gr.Blocks() as demo:
|
297 |
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
# Segmentation Section
|
307 |
-
segment_button = gr.Button("Segment Image")
|
308 |
-
segment_button.click(
|
309 |
-
segment_image,
|
310 |
-
inputs=input1,
|
311 |
-
# examples=examples,
|
312 |
-
outputs=[output1, output2, output3],
|
313 |
-
# title="Breast Cancer Semantic Segmentation"
|
314 |
-
)
|
315 |
-
|
316 |
-
# Superimpose Section
|
317 |
-
gr.Markdown("### Superimpose Images")
|
318 |
-
|
319 |
-
alpha_slider = gr.Slider(minimum=0, maximum=1, value=0.5, step=0.1, label="Alpha (Transparency)")
|
320 |
-
superimpose_btn = gr.Button("Superimpose")
|
321 |
-
|
322 |
-
superimpose_btn.click(
|
323 |
-
superimpose_images,
|
324 |
-
inputs=[input1, output1, alpha_slider],
|
325 |
-
outputs=output_image
|
326 |
-
)
|
327 |
-
|
328 |
-
# demo = gr.Interface(
|
329 |
-
# segment_image,
|
330 |
-
# inputs=gr.Image(),
|
331 |
-
# examples=examples,
|
332 |
-
# outputs=["image", "image", "image"],
|
333 |
-
# title="Breast Cancer Semantic Segmentation"
|
334 |
-
# )
|
335 |
|
336 |
demo.launch()
|
|
|
20 |
repo_id="srijaydeshpande/spadesegresnet"
|
21 |
)
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
class SPADE(nn.Module):
|
24 |
def __init__(self, norm_nc, label_nc, norm):
|
25 |
super().__init__()
|
|
|
266 |
|
267 |
legend = Image.open('legend.png')
|
268 |
|
269 |
+
superimposed_image = superimpose_images(img, image)
|
270 |
+
|
271 |
+
return image, legend, stats, superimposed_image
|
272 |
+
|
273 |
+
def superimpose_images(image1, image2, alpha=0.5):
|
274 |
+
if image1 is None or image2 is None:
|
275 |
+
return "Please upload both images."
|
276 |
+
try:
|
277 |
+
image1 = image1.resize(image2.size)
|
278 |
+
blended = Image.blend(image1, image2, alpha)
|
279 |
+
return blended
|
280 |
+
except Exception as e:
|
281 |
+
return f"Error superimposing images: {str(e)}"
|
282 |
+
|
283 |
|
284 |
model_path = os.path.join(model_dir, 'spaderesnet.pt')
|
285 |
model = SPADEResNet(input_nc=3, output_nc=6)
|
|
|
290 |
["sample1.png"],
|
291 |
["sample2.png"]
|
292 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
293 |
|
294 |
+
demo = gr.Interface(
|
295 |
+
segment_image,
|
296 |
+
inputs=gr.Image(),
|
297 |
+
examples=examples,
|
298 |
+
outputs=["image", "image", "image", "image"],
|
299 |
+
title="Breast Cancer Semantic Segmentation"
|
300 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
301 |
|
302 |
demo.launch()
|