HeetSavaliya commited on
Commit
381088a
Β·
verified Β·
1 Parent(s): 9d74a95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +106 -103
app.py CHANGED
@@ -1541,6 +1541,109 @@ with gr.Blocks(title="πŸ§ͺ Toilet Segmentation & Measurement App") as full_app_i
1541
  out_image = gr.Image(label="πŸ” Top Rim Width", height=600, width=800)
1542
  with gr.Row():
1543
  top_width_str = gr.Textbox(label="πŸ” Top Width:", interactive=False, elem_id='pretty-box')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1544
 
1545
  # πŸ”— Pipeline chaining starting from Part 4
1546
  run_pipeline_btn.click(fn=segment_and_overlay_all_p4,
@@ -1724,110 +1827,10 @@ with gr.Blocks(title="πŸ§ͺ Toilet Segmentation & Measurement App") as full_app_i
1724
  out_dist_in,
1725
  out_angle_deg,
1726
  top_width_str
1727
- ])
1728
-
1729
- import gradio as gr
1730
-
1731
- def get_predictions_by_unit(unit, closed_remaining_in, top_to_hole_line_inch,
1732
- hole_width_inch, out_rimellipse_inch, rim_height_inch, out_dist_in):
1733
- # Compute values in inches
1734
- a1 = abs(closed_remaining_in - top_to_hole_line_inch)
1735
- b1 = top_to_hole_line_inch
1736
- c1 = hole_width_inch
1737
- d1 = float(out_rimellipse_inch["right_inner"]) * 2
1738
- e1 = float(out_rimellipse_inch["down_inner"]) * 2
1739
- f1 = float(out_rimellipse_inch["right_outer"]) * 2
1740
- g1 = rim_height_inch
1741
- h1 = out_dist_in
1742
-
1743
- if unit == "in":
1744
- return [a1, b1, c1, d1, e1, f1, g1, h1]
1745
- elif unit == "cm":
1746
- return [x * 2.54 for x in [a1, b1, c1, d1, e1, f1, g1, h1]]
1747
- else:
1748
- return [0.0] * 8
1749
-
1750
- def compare_measurements(a1, b1, c1, d1, e1, f1, g1, h1, a2, b2, c2, d2, e2, f2, g2, h2):
1751
- a2, b2, c2, d2, e2, f2, g2, h2 = float(a2), float(b2), float(c2), float(d2), float(e2), float(f2), float(g2), float(h2)
1752
- a1, b1, c1, d1, e1, f1, g1, h1 = float(a1), float(b1), float(c1), float(d1), float(e1), float(f1), float(g1), float(h1)
1753
- def error(gt, pred):
1754
- if gt == 0:
1755
- return "N/A"
1756
- return f"{abs(gt - pred) / gt * 100:.2f}%"
1757
-
1758
- errors = {
1759
- "a": error(a2, a1),
1760
- "b": error(b2, b1),
1761
- "c": error(c2, c1),
1762
- "d": error(d2, d1),
1763
- "e": error(e2, e1),
1764
- "f": error(f2, f1),
1765
- "g": error(g2, g1),
1766
- "h": error(h2, h1)
1767
- }
1768
-
1769
- valid_errors = [
1770
- abs(gt - pred) / gt * 100
1771
- for gt, pred in [
1772
- (a2, a1), (b2, b1), (c2, c1), (d2, d1), (e2, e1), (f2, f1), (g2, g1), (h2, h1)
1773
- ] if gt != 0
1774
- ]
1775
-
1776
- avg_error = f"{sum(valid_errors)/len(valid_errors):.2f}%" if valid_errors else "N/A"
1777
-
1778
- return errors, f"βœ… Average Error: {avg_error}"
1779
-
1780
- gr.Markdown("## πŸ“ Ground Truth vs Predicted Measurements Comparison")
1781
-
1782
- with gr.Row():
1783
- gr.Markdown("### πŸ–ΌοΈ Reference Diagram")
1784
- ref_image = gr.Image(value="./static/reference.jpg", interactive=False, label="Measurement Guide")
1785
-
1786
- unit_dropdown = gr.Radio(choices=["in", "cm"], label="Select Unit", value="in")
1787
-
1788
- with gr.Row():
1789
- with gr.Column():
1790
- gr.Markdown("### πŸ“Š Predicted Values")
1791
- a1 = gr.Number(label="a", interactive=False)
1792
- b1 = gr.Number(label="b", interactive=False)
1793
- c1 = gr.Number(label="c", interactive=False)
1794
- d1 = gr.Number(label="d", interactive=False)
1795
- e1 = gr.Number(label="e", interactive=False)
1796
- f1 = gr.Number(label="f", interactive=False)
1797
- g1 = gr.Number(label="g", interactive=False)
1798
- h1 = gr.Number(label="h", interactive=False)
1799
-
1800
- with gr.Column():
1801
- gr.Markdown("### βœ… Enter True Values")
1802
- a2 = gr.Number(label="a")
1803
- b2 = gr.Number(label="b")
1804
- c2 = gr.Number(label="c")
1805
- d2 = gr.Number(label="d")
1806
- e2 = gr.Number(label="e")
1807
- f2 = gr.Number(label="f")
1808
- g2 = gr.Number(label="g")
1809
- h2 = gr.Number(label="h")
1810
-
1811
- def update_preds(unit, closed_remaining_in_p11, top_to_hole_line_inch_p10, hole_width_inch_p9, out_rimellipse_inch_p7, rim_height_inch_p8, out_dist_in):
1812
- return get_predictions_by_unit(unit, closed_remaining_in_p11, top_to_hole_line_inch_p10,hole_width_inch_p9, out_rimellipse_inch_p7,rim_height_inch_p8, out_dist_in)
1813
-
1814
- unit_dropdown.change(
1815
- fn=update_preds,
1816
  inputs=[unit_dropdown, closed_remaining_in_p11, top_to_hole_line_inch_p10, hole_width_inch_p9, out_rimellipse_inch_p7, rim_height_inch_p8, out_dist_in],
1817
- outputs=[a1, b1, c1, d1, e1, f1, g1, h1]
1818
- )
1819
-
1820
- submit_btn = gr.Button("πŸ“ˆ Compare & Calculate Error")
1821
-
1822
- with gr.Row():
1823
- result_json = gr.JSON(label="πŸ“‰ Individual Error %")
1824
- avg_error_text = gr.Textbox(label="πŸ“Š Average Error %")
1825
-
1826
- submit_btn.click(
1827
- fn=compare_measurements,
1828
- inputs=[a1, b1, c1, d1, e1, f1, g1, h1, a2, b2, c2, d2, e2, f2, g2, h2],
1829
- outputs=[result_json, avg_error_text]
1830
- )
1831
 
