Coddieharsh commited on
Commit
61752f1
·
1 Parent(s): 157dd34

Simplify app using gr.Interface and use HF default gradio

Browse files
Files changed (2) hide show
  1. app.py +26 -61
  2. requirements.txt +0 -2
app.py CHANGED
@@ -28,7 +28,7 @@ def generate_fft(image):
28
  def predict(image):
29
  """Main prediction function."""
30
  if image is None:
31
- return None, "Please upload an image", None
32
 
33
  try:
34
  img = image.convert('RGB').resize((128, 128))
@@ -44,8 +44,7 @@ def predict(image):
44
  label = "REAL (Authentic)"
45
  confidence = (1 - prediction) * 100
46
 
47
- result_text = f"""
48
- ## Detection Result: {label}
49
 
50
  **Confidence:** {confidence:.2f}%
51
 
@@ -68,68 +67,34 @@ This model is trained on StyleGAN-generated faces and may not accurately detect
68
  return f"Error: {str(e)}", None
69
 
70
 
71
- with gr.Blocks(
 
 
 
 
 
 
 
72
  title="DeepGuard - AI Face Authenticator",
73
- theme=gr.themes.Base(primary_hue="green", secondary_hue="blue", neutral_hue="gray")
74
- ) as demo:
75
-
76
- gr.HTML("""
77
- <div style="text-align: center; margin-bottom: 1rem;">
78
- <h1 style="color: #00f260; font-size: 2.5rem;">DeepGuard</h1>
79
- <p style="color: #888;">AI Face Authenticator - Deepfake Detection</p>
80
- </div>
81
- """)
82
-
83
- with gr.Row():
84
- with gr.Column(scale=1):
85
- input_image = gr.Image(label="Upload Image", type="pil", height=300)
86
- analyze_btn = gr.Button("Analyze Image", variant="primary", size="lg")
87
-
88
- with gr.Row():
89
- with gr.Column(scale=2):
90
- result_output = gr.Markdown(label="Detection Result")
91
- with gr.Column(scale=1):
92
- fft_output = gr.Image(label="FFT Frequency Analysis", height=200)
93
-
94
- with gr.Accordion("How It Works", open=False):
95
- gr.Markdown("""
96
- ### XceptionTransfer Deep Learning Model
97
-
98
- - **Architecture:** Transfer learning with Xception backbone
99
  - **Training Data:** 140,000 real and GAN-generated faces
100
  - **Accuracy:** 88% on test dataset
101
- - **ROC-AUC:** 95%
102
- """)
103
-
104
- with gr.Accordion("FFT Interpretation Guide", open=False):
105
- gr.Markdown("""
106
- | Pattern | Interpretation |
107
- |---------|----------------|
108
- | Bright center spot | Normal low-frequency content |
109
- | Radiating spokes | Edge directions in original image |
110
- | Random noise distribution | Natural texture (real photos) |
111
- | Grid or cross artifacts | Potential GAN fingerprint |
112
-
113
- *GAN artifacts in FFT are subtle and require trained interpretation.*
114
- """)
115
-
116
- with gr.Accordion("Model Limitations", open=False):
117
- gr.Markdown("""
118
- This model is trained on StyleGAN-generated faces only.
119
 
120
- It may NOT accurately detect:
121
- - Stable Diffusion / Midjourney / DALL-E images
122
- - Non-face subjects
123
- - Heavily edited images
124
- """)
125
-
126
- gr.HTML("""<div style="text-align: center; margin-top: 2rem; color: #666;">
127
- Built with TensorFlow and MLflow | DeepGuard MLOps Pipeline
128
- </div>""")
129
-
130
- analyze_btn.click(fn=predict, inputs=input_image, outputs=[result_output, fft_output])
131
- input_image.change(fn=predict, inputs=input_image, outputs=[result_output, fft_output])
132
 
 
 
 
 
 
133
 
134
  if __name__ == "__main__":
135
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
28
  def predict(image):
29
  """Main prediction function."""
30
  if image is None:
31
+ return "Please upload an image", None
32
 
33
  try:
34
  img = image.convert('RGB').resize((128, 128))
 
44
  label = "REAL (Authentic)"
45
  confidence = (1 - prediction) * 100
46
 
47
+ result_text = f"""## Detection Result: {label}
 
48
 
49
  **Confidence:** {confidence:.2f}%
50
 
 
67
  return f"Error: {str(e)}", None
68
 
69
 
70
+ # Simple Interface
71
+ demo = gr.Interface(
72
+ fn=predict,
73
+ inputs=gr.Image(type="pil", label="Upload Face Image"),
74
+ outputs=[
75
+ gr.Markdown(label="Detection Result"),
76
+ gr.Image(label="FFT Frequency Analysis")
77
+ ],
78
  title="DeepGuard - AI Face Authenticator",
79
+ description="Detect AI-generated (deepfake) faces using deep learning. Upload a face image for analysis.",
80
+ article="""
81
+ ### Model Info
82
+ - **Architecture:** XceptionTransfer
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  - **Training Data:** 140,000 real and GAN-generated faces
84
  - **Accuracy:** 88% on test dataset
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
+ ### FFT Interpretation
87
+ | Pattern | Meaning |
88
+ |---------|---------|
89
+ | Bright center | Normal low-frequency content |
90
+ | Radiating spokes | Edge directions in image |
91
+ | Grid artifacts | Potential GAN fingerprint |
 
 
 
 
 
 
92
 
93
+ ### Limitations
94
+ This model is trained on StyleGAN faces only. It may not detect Stable Diffusion, Midjourney, or DALL-E images.
95
+ """,
96
+ allow_flagging="never"
97
+ )
98
 
99
  if __name__ == "__main__":
100
+ demo.launch()
requirements.txt CHANGED
@@ -1,5 +1,3 @@
1
- gradio==4.19.2
2
- huggingface_hub==0.20.3
3
  tensorflow==2.17.0
4
  numpy>=1.24.0
5
  Pillow>=10.0.0
 
 
 
1
  tensorflow==2.17.0
2
  numpy>=1.24.0
3
  Pillow>=10.0.0