LPX55 commited on
Commit
387e421
·
verified ·
1 Parent(s): d7d030d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -2
app.py CHANGED
@@ -36,12 +36,16 @@ model_4 = AutoModelForImageClassification.from_pretrained(models[1]).to(device)
36
  model_5_path = "prithivMLmods/Deep-Fake-Detector-v2-Model"
37
  clf_5 = pipeline("image-classification", model=model_5_path, device=device)
38
 
 
 
 
39
  # Define class names for all models
40
  class_names_1 = ['artificial', 'real']
41
  class_names_2 = ['AI Image', 'Real Image']
42
  labels_3 = ['AI', 'Real']
43
  labels_4 = ['AI', 'Real']
44
  class_names_5 = ['Realism', 'Deepfake']
 
45
 
46
  def softmax(vector):
47
  e = np.exp(vector - np.max(vector)) # for numerical stability
@@ -223,6 +227,30 @@ def predict_image(img, confidence_threshold):
223
 
224
  print(result_5output)
225
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
 
227
  # try:
228
  # result_5output = [5, 'TBA', 0.0, 0.0, 'MAINTENANCE']
@@ -245,11 +273,12 @@ def predict_image(img, confidence_threshold):
245
  "ViT/AI-vs-Real": label_2,
246
  "Swin/SDXL": label_3,
247
  "Swin/SDXL-FLUX": label_4,
248
- "prithivMLmods": label_5
 
249
  }
250
  # Generate HTML content
251
 
252
- combined_outputs = [ result_1output, result_2output, result_3output, result_4output, result_5output ]
253
  # html_content = generate_results_html(combined_outputs)
254
 
255
  return img_pil, combined_outputs
@@ -488,6 +517,7 @@ def generate_results_html(results):
488
  <h4 class="mt-4 text-sm font-semibold tracking-wide">Vits Model</h4>
489
 
490
  <div class="text-xs font-mono">Real: {results[4][2]:.4f}, AI: {results[4][3]:.4f}</div>
 
491
 
492
  <a class="mt-2 text-xs tracking-wide">@prithivMLmods / more info</a>
493
  </div>
 
36
  model_5_path = "prithivMLmods/Deep-Fake-Detector-v2-Model"
37
  clf_5 = pipeline("image-classification", model=model_5_path, device=device)
38
 
39
+ model_5b_path = "prithivMLmods/Deepfake-Detection-Exp-02-22"
40
+ clf_5b = pipeline("image-classification", model=model_5b_path, device=device)
41
+
42
  # Define class names for all models
43
  class_names_1 = ['artificial', 'real']
44
  class_names_2 = ['AI Image', 'Real Image']
45
  labels_3 = ['AI', 'Real']
46
  labels_4 = ['AI', 'Real']
47
  class_names_5 = ['Realism', 'Deepfake']
48
+ class_names_5b = ['Real', 'Deepfake']
49
 
50
  def softmax(vector):
51
  e = np.exp(vector - np.max(vector)) # for numerical stability
 
227
 
228
  print(result_5output)
229
 
230
+ try:
231
+ prediction_5b = clf_5b(img_pilvits)
232
+ result_5b = {pred['label']: pred['score'] for pred in prediction_5b}
233
+ result_5boutput = [6, 'ViT-base Newcomer', result_5b['Real'], result_5b['Deepfake']]
234
+
235
+ # Ensure the result dictionary contains all class names
236
+ for class_name in class_names_5b:
237
+ if class_name not in result_5b:
238
+ result_5b[class_name] = 0.0
239
+ # Check if either class meets the confidence threshold
240
+ if result_5b['Deepfake'] >= confidence_threshold:
241
+ label_5b = f"AI, Confidence: {result_5b['Deepfake']:.4f}"
242
+ result_5boutput += ['AI']
243
+ elif result_5b['Real Image'] >= confidence_threshold:
244
+ label_5b = f"Real, Confidence: {result_5b['Real']:.4f}"
245
+ result_5boutput += ['REAL']
246
+ else:
247
+ label_5b = "Uncertain Classification"
248
+ result_5boutput += ['UNCERTAIN']
249
+ except Exception as e:
250
+ label_5b = f"Error: {str(e)}"
251
+
252
+ print(result_5boutput)
253
+
254
 
255
  # try:
256
  # result_5output = [5, 'TBA', 0.0, 0.0, 'MAINTENANCE']
 
273
  "ViT/AI-vs-Real": label_2,
274
  "Swin/SDXL": label_3,
275
  "Swin/SDXL-FLUX": label_4,
276
+ "prithivMLmods": label_5,
277
+ "prithivMLmods-2-22": label_5b
278
  }
279
  # Generate HTML content
280
 
281
+ combined_outputs = [ result_1output, result_2output, result_3output, result_4output, result_5output, result_5boutput ]
282
  # html_content = generate_results_html(combined_outputs)
283
 
284
  return img_pil, combined_outputs
 
517
  <h4 class="mt-4 text-sm font-semibold tracking-wide">Vits Model</h4>
518
 
519
  <div class="text-xs font-mono">Real: {results[4][2]:.4f}, AI: {results[4][3]:.4f}</div>
520
+ <div class="text-xs font-mono">Real: {results[5][2]:.4f}, AI: {results[5][3]:.4f}</div>
521
 
522
  <a class="mt-2 text-xs tracking-wide">@prithivMLmods / more info</a>
523
  </div>