1832
  with gr.Row():
1833
  gr.Markdown(
 
1541
  out_image = gr.Image(label="πŸ” Top Rim Width", height=600, width=800)
1542
  with gr.Row():
1543
  top_width_str = gr.Textbox(label="πŸ” Top Width:", interactive=False, elem_id='pretty-box')
1544
+
1545
+ import gradio as gr
1546
+
1547
+ def get_predictions_by_unit(unit, closed_remaining_in, top_to_hole_line_inch,
1548
+ hole_width_inch, out_rimellipse_inch, rim_height_inch, out_dist_in):
1549
+ # Compute values in inches
1550
+ a1 = abs(closed_remaining_in - top_to_hole_line_inch)
1551
+ b1 = top_to_hole_line_inch
1552
+ c1 = hole_width_inch
1553
+ d1 = float(out_rimellipse_inch["right_inner"]) * 2
1554
+ e1 = float(out_rimellipse_inch["down_inner"]) * 2
1555
+ f1 = float(out_rimellipse_inch["right_outer"]) * 2
1556
+ g1 = rim_height_inch
1557
+ h1 = out_dist_in
1558
+
1559
+ if unit == "in":
1560
+ return [a1, b1, c1, d1, e1, f1, g1, h1]
1561
+ elif unit == "cm":
1562
+ return [x * 2.54 for x in [a1, b1, c1, d1, e1, f1, g1, h1]]
1563
+ else:
1564
+ return [0.0] * 8
1565
+
1566
+ def compare_measurements(a1, b1, c1, d1, e1, f1, g1, h1, a2, b2, c2, d2, e2, f2, g2, h2):
1567
+ a2, b2, c2, d2, e2, f2, g2, h2 = float(a2), float(b2), float(c2), float(d2), float(e2), float(f2), float(g2), float(h2)
1568
+ a1, b1, c1, d1, e1, f1, g1, h1 = float(a1), float(b1), float(c1), float(d1), float(e1), float(f1), float(g1), float(h1)
1569
+ def error(gt, pred):
1570
+ if gt == 0:
1571
+ return "N/A"
1572
+ return f"{abs(gt - pred) / gt * 100:.2f}%"
1573
+
1574
+ errors = {
1575
+ "a": error(a2, a1),
1576
+ "b": error(b2, b1),
1577
+ "c": error(c2, c1),
1578
+ "d": error(d2, d1),
1579
+ "e": error(e2, e1),
1580
+ "f": error(f2, f1),
1581
+ "g": error(g2, g1),
1582
+ "h": error(h2, h1)
1583
+ }
1584
+
1585
+ valid_errors = [
1586
+ abs(gt - pred) / gt * 100
1587
+ for gt, pred in [
1588
+ (a2, a1), (b2, b1), (c2, c1), (d2, d1), (e2, e1), (f2, f1), (g2, g1), (h2, h1)
1589
+ ] if gt != 0
1590
+ ]
1591
+
1592
+ avg_error = f"{sum(valid_errors)/len(valid_errors):.2f}%" if valid_errors else "N/A"
1593
+
1594
+ return errors, f"βœ… Average Error: {avg_error}"
1595
+
1596
+ gr.Markdown("## πŸ“ Ground Truth vs Predicted Measurements Comparison")
1597
+
1598
+ with gr.Row():
1599
+ gr.Markdown("### πŸ–ΌοΈ Reference Diagram")
1600
+ ref_image = gr.Image(value="./static/reference.jpg", interactive=False, label="Measurement Guide")
1601
+
1602
+ unit_dropdown = gr.Radio(choices=["in", "cm"], label="Select Unit", value="in")
1603
+
1604
+ with gr.Row():
1605
+ with gr.Column():
1606
+ gr.Markdown("### πŸ“Š Predicted Values")
1607
+ a1 = gr.Number(label="a", interactive=False)
1608
+ b1 = gr.Number(label="b", interactive=False)
1609
+ c1 = gr.Number(label="c", interactive=False)
1610
+ d1 = gr.Number(label="d", interactive=False)
1611
+ e1 = gr.Number(label="e", interactive=False)
1612
+ f1 = gr.Number(label="f", interactive=False)
1613
+ g1 = gr.Number(label="g", interactive=False)
1614
+ h1 = gr.Number(label="h", interactive=False)
1615
+
1616
+ with gr.Column():
1617
+ gr.Markdown("### βœ… Enter True Values")
1618
+ a2 = gr.Number(label="a")
1619
+ b2 = gr.Number(label="b")
1620
+ c2 = gr.Number(label="c")
1621
+ d2 = gr.Number(label="d")
1622
+ e2 = gr.Number(label="e")
1623
+ f2 = gr.Number(label="f")
1624
+ g2 = gr.Number(label="g")
1625
+ h2 = gr.Number(label="h")
1626
+
1627
+ def update_preds(unit, closed_remaining_in_p11, top_to_hole_line_inch_p10, hole_width_inch_p9, out_rimellipse_inch_p7, rim_height_inch_p8, out_dist_in):
1628
+ return get_predictions_by_unit(unit, closed_remaining_in_p11, top_to_hole_line_inch_p10,hole_width_inch_p9, out_rimellipse_inch_p7,rim_height_inch_p8, out_dist_in)
1629
+
1630
+ unit_dropdown.change(
1631
+ fn=update_preds,
1632
+ inputs=[unit_dropdown, closed_remaining_in_p11, top_to_hole_line_inch_p10, hole_width_inch_p9, out_rimellipse_inch_p7, rim_height_inch_p8, out_dist_in],
1633
+ outputs=[a1, b1, c1, d1, e1, f1, g1, h1]
1634
+ )
1635
+
1636
+ submit_btn = gr.Button("πŸ“ˆ Compare & Calculate Error")
1637
+
1638
+ with gr.Row():
1639
+ result_json = gr.JSON(label="πŸ“‰ Individual Error %")
1640
+ avg_error_text = gr.Textbox(label="πŸ“Š Average Error %")
1641
+
1642
+ submit_btn.click(
1643
+ fn=compare_measurements,
1644
+ inputs=[a1, b1, c1, d1, e1, f1, g1, h1, a2, b2, c2, d2, e2, f2, g2, h2],
1645
+ outputs=[result_json, avg_error_text]
1646
+ )
1647
 
1648
  # πŸ”— Pipeline chaining starting from Part 4
1649
  run_pipeline_btn.click(fn=segment_and_overlay_all_p4,
 
1827
  out_dist_in,
1828
  out_angle_deg,
1829
  top_width_str
1830
+ ]).\
1831
+ then(fn=update_preds,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1832
  inputs=[unit_dropdown, closed_remaining_in_p11, top_to_hole_line_inch_p10, hole_width_inch_p9, out_rimellipse_inch_p7, rim_height_inch_p8, out_dist_in],
1833
+ outputs=[a1, b1, c1, d1, e1, f1, g1, h1])
 
 
 
 
 
 
 
 
 
 
 
 
 
1834
 
1835
  with gr.Row():
1836
  gr.Markdown(