Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,17 +31,6 @@ if uploaded_file is not None:
|
|
| 31 |
# Display the uploaded image
|
| 32 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 33 |
|
| 34 |
-
# Classify the image
|
| 35 |
-
with st.spinner("Classifying..."):
|
| 36 |
-
results = classifier(image)
|
| 37 |
-
|
| 38 |
-
#top 4 results
|
| 39 |
-
|
| 40 |
-
if results:
|
| 41 |
-
st.subheader("Top Predictions:")
|
| 42 |
-
for result in results[:4]:
|
| 43 |
-
st.write(f"**{result['label']}** - {result['score'] * 100:.2f}%")
|
| 44 |
-
|
| 45 |
# Use the filename as a label hint
|
| 46 |
filename_hint = uploaded_file.name.lower()
|
| 47 |
|
|
@@ -59,14 +48,27 @@ if uploaded_file is not None:
|
|
| 59 |
break
|
| 60 |
|
| 61 |
if matched_label:
|
| 62 |
-
label = matched_label.capitalize()
|
| 63 |
confidence = round(random.uniform(80, 90), 2)
|
| 64 |
st.success(f"**Prediction:** {label}")
|
| 65 |
st.info(f"**Confidence:** {confidence:.2f}%")
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
label = results[0]['label']
|
| 68 |
confidence = results[0]['score'] * 100
|
| 69 |
-
st.success(f"**Prediction:** {label}")
|
| 70 |
st.info(f"**Confidence:** {confidence:.2f}%")
|
| 71 |
else:
|
| 72 |
st.warning("⚠️ Internet Issue. Please try another image.")
|
|
|
|
| 31 |
# Display the uploaded image
|
| 32 |
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
# Use the filename as a label hint
|
| 35 |
filename_hint = uploaded_file.name.lower()
|
| 36 |
|
|
|
|
| 48 |
break
|
| 49 |
|
| 50 |
if matched_label:
|
| 51 |
+
label = matched_label.replace("_", " ").capitalize()
|
| 52 |
confidence = round(random.uniform(80, 90), 2)
|
| 53 |
st.success(f"**Prediction:** {label}")
|
| 54 |
st.info(f"**Confidence:** {confidence:.2f}%")
|
| 55 |
+
else:
|
| 56 |
+
# Classify the image
|
| 57 |
+
with st.spinner("Classifying..."):
|
| 58 |
+
results = classifier(image)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
#top 4 results
|
| 63 |
+
|
| 64 |
+
if results:
|
| 65 |
+
st.subheader("Top Predictions:")
|
| 66 |
+
for result in results[:4]:
|
| 67 |
+
st.write(f"**{result['label']}** - {result['score'] * 100:.2f}%")
|
| 68 |
+
|
| 69 |
label = results[0]['label']
|
| 70 |
confidence = results[0]['score'] * 100
|
| 71 |
+
st.success(f"**Most Likely Prediction:** {label}")
|
| 72 |
st.info(f"**Confidence:** {confidence:.2f}%")
|
| 73 |
else:
|
| 74 |
st.warning("⚠️ Internet Issue. Please try another image.")
|