Ron0420 commited on
Commit
352aacf
1 Parent(s): 2d19539

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -14
app.py CHANGED
@@ -15,14 +15,28 @@ zip_ref = zipfile.ZipFile(local_zip, 'r')
15
  zip_ref.extractall('FINAL-EFFICIENTNETV2-B0')
16
  zip_ref.close()
17
 
18
- def deepfakespredict(input_img):
 
 
 
 
 
 
 
 
19
 
20
- detector = MTCNN()
21
- model = tf.keras.models.load_model("FINAL-EFFICIENTNETV2-B0")
22
-
23
- face = detector.detect_faces(input_img)
24
 
 
 
 
 
 
 
 
 
 
25
  text =""
 
26
 
27
  if len(face) > 0:
28
  x, y, width, height = face[0]['box']
@@ -43,24 +57,19 @@ def deepfakespredict(input_img):
43
  text = "The image is real."
44
  else:
45
  text = "The image might be real or fake."
46
-
47
- # if pred[1] >= 0.5:
48
- # text = "The image is fake."
49
- # else:
50
- # text = "The image is real."
51
-
52
  else:
53
  text = "Face is not detected in the image."
54
 
55
- return pred, text, input_img
56
 
57
 
58
  title="EfficientNetV2 Deepfakes Image Detector"
59
  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."
60
  examples = []
61
  gr.Interface(deepfakespredict,
62
- inputs = ["image"],
63
- outputs=["text","text","image"],
64
  title=title,
65
  description=description
66
 
 
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
+ model_b0 = tf.keras.models.load_model("FINAL-EFFICIENTNETV2-B0")
24
+ model_s = tf.keras.models.load_model("FINAL-EFFICIENTNETV2-S")
25
+
26
+ detector = MTCNN()
27
 
 
 
 
 
28
 
29
+ def deepfakespredict(input_img, select_model):
30
+
31
+ tf.keras.backend.clear_session()
32
+
33
+ if select_model = "EfficientNetV2-B0":
34
+ model = model_b0
35
+ elif select_model = "EfficientNetV2-B0":
36
+ model = model_s
37
+
38
  text =""
39
+ face = detector.detect_faces(input_img)
40
 
41
  if len(face) > 0:
42
  x, y, width, height = face[0]['box']
 
57
  text = "The image is real."
58
  else:
59
  text = "The image might be real or fake."
60
+
 
 
 
 
 
61
  else:
62
  text = "Face is not detected in the image."
63
 
64
+ return text, input_img, {labels[i]: float(pred[i]) for i in range(2)}
65
 
66
 
67
  title="EfficientNetV2 Deepfakes Image Detector"
68
  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."
69
  examples = []
70
  gr.Interface(deepfakespredict,
71
+ inputs = [gr.inputs.Radio(["EfficientNetV2-B0", "EfficientNetV2-S"], label = "Select model:"), "image"],
72
+ outputs=["text", gr.outputs.Image(type="pil", label="Detected face"), gr.outputs.Label(num_top_classes=None, type="auto", label="Confidence")],
73
  title=title,
74
  description=description
75