DSCmatter commited on
Commit
456f40a
·
1 Parent(s): f2a15b4

adding intelligent way!

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -10,6 +10,7 @@ from PIL import Image
10
  @st.cache_resource
11
  def load_my_model():
12
  # Load the new, modern .keras file
 
13
  model = load_model('resnet50_dryfruits.keras')
14
  return model
15
 
@@ -48,7 +49,17 @@ if uploaded_file is not None:
48
  predicted_class_name = class_names[predicted_index]
49
  confidence = np.max(prediction[0])
50
 
51
- # 3. Display results
 
 
 
52
  st.image(img, caption="Uploaded Image", use_column_width=True)
53
- st.markdown(f"## Prediction: **{predicted_class_name}**")
54
- st.markdown(f"### Confidence: **{confidence * 100:.2f}%**")
 
 
 
 
 
 
 
 
10
  @st.cache_resource
11
  def load_my_model():
12
  # Load the new, modern .keras file
13
+ # (Assuming your file is named 'resnet50_dryfruits.keras')
14
  model = load_model('resnet50_dryfruits.keras')
15
  return model
16
 
 
49
  predicted_class_name = class_names[predicted_index]
50
  confidence = np.max(prediction[0])
51
 
52
+ # 3. Display results with confidence threshold
53
+ CONFIDENCE_THRESHOLD = 0.85 # Set your threshold (e.g., 90%)
54
+
55
+ # Always display the uploaded image
56
  st.image(img, caption="Uploaded Image", use_column_width=True)
57
+
58
+ if confidence < CONFIDENCE_THRESHOLD:
59
+ # If confidence is low, show a "Not Sure" message
60
+ st.markdown(f"## Prediction: Not Sure")
61
+ st.write(f"This doesn't look like a dry fruit from my dataset. Please upload a clearer image.")
62
+ else:
63
+ # If confidence is high, show the prediction
64
+ st.markdown(f"## Prediction: **{predicted_class_name}**")
65
+ st.markdown(f"### Confidence: **{confidence * 100:.2f}%**")