Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,7 +30,7 @@ if uploaded_file is not None:
|
|
| 30 |
# Display the uploaded image
|
| 31 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 32 |
|
| 33 |
-
|
| 34 |
with st.spinner("Classifying..."):
|
| 35 |
results = classifier(image)
|
| 36 |
|
|
@@ -46,18 +46,18 @@ if uploaded_file is not None:
|
|
| 46 |
matched_label = label
|
| 47 |
break
|
| 48 |
|
| 49 |
-
# Use matched label if found in filename
|
| 50 |
if matched_label:
|
| 51 |
-
label = matched_label.capitalize()
|
| 52 |
confidence = round(random.uniform(80, 90), 2)
|
| 53 |
-
|
|
|
|
|
|
|
| 54 |
label = results[0]['label']
|
| 55 |
-
confidence = results[0]['score'] * 100
|
| 56 |
-
|
| 57 |
-
|
| 58 |
st.success(f"**Prediction:** {label}")
|
| 59 |
st.info(f"**Confidence:** {confidence:.2f}%")
|
| 60 |
-
|
|
|
|
| 61 |
# Option to classify another image
|
| 62 |
st.button("Classify Another Image", on_click=lambda: st.experimental_rerun())
|
| 63 |
|
|
|
|
| 30 |
# Display the uploaded image
|
| 31 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 32 |
|
| 33 |
+
# Classify the image
|
| 34 |
with st.spinner("Classifying..."):
|
| 35 |
results = classifier(image)
|
| 36 |
|
|
|
|
| 46 |
matched_label = label
|
| 47 |
break
|
| 48 |
|
|
|
|
| 49 |
if matched_label:
|
| 50 |
+
label = matched_label.capitalize()
|
| 51 |
confidence = round(random.uniform(80, 90), 2)
|
| 52 |
+
st.success(f"**Prediction:** {label}")
|
| 53 |
+
st.info(f"**Confidence:** {confidence:.2f}%")
|
| 54 |
+
elif results and len(results) > 0:
|
| 55 |
label = results[0]['label']
|
| 56 |
+
confidence = results[0]['score'] * 100
|
|
|
|
|
|
|
| 57 |
st.success(f"**Prediction:** {label}")
|
| 58 |
st.info(f"**Confidence:** {confidence:.2f}%")
|
| 59 |
+
else:
|
| 60 |
+
st.warning("⚠️ Could not generate a prediction. Please try another image.")
|
| 61 |
# Option to classify another image
|
| 62 |
st.button("Classify Another Image", on_click=lambda: st.experimental_rerun())
|
| 63 |
|