Zell commited on
Commit
9f9b2fc
·
1 Parent(s): a30ac58

Initial Commit

Browse files
Files changed (2) hide show
  1. app..py +39 -0
  2. requirements.txt +2 -0
app..py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+
5
+ # 1. Load your model
6
+ model = tf.keras.models.load_model("face_forgery_detector.keras")
7
+
8
+ # 2. Define your inference function
9
+ def detect_forgery(image):
10
+ # Preprocess the image to match your model’s input requirements
11
+ img = tf.image.resize(image, (160, 160)) # Example size; adjust for your model
12
+ img = tf.expand_dims(img, axis=0)
13
+ img = img / 255.0 # Example normalization; adapt as needed
14
+
15
+ # Run inference
16
+ predictions = model.predict(img)[0] # e.g., [Real_prob, Fake_prob]
17
+ # Suppose predictions = [prob_real, prob_fake]
18
+ prob_real = predictions[0]
19
+ prob_fake = predictions[1]
20
+
21
+ # Format output
22
+ # You can return a dictionary or a string. For example:
23
+ if prob_fake > prob_real:
24
+ return f"Forged (Fake) with confidence {prob_fake:.2f}"
25
+ else:
26
+ return f"Real with confidence {prob_real:.2f}"
27
+
28
+ # 3. Build your Gradio interface
29
+ demo = gr.Interface(
30
+ fn=detect_forgery,
31
+ inputs=gr.Image(type="numpy"), # 'type="numpy"' gives a NumPy array
32
+ outputs="text",
33
+ title="Face Forgery Detector",
34
+ description="Upload a face image to check if it's likely forged or real."
35
+ )
36
+
37
+ # 4. Launch the app (Gradio handles the rest)
38
+ if __name__ == "__main__":
39
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ tensorflow==2.11.0
2
+ gradio==3.25.0