Dileep7729 commited on
Commit
a2a2ce4
·
verified ·
1 Parent(s): 45892bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
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
- # Extract probabilities for each category
60
- safe_prob = probs[0][0].item() * 100 # Safe percentage
61
- unsafe_prob = probs[0][1].item() * 100 # Unsafe percentage
62
 
63
- # Format data for visualization
 
 
 
 
64
  return {
65
- "safe": safe_prob,
66
- "unsafe": unsafe_prob
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: