munnae commited on
Commit
2e57375
·
verified ·
1 Parent(s): 3bb9f08

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -20
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
- # Look for a label match in the filename
40
- matched_label = None
 
 
41
  for result in results:
42
- label = result["label"].lower()
43
- if label in filename_hint:
44
- matched_label = result["label"] # Keep original label casing
45
- break # Use the first match found
 
46
 
47
- if matched_label:
48
- label = matched_label
49
- confidence = round(random.uniform(80, 95), 2) # Random confidence between 80–95
50
 
51
- else:
 
52
  label = results[0]['label']
53
  confidence = results[0]['score'] * 100 # Convert to percentage
54
 
55
- # Display results
56
- st.success(f"**Prediction:** {label}")
57
- st.info(f"**Confidence:** {confidence:.2f}%")
58
 
59
- # Option to classify another image
60
- st.button("Classify Another Image", on_click=lambda: st.experimental_rerun())
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")