AdarshRajDS commited on
Commit
8e269c3
Β·
1 Parent(s): 6bf61b1

Add mold detection Streamlit frontend v5

Browse files
Files changed (1) hide show
  1. app.py +50 -82
app.py CHANGED
@@ -6,8 +6,6 @@ from PIL import Image
6
  # CONFIG
7
  # ==============================
8
  API_BASE = "https://AdarshDS-mold-detection-api.hf.space"
9
-
10
- RESNET_API = f"{API_BASE}/predict/resnet"
11
  CONVNEXT_API = f"{API_BASE}/predict/v2"
12
 
13
  st.set_page_config(
@@ -19,11 +17,12 @@ st.set_page_config(
19
  # UI HEADER
20
  # ==============================
21
  st.title("🦠 AI Mold Detection System")
22
- st.caption("Dual-model analysis using ResNet (Baseline) and ConvNeXt (Advanced)")
23
 
24
  st.write(
25
  "Upload an image of a wall or ceiling. "
26
- "The system evaluates the image using two independent AI models."
 
27
  )
28
 
29
  file = st.file_uploader(
@@ -44,85 +43,54 @@ if file:
44
  "file": (file.name, file_bytes, file.type)
45
  }
46
 
47
- with st.spinner("πŸ” Analyzing image with both models..."):
48
- resnet_resp = requests.post(RESNET_API, files=files_payload)
49
- convnext_resp = requests.post(CONVNEXT_API, files=files_payload)
50
 
51
  st.markdown("---")
52
- st.subheader("πŸ“Š Model Predictions")
53
-
54
- cols = st.columns(2)
55
-
56
- # ==============================
57
- # ResNet Results
58
- # ==============================
59
- with cols[0]:
60
- st.subheader("πŸ”Ή ResNet (Baseline)")
61
-
62
- if resnet_resp.status_code != 200:
63
- st.warning("⚠️ ResNet model unavailable.")
64
- else:
65
- res = resnet_resp.json()
66
-
67
- st.metric("Decision", res["decision"])
68
- st.metric("Mold Probability", res["mold_probability"])
69
- st.metric("Biological Probability", res["biological_probability"])
70
-
71
- if res["decision"] == "Mold":
72
- st.error("❌ Mold detected (ResNet).")
73
- elif res["decision"] == "Possible Mold":
74
- st.warning("⚠️ Possible mold detected (ResNet).")
75
- else:
76
- st.success("βœ… No mold detected (ResNet).")
77
-
78
- # ==============================
79
- # ConvNeXt Results
80
- # ==============================
81
- with cols[1]:
82
- st.subheader("πŸ”Ή ConvNeXt (Advanced)")
83
-
84
- if convnext_resp.status_code != 200:
85
- st.error("❌ ConvNeXt API error.")
86
- st.text(convnext_resp.text)
87
- else:
88
- res = convnext_resp.json()
89
-
90
- st.metric("Decision", res["decision"])
91
- st.metric(
92
- "Mold Probability",
93
- res["model_outputs"]["mold_probability"]
94
  )
95
- st.metric(
96
- "Biological Probability",
97
- res["model_outputs"]["biological_probability"]
 
98
  )
99
-
100
- cc = res["confidence_checks"]
101
- st.caption("Confidence checks")
102
- c1, c2, c3 = st.columns(3)
103
- c1.metric("Uncertainty", cc["uncertainty"])
104
- c2.metric("Patch Ratio", cc["patch_ratio"])
105
- c3.metric("DINO Similarity", cc["dino_similarity"])
106
-
107
- if res["decision"] == "Mold":
108
- st.error("❌ Mold detected (ConvNeXt). Professional remediation recommended.")
109
- elif res["decision"] == "Possible Mold":
110
- st.warning("⚠️ Possible mold detected (ConvNeXt). Human inspection advised.")
111
- else:
112
- st.success("βœ… No mold detected (ConvNeXt).")
113
-
114
- # ==============================
115
- # Comparison Insight (Optional)
116
- # ==============================
117
- try:
118
- if resnet_resp.ok and convnext_resp.ok:
119
- r_dec = resnet_resp.json()["decision"]
120
- c_dec = convnext_resp.json()["decision"]
121
-
122
- if r_dec != c_dec:
123
- st.info(
124
- "ℹ️ The two models disagree. "
125
- "ConvNeXt uses uncertainty estimation and self-supervised verification."
126
- )
127
- except Exception:
128
- pass
 
6
  # CONFIG
7
  # ==============================
8
  API_BASE = "https://AdarshDS-mold-detection-api.hf.space"
 
 
9
  CONVNEXT_API = f"{API_BASE}/predict/v2"
10
 
11
  st.set_page_config(
 
17
  # UI HEADER
18
  # ==============================
19
  st.title("🦠 AI Mold Detection System")
20
+ st.caption("Powered by ConvNeXt (Advanced Model)")
21
 
22
  st.write(
23
  "Upload an image of a wall or ceiling. "
24
+ "The image is analyzed using an advanced ConvNeXt-based AI model "
25
+ "with uncertainty estimation and self-supervised verification."
26
  )
27
 
28
  file = st.file_uploader(
 
43
  "file": (file.name, file_bytes, file.type)
44
  }
45
 
46
+ with st.spinner("πŸ” Analyzing image..."):
47
+ resp = requests.post(CONVNEXT_API, files=files_payload)
 
48
 
49
  st.markdown("---")
50
+ st.subheader("πŸ“Š Prediction Result")
51
+
52
+ if resp.status_code != 200:
53
+ st.error("❌ API error while analyzing the image.")
54
+ st.text(resp.text)
55
+ else:
56
+ res = resp.json()
57
+
58
+ # ==============================
59
+ # Main Results
60
+ # ==============================
61
+ st.metric("Decision", res["decision"])
62
+ st.metric(
63
+ "Mold Probability",
64
+ res["model_outputs"]["mold_probability"]
65
+ )
66
+ st.metric(
67
+ "Biological Probability",
68
+ res["model_outputs"]["biological_probability"]
69
+ )
70
+
71
+ # ==============================
72
+ # Confidence Checks
73
+ # ==============================
74
+ st.subheader("πŸ“ˆ Confidence Checks")
75
+ cc = res["confidence_checks"]
76
+
77
+ c1, c2, c3 = st.columns(3)
78
+ c1.metric("Uncertainty", cc["uncertainty"])
79
+ c2.metric("Patch Ratio", cc["patch_ratio"])
80
+ c3.metric("DINO Similarity", cc["dino_similarity"])
81
+
82
+ # ==============================
83
+ # User Feedback
84
+ # ==============================
85
+ if res["decision"] == "Mold":
86
+ st.error(
87
+ "❌ Mold detected. "
88
+ "Professional remediation is strongly recommended."
 
 
 
89
  )
90
+ elif res["decision"] == "Possible Mold":
91
+ st.warning(
92
+ "⚠️ Possible mold detected. "
93
+ "Human inspection is advised."
94
  )
95
+ else:
96
+ st.success("βœ… No mold detected.")