srijaydeshpande commited on
Commit
ce0ca30
·
verified ·
1 Parent(s): e899207

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -8
app.py CHANGED
@@ -20,11 +20,20 @@ model_dir = snapshot_download(
20
  repo_id="srijaydeshpande/spadesegresnet"
21
  )
22
 
 
 
 
 
 
 
 
 
 
 
23
  class SPADE(nn.Module):
24
  def __init__(self, norm_nc, label_nc, norm):
25
  super().__init__()
26
 
27
-
28
  if norm == 'instance':
29
  self.param_free_norm = nn.InstanceNorm2d(norm_nc, affine=False)
30
  elif norm == 'batch':
@@ -279,12 +288,49 @@ examples = [
279
  ["sample2.png"]
280
  ]
281
 
282
- demo = gr.Interface(
283
- segment_image,
284
- inputs=gr.Image(),
285
- examples=examples,
286
- outputs=["image", "image", "image"],
287
- title="Breast Cancer Semantic Segmentation"
288
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
289
 
290
  demo.launch()
 
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__()
36
 
 
37
  if norm == 'instance':
38
  self.param_free_norm = nn.InstanceNorm2d(norm_nc, affine=False)
39
  elif norm == 'batch':
 
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
+ # demo = gr.Interface(
299
+ # segment_image,
300
+ # inputs=gr.Image(),
301
+ # examples=examples,
302
+ # outputs=["image", "image", "image"],
303
+ # title="Breast Cancer Semantic Segmentation"
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()