Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -139,10 +139,10 @@ def main():
|
|
| 139 |
threshold = st.slider(
|
| 140 |
"Anomaly Threshold",
|
| 141 |
min_value=0.0,
|
| 142 |
-
max_value=
|
| 143 |
-
value=
|
| 144 |
-
step=0.
|
| 145 |
-
help="Adjust sensitivity: lower = more sensitive to defects"
|
| 146 |
)
|
| 147 |
|
| 148 |
show_heatmap = st.checkbox("Show Anomaly Heatmap", value=True)
|
|
@@ -169,6 +169,9 @@ def main():
|
|
| 169 |
- π Anomaly score quantification
|
| 170 |
- π CPU-friendly inference
|
| 171 |
""")
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
|
| 174 |
# Load model
|
|
@@ -191,12 +194,18 @@ def main():
|
|
| 191 |
use_demo = st.button("π² Try Demo Image")
|
| 192 |
|
| 193 |
if use_demo:
|
| 194 |
-
# Load a random test image
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
|
| 201 |
if uploaded_file is not None:
|
| 202 |
# Load image
|
|
@@ -323,20 +332,18 @@ def main():
|
|
| 323 |
st.divider()
|
| 324 |
st.subheader("π Example Defect Types")
|
| 325 |
|
| 326 |
-
cols = st.columns(
|
| 327 |
defect_examples = {
|
| 328 |
-
"
|
| 329 |
-
"Crack": config.TEST_DIR / "crack",
|
| 330 |
"Poke": config.TEST_DIR / "poke",
|
| 331 |
-
"
|
| 332 |
-
"Squeeze": config.TEST_DIR / "squeeze"
|
| 333 |
}
|
| 334 |
|
| 335 |
for idx, (defect_name, defect_dir) in enumerate(defect_examples.items()):
|
| 336 |
if defect_dir.exists():
|
| 337 |
images = list(defect_dir.glob("*.png"))
|
| 338 |
if images:
|
| 339 |
-
with cols[idx %
|
| 340 |
example_img = Image.open(images[0])
|
| 341 |
st.image(example_img, caption=defect_name, use_column_width=True)
|
| 342 |
|
|
|
|
| 139 |
threshold = st.slider(
|
| 140 |
"Anomaly Threshold",
|
| 141 |
min_value=0.0,
|
| 142 |
+
max_value=30.0,
|
| 143 |
+
value=15.0,
|
| 144 |
+
step=0.5,
|
| 145 |
+
help="Adjust sensitivity: lower = more sensitive to defects (typical range: 10-20)"
|
| 146 |
)
|
| 147 |
|
| 148 |
show_heatmap = st.checkbox("Show Anomaly Heatmap", value=True)
|
|
|
|
| 169 |
- π Anomaly score quantification
|
| 170 |
- π CPU-friendly inference
|
| 171 |
""")
|
| 172 |
+
|
| 173 |
+
st.divider()
|
| 174 |
+
st.warning("β οΈ **Model Limitation:** This model is trained specifically on the Actavis 500mg capsule dataset. It will NOT work accurately on other tablet/capsule types, shapes, or colors.")
|
| 175 |
|
| 176 |
|
| 177 |
# Load model
|
|
|
|
| 194 |
use_demo = st.button("π² Try Demo Image")
|
| 195 |
|
| 196 |
if use_demo:
|
| 197 |
+
# Load a random test image from specific defect types only
|
| 198 |
+
demo_categories = ["squeeze", "poke", "crack"]
|
| 199 |
+
demo_category = np.random.choice(demo_categories)
|
| 200 |
+
demo_dir = config.TEST_DIR / demo_category
|
| 201 |
+
|
| 202 |
+
if demo_dir.exists():
|
| 203 |
+
demo_images = list(demo_dir.glob("*.png"))
|
| 204 |
+
if demo_images:
|
| 205 |
+
demo_path = np.random.choice(demo_images)
|
| 206 |
+
uploaded_file = demo_path
|
| 207 |
+
else:
|
| 208 |
+
st.error(f"Demo category '{demo_category}' not found.")
|
| 209 |
|
| 210 |
if uploaded_file is not None:
|
| 211 |
# Load image
|
|
|
|
| 332 |
st.divider()
|
| 333 |
st.subheader("π Example Defect Types")
|
| 334 |
|
| 335 |
+
cols = st.columns(3)
|
| 336 |
defect_examples = {
|
| 337 |
+
"Squeeze": config.TEST_DIR / "squeeze",
|
|
|
|
| 338 |
"Poke": config.TEST_DIR / "poke",
|
| 339 |
+
"Crack": config.TEST_DIR / "crack"
|
|
|
|
| 340 |
}
|
| 341 |
|
| 342 |
for idx, (defect_name, defect_dir) in enumerate(defect_examples.items()):
|
| 343 |
if defect_dir.exists():
|
| 344 |
images = list(defect_dir.glob("*.png"))
|
| 345 |
if images:
|
| 346 |
+
with cols[idx % 3]:
|
| 347 |
example_img = Image.open(images[0])
|
| 348 |
st.image(example_img, caption=defect_name, use_column_width=True)
|
| 349 |
|