TKM03 commited on
Commit
0dc044a
·
verified ·
1 Parent(s): 79ee477

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -29,8 +29,8 @@ def detect(image, confidence_threshold=0.5):
29
  logits = outputs.logits
30
  probabilities = torch.softmax(logits, dim=1)[0]
31
 
32
- confidence_real = probabilities[0].item() * 100
33
- confidence_fake = probabilities[1].item() * 100
34
 
35
  id2label = model.config.id2label
36
  predicted_class = torch.argmax(logits, dim=1).item()
@@ -38,17 +38,21 @@ def detect(image, confidence_threshold=0.5):
38
  threshold_predicted = "Fake" if confidence_fake / 100 >= confidence_threshold else "Real"
39
  confidence_score = max(confidence_real, confidence_fake)
40
 
41
- # Differentiate outputs (example heuristic)
 
 
 
 
42
  overall = f"{confidence_score:.1f}% Confidence ({threshold_predicted})"
43
- aigen = f"{confidence_fake * 0.9:.1f}% (AI-Generated Content Likelihood)" # Arbitrary scaling
44
- deepfake = f"{confidence_fake:.1f}% (Face Manipulation Likelihood)"
45
 
46
  return overall, aigen, deepfake
47
 
48
  except Exception as e:
49
  logger.error(f"Error during analysis: {str(e)}")
50
  raise gr.Error(f"Analysis error: {str(e)}")
51
- # Custom CSS (unchanged)
52
  custom_css = """
53
  .container {
54
  max-width: 1200px;
@@ -91,6 +95,11 @@ MARKDOWN0 = """
91
  <h1>DeepFake Detection System</h1>
92
  <p>Advanced AI-powered analysis for identifying manipulated media<br>
93
  Powered by prithivMLmods/Deep-Fake-Detector-Model (Updated Jan 2025)<br>
 
 
 
 
 
94
  Adjust threshold to tune sensitivity; check logs for detailed output</p>
95
  </div>
96
  """
 
29
  logits = outputs.logits
30
  probabilities = torch.softmax(logits, dim=1)[0]
31
 
32
+ confidence_real = probabilities[0].item() * 100 # Probability of being Real
33
+ confidence_fake = probabilities[1].item() * 100 # Probability of being Fake
34
 
35
  id2label = model.config.id2label
36
  predicted_class = torch.argmax(logits, dim=1).item()
 
38
  threshold_predicted = "Fake" if confidence_fake / 100 >= confidence_threshold else "Real"
39
  confidence_score = max(confidence_real, confidence_fake)
40
 
41
+ # Use raw probabilities for clarity, with optional fine-tuning for specific categories
42
+ aigen_likelihood = confidence_fake # Assuming AI-Generated is synonymous with Fake for simplicity
43
+ face_manipulation_likelihood = confidence_fake # You might want to refine this with additional analysis
44
+
45
+ # Format outputs
46
  overall = f"{confidence_score:.1f}% Confidence ({threshold_predicted})"
47
+ aigen = f"{aigen_likelihood:.1f}% (AI-Generated Content Likelihood)"
48
+ deepfake = f"{face_manipulation_likelihood:.1f}% (Face Manipulation Likelihood)"
49
 
50
  return overall, aigen, deepfake
51
 
52
  except Exception as e:
53
  logger.error(f"Error during analysis: {str(e)}")
54
  raise gr.Error(f"Analysis error: {str(e)}")
55
+
56
  custom_css = """
57
  .container {
58
  max-width: 1200px;
 
95
  <h1>DeepFake Detection System</h1>
96
  <p>Advanced AI-powered analysis for identifying manipulated media<br>
97
  Powered by prithivMLmods/Deep-Fake-Detector-Model (Updated Jan 2025)<br>
98
+ <ul>
99
+ <li><strong>Confidence Score:</strong> Overall probability the image is Real or Fake (based on threshold).</li>
100
+ <li><strong>AI-Generated Content Likelihood:</strong> Probability the image was fully generated by AI.</li>
101
+ <li><strong>Face Manipulation Likelihood:</strong> Probability the image contains manipulated faces (e.g., swaps or alterations).</li>
102
+ </ul>
103
  Adjust threshold to tune sensitivity; check logs for detailed output</p>
104
  </div>
105
  """