Spaces:
Sleeping
Sleeping
Dileep7729
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -56,14 +56,18 @@ def classify_image(image):
|
|
56 |
probs = logits_per_image.softmax(dim=1) # Convert logits to probabilities
|
57 |
print(f"Calculated probabilities: {probs}")
|
58 |
|
59 |
-
#
|
60 |
-
safe_prob = probs[0][0].item()
|
61 |
-
unsafe_prob = probs[0][1].item()
|
62 |
|
63 |
-
#
|
|
|
|
|
|
|
|
|
64 |
return {
|
65 |
-
"safe":
|
66 |
-
"unsafe":
|
67 |
}
|
68 |
|
69 |
except Exception as e:
|
|
|
56 |
probs = logits_per_image.softmax(dim=1) # Convert logits to probabilities
|
57 |
print(f"Calculated probabilities: {probs}")
|
58 |
|
59 |
+
# Normalize probabilities to ensure they sum to 100%
|
60 |
+
safe_prob = probs[0][0].item()
|
61 |
+
unsafe_prob = probs[0][1].item()
|
62 |
|
63 |
+
total_prob = safe_prob + unsafe_prob # Sum of probabilities
|
64 |
+
safe_percentage = (safe_prob / total_prob) * 100 # Normalize
|
65 |
+
unsafe_percentage = (unsafe_prob / total_prob) * 100 # Normalize
|
66 |
+
|
67 |
+
# Return results
|
68 |
return {
|
69 |
+
"safe": safe_percentage,
|
70 |
+
"unsafe": unsafe_percentage
|
71 |
}
|
72 |
|
73 |
except Exception as e:
|