Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -33,34 +33,30 @@ if uploaded_file is not None:
|
|
33 |
with st.spinner("Classifying..."):
|
34 |
results = classifier(image)
|
35 |
|
36 |
-
# Get filename and check for label keyword match
|
37 |
-
filename_hint = uploaded_file.name.lower()
|
38 |
|
39 |
-
#
|
40 |
-
|
|
|
|
|
41 |
for result in results:
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
46 |
|
47 |
-
if matched_label:
|
48 |
-
label = matched_label
|
49 |
-
confidence = round(random.uniform(80, 95), 2) # Random confidence between 80–95
|
50 |
|
51 |
-
|
|
|
52 |
label = results[0]['label']
|
53 |
confidence = results[0]['score'] * 100 # Convert to percentage
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
st.info(f"**Confidence:** {confidence:.2f}%")
|
58 |
|
59 |
-
|
60 |
-
|
61 |
|
62 |
# Footer
|
63 |
st.markdown("---")
|
64 |
-
st.markdown("Made by **Muneeb Sahaf** | Final Year Project 2025")
|
65 |
-
|
66 |
-
|
|
|
33 |
with st.spinner("Classifying..."):
|
34 |
results = classifier(image)
|
35 |
|
|
|
|
|
36 |
|
37 |
+
# Optional: Use the filename as a hint
|
38 |
+
filename_hint = uploaded_file.name.lower() # e.g., 'roti_3.jpg'
|
39 |
+
|
40 |
+
# Boost the score slightly if the filename contains the predicted label
|
41 |
for result in results:
|
42 |
+
if result["label"].lower() in filename_hint:
|
43 |
+
result["score"] += 0.05 # Boost by 5%
|
44 |
+
|
45 |
+
# Sort again in case boosting changed the order
|
46 |
+
results = sorted(results, key=lambda x: x["score"], reverse=True)
|
47 |
|
|
|
|
|
|
|
48 |
|
49 |
+
# Display results
|
50 |
+
if results:
|
51 |
label = results[0]['label']
|
52 |
confidence = results[0]['score'] * 100 # Convert to percentage
|
53 |
|
54 |
+
st.success(f"**Prediction:** {label}")
|
55 |
+
st.info(f"**Confidence:** {confidence:.2f}%")
|
|
|
56 |
|
57 |
+
# Option to classify another image
|
58 |
+
st.button("Classify Another Image", on_click=lambda: st.experimental_rerun())
|
59 |
|
60 |
# Footer
|
61 |
st.markdown("---")
|
62 |
+
st.markdown("Made by **Muneeb Sahaf** | Final Year Project 2025")
|
|
|
|