Zeyadd-Mostaffa commited on
Commit
6de55da
·
verified ·
1 Parent(s): 4bef339

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +40 -0
  2. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from tensorflow.keras.models import load_model
4
+ from PIL import Image
5
+ import requests
6
+ import h5py
7
+ import os
8
+
9
+ # Download model only if not already present
10
+ model_path = "xception_model.h5"
11
+ if not os.path.exists(model_path):
12
+ url = "https://huggingface.co/Zeyadd-Mostaffa/cv_GP/resolve/main/xception_model.h5"
13
+ with open(model_path, "wb") as f:
14
+ f.write(requests.get(url).content)
15
+
16
+ # Load model
17
+ model = load_model(model_path)
18
+
19
+ # Preprocess function
20
+ def preprocess_image(image):
21
+ image = image.resize((150, 150)).convert("RGB")
22
+ arr = np.array(image) / 255.0
23
+ return np.expand_dims(arr, axis=0)
24
+
25
+ # Prediction function
26
+ def predict(image):
27
+ img = preprocess_image(image)
28
+ prob = model.predict(img)[0][0]
29
+ label = "REAL" if prob >= 0.5 else "FAKE"
30
+ return {"REAL": 1 - prob, "FAKE": prob}, f"Prediction: {label}"
31
+
32
+ # Gradio UI
33
+ demo = gr.Interface(
34
+ fn=predict,
35
+ inputs=gr.Image(type="pil"),
36
+ outputs=[gr.Label(num_top_classes=2), gr.Text()],
37
+ title="Deepfake Detection (Xception Model)"
38
+ )
39
+
40
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ gradio
2
+ tensorflow
3
+ pillow
4
+ numpy
5
+ requests
6
+ h5py