Spaces:
Sleeping
Sleeping
AdarshRajDS commited on
Commit Β·
8e269c3
1
Parent(s): 6bf61b1
Add mold detection Streamlit frontend v5
Browse files
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("
|
| 23 |
|
| 24 |
st.write(
|
| 25 |
"Upload an image of a wall or ceiling. "
|
| 26 |
-
"The
|
|
|
|
| 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
|
| 48 |
-
|
| 49 |
-
convnext_resp = requests.post(CONVNEXT_API, files=files_payload)
|
| 50 |
|
| 51 |
st.markdown("---")
|
| 52 |
-
st.subheader("π
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
st.metric(
|
| 92 |
-
"Mold Probability",
|
| 93 |
-
res["model_outputs"]["mold_probability"]
|
| 94 |
)
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
|
|
|
| 98 |
)
|
| 99 |
-
|
| 100 |
-
|
| 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.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|