Ron0420 commited on
Commit
9045369
1 Parent(s): bb689a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -19
app.py CHANGED
@@ -15,35 +15,26 @@ zip_ref = zipfile.ZipFile(local_zip, 'r')
15
  zip_ref.extractall('FINAL-EFFICIENTNETV2-B0')
16
  zip_ref.close()
17
 
18
- local_zip = "FINAL-EFFICIENTNETV2-S.zip"
19
- zip_ref = zipfile.ZipFile(local_zip, 'r')
20
- zip_ref.extractall('FINAL-EFFICIENTNETV2-S')
21
- zip_ref.close()
22
-
23
  local_zip = "deepfakes-test-images.zip"
24
  zip_ref = zipfile.ZipFile(local_zip, 'r')
25
  zip_ref.extractall('deepfakes-test-images')
26
  zip_ref.close()
27
 
28
 
29
- model_b0 = tf.keras.models.load_model("FINAL-EFFICIENTNETV2-B0")
30
- model_s = tf.keras.models.load_model("FINAL-EFFICIENTNETV2-S")
31
 
32
  detector = MTCNN()
33
 
34
 
35
- def deepfakespredict(select_model, input_img ):
36
 
37
  model = []
38
  labels = ['real', 'fake']
39
  pred = [0, 0]
40
 
41
- if select_model == "EfficientNetV2-B0":
42
- model = model_b0
43
- elif select_model == "EfficientNetV2-B0":
44
- model = model_s
45
-
46
  text =""
 
47
  face = detector.detect_faces(input_img)
48
 
49
  if len(face) > 0:
@@ -68,13 +59,15 @@ def deepfakespredict(select_model, input_img ):
68
 
69
  else:
70
  text = "Face is not detected in the image."
 
 
71
 
72
- return text, input_img, {labels[i]: float(pred[i]) for i in range(2)}
73
 
74
 
75
  title="EfficientNetV2 Deepfakes Image Detector"
76
  description="This is a demo implementation of EfficientNetV2 Deepfakes Image Detector. To use it, simply upload your image, or click one of the examples to load them."
77
- examples = [ [],[
78
  ['deepfakes-test-images/Fake-1.jpg'],
79
  ['deepfakes-test-images/Fake-2.jpg'],
80
  ['deepfakes-test-images/Fake-3.jpg'],
@@ -86,12 +79,13 @@ examples = [ [],[
86
  ['deepfakes-test-images/Real-3.jpg'],
87
  ['deepfakes-test-images/Real-4.jpg'],
88
  ['deepfakes-test-images/Real-5.jpg']
89
- ]
90
  ]
91
 
92
  gr.Interface(deepfakespredict,
93
- inputs = [gr.inputs.Radio(["EfficientNetV2-B0", "EfficientNetV2-S"], label = "Select model:"), "image"],
94
- outputs=["text", gr.outputs.Image(type="pil", label="Detected face"), gr.outputs.Label(num_top_classes=None, type="auto", label="Confidence")],
95
  title=title,
96
- description=description
 
97
  ).launch()
 
15
  zip_ref.extractall('FINAL-EFFICIENTNETV2-B0')
16
  zip_ref.close()
17
 
 
 
 
 
 
18
  local_zip = "deepfakes-test-images.zip"
19
  zip_ref = zipfile.ZipFile(local_zip, 'r')
20
  zip_ref.extractall('deepfakes-test-images')
21
  zip_ref.close()
22
 
23
 
24
+ model = tf.keras.models.load_model("FINAL-EFFICIENTNETV2-B0")
25
+
26
 
27
  detector = MTCNN()
28
 
29
 
30
+ def deepfakespredict(input_img ):
31
 
32
  model = []
33
  labels = ['real', 'fake']
34
  pred = [0, 0]
35
 
 
 
 
 
 
36
  text =""
37
+ text2 =""
38
  face = detector.detect_faces(input_img)
39
 
40
  if len(face) > 0:
 
59
 
60
  else:
61
  text = "Face is not detected in the image."
62
+
63
+ text2 = "Real: " + str(np.round(pred[0]*100, 2)) + "%, Fake: " + str(np.round(pred[1]*100, 2)) + "%"
64
 
65
+ return input_img, text, text2, {labels[i]: float(pred[i]) for i in range(2)}
66
 
67
 
68
  title="EfficientNetV2 Deepfakes Image Detector"
69
  description="This is a demo implementation of EfficientNetV2 Deepfakes Image Detector. To use it, simply upload your image, or click one of the examples to load them."
70
+ examples = [
71
  ['deepfakes-test-images/Fake-1.jpg'],
72
  ['deepfakes-test-images/Fake-2.jpg'],
73
  ['deepfakes-test-images/Fake-3.jpg'],
 
79
  ['deepfakes-test-images/Real-3.jpg'],
80
  ['deepfakes-test-images/Real-4.jpg'],
81
  ['deepfakes-test-images/Real-5.jpg']
82
+
83
  ]
84
 
85
  gr.Interface(deepfakespredict,
86
+ inputs = ["image"],
87
+ outputs=[gr.outputs.Image(type="pil", label="Detected face"), "text", "text", gr.outputs.Label(num_top_classes=None, type="auto", label="Confidence")],
88
  title=title,
89
+ description=description,
90
+ examples = examples
91
  ).launch()