carlosriverat commited on
Commit
b883a76
·
verified ·
1 Parent(s): 24647ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -20
app.py CHANGED
@@ -49,24 +49,23 @@ def compare_images(image1, image2, blur_value, technique, threshold_value):
49
  def update_threshold_visibility(technique):
50
  return gr.update(visible=(technique == "Simple Binary"))
51
 
52
- demo = gr.Interface(
53
- fn=compare_images,
54
- inputs=[
55
- gr.Image(type="numpy", label="Image Without Object"),
56
- gr.Image(type="numpy", label="Image With Object"),
57
- gr.Slider(minimum=1, maximum=15, step=2, value=5, label="Gaussian Blur"),
58
- gr.Dropdown(["Adaptive Threshold", "Otsu's Threshold", "Simple Binary"], label="Thresholding Technique", value="Adaptive Threshold", interactive=True),
59
- gr.Slider(minimum=0, maximum=255, step=1, value=50, label="Threshold Value", visible=False)
60
- ],
61
- outputs=[
62
- gr.Image(type="numpy", label="Highlighted Differences"),
63
- gr.Image(type="numpy", label="Raw Difference Overlay (Magenta)")
64
- ],
65
- title="Object Difference Highlighter",
66
- description="Upload two images: one without an object and one with an object. The app will highlight only the newly added object and show the real differences in magenta overlayed on the original image.",
67
- live=True
68
- )
69
-
70
- demo.load(update_threshold_visibility, inputs=["Thresholding Technique"], outputs=["Threshold Value"])
71
 
72
- demo.launch()
 
49
  def update_threshold_visibility(technique):
50
  return gr.update(visible=(technique == "Simple Binary"))
51
 
52
+ with gr.Blocks() as demo:
53
+ gr.Markdown("# Object Difference Highlighter\nUpload two images: one without an object and one with an object. The app will highlight only the newly added object and show the real differences in magenta overlayed on the original image.")
54
+
55
+ with gr.Row():
56
+ img1 = gr.Image(type="numpy", label="Image Without Object")
57
+ img2 = gr.Image(type="numpy", label="Image With Object")
58
+
59
+ blur_slider = gr.Slider(minimum=1, maximum=15, step=2, value=5, label="Gaussian Blur")
60
+ technique_dropdown = gr.Dropdown(["Adaptive Threshold", "Otsu's Threshold", "Simple Binary"], label="Thresholding Technique", value="Adaptive Threshold", interactive=True)
61
+ threshold_slider = gr.Slider(minimum=0, maximum=255, step=1, value=50, label="Threshold Value", visible=False)
62
+
63
+ technique_dropdown.change(update_threshold_visibility, inputs=[technique_dropdown], outputs=[threshold_slider])
64
+
65
+ output1 = gr.Image(type="numpy", label="Highlighted Differences")
66
+ output2 = gr.Image(type="numpy", label="Raw Difference Overlay (Magenta)")
67
+
68
+ btn = gr.Button("Process")
69
+ btn.click(compare_images, inputs=[img1, img2, blur_slider, technique_dropdown, threshold_slider], outputs=[output1, output2])
 
70
 
71
+ demo.launch()