NizamuddinMandekar commited on
Commit
03e846b
Β·
verified Β·
1 Parent(s): 193d822

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +321 -79
app.py CHANGED
@@ -44,118 +44,340 @@ def predict(img) -> Tuple[Dict, float]:
44
  return pred_labels_and_probs, pred_time
45
 
46
  ### 4. Enhanced Gradio app ###
47
- # Custom CSS for modern, compact styling
48
  custom_css = """
49
- #main-container {
50
- max-width: 900px !important;
51
- margin: 0 auto;
52
- padding: 20px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  }
54
 
55
  .gradio-container {
56
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
57
  min-height: 100vh;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  }
59
 
60
  #title {
61
  text-align: center;
62
- color: white;
63
- font-size: 2.5em;
64
- font-weight: bold;
 
 
 
65
  margin-bottom: 10px;
66
- text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
 
 
 
 
 
 
67
  }
68
 
69
  #subtitle {
70
  text-align: center;
71
- color: rgba(255,255,255,0.9);
72
- font-size: 1.2em;
73
- margin-bottom: 30px;
 
 
 
74
  }
75
 
76
- .input-output-container {
77
- background: rgba(255,255,255,0.95);
78
- border-radius: 20px;
79
- padding: 30px;
80
- box-shadow: 0 10px 30px rgba(0,0,0,0.2);
81
- backdrop-filter: blur(10px);
82
  }
83
 
84
- .output-container {
85
- background: rgba(255,255,255,0.9);
86
- border-radius: 15px;
87
- padding: 20px;
88
- margin-top: 20px;
 
 
 
 
 
 
89
  }
90
 
91
- #upload-button {
92
- background: linear-gradient(45deg, #4CAF50, #45a049);
93
- border: none;
94
- border-radius: 10px;
95
- padding: 15px 30px;
 
96
  color: white;
97
- font-weight: bold;
98
- cursor: pointer;
99
- transition: all 0.3s ease;
 
 
100
  }
101
 
102
- #upload-button:hover {
103
- transform: translateY(-2px);
104
- box-shadow: 0 5px 15px rgba(0,0,0,0.2);
 
 
 
 
 
 
105
  }
106
 
107
- .examples-container {
108
- margin-top: 30px;
109
- background: rgba(255,255,255,0.1);
110
- border-radius: 15px;
111
- padding: 20px;
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  }
113
 
114
  .guide-box {
115
- background: rgba(255,255,255,0.95);
116
- border-radius: 15px;
117
- padding: 25px;
118
- margin: 20px 0;
119
- box-shadow: 0 5px 15px rgba(0,0,0,0.1);
 
 
 
 
 
120
  }
121
 
122
- .guide-box h3 {
123
- color: #333;
124
- margin-bottom: 15px;
125
- display: flex;
126
- align-items: center;
127
- gap: 10px;
128
  }
129
 
130
- .guide-box ul, .guide-box ol {
131
- color: #555;
132
- line-height: 1.6;
 
 
 
 
 
 
 
133
  }
134
 
135
- .stats-container {
136
- display: flex;
137
- justify-content: space-around;
138
- margin: 20px 0;
139
- text-align: center;
140
  }
141
 
142
- .stat-item {
143
- background: rgba(255,255,255,0.2);
144
- border-radius: 10px;
145
- padding: 15px;
146
  color: white;
 
 
 
 
147
  }
148
 
149
- .stat-number {
150
- font-size: 2em;
151
- font-weight: bold;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  }
153
 
154
  .footer {
155
  text-align: center;
156
  color: rgba(255,255,255,0.8);
157
- margin-top: 30px;
158
- padding: 20px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  }
160
  """
161
 
@@ -169,24 +391,29 @@ description = """
169
  <div class="stats-container">
170
  <div class="stat-item">
171
  <div class="stat-number">95%</div>
172
- <div>Accuracy</div>
173
  </div>
174
  <div class="stat-item">
175
- <div class="stat-number"><1s</div>
176
- <div>Processing</div>
177
  </div>
178
  <div class="stat-item">
179
- <div class="stat-number">AI</div>
180
- <div>Powered</div>
 
 
 
 
181
  </div>
182
  </div>
183
 
184
  <div class="guide-box">
185
- <h3>🎯 Quick Guide</h3>
186
  <ul>
187
- <li><strong>πŸ“Έ Focus on Faces:</strong> Upload clear images with visible faces</li>
188
- <li><strong>⚑ Instant Results:</strong> Get real-time classification with confidence scores</li>
189
- <li><strong>πŸŽͺ Try Examples:</strong> Use sample images below to test the model</li>
 
190
  </ul>
191
  </div>
192
  </div>
@@ -202,7 +429,7 @@ except:
202
  with gr.Blocks(css=custom_css, title="Reality Check - AI Face Detector") as demo:
203
  gr.HTML(description)
204
 
205
- with gr.Row():
206
  with gr.Column(scale=1):
207
  input_image = gr.Image(
208
  type="pil",
@@ -228,6 +455,18 @@ with gr.Blocks(css=custom_css, title="Reality Check - AI Face Detector") as demo
228
  label="⚑ Processing Time (seconds)",
229
  show_label=True
230
  )
 
 
 
 
 
 
 
 
 
 
 
 
231
 
232
  # Submit button
233
  submit_btn = gr.Button(
@@ -254,7 +493,10 @@ with gr.Blocks(css=custom_css, title="Reality Check - AI Face Detector") as demo
254
  # Footer
255
  gr.HTML("""
256
  <div class="footer">
257
- <p>πŸš€ Created with ❀️ | Powered by AI | Real Or Fake Detection</p>
 
 
 
258
  </div>
259
  """)
260
 
 
44
  return pred_labels_and_probs, pred_time
45
 
46
  ### 4. Enhanced Gradio app ###
47
+ # Custom CSS for ultra-modern, attractive styling
48
  custom_css = """
49
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
50
+
51
+ * {
52
+ font-family: 'Inter', sans-serif;
53
+ }
54
+
55
+ body {
56
+ background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
57
+ background-size: 400% 400%;
58
+ animation: gradientBG 15s ease infinite;
59
+ margin: 0;
60
+ padding: 0;
61
+ }
62
+
63
+ @keyframes gradientBG {
64
+ 0% { background-position: 0% 50%; }
65
+ 50% { background-position: 100% 50%; }
66
+ 100% { background-position: 0% 50%; }
67
  }
68
 
69
  .gradio-container {
70
+ background: transparent !important;
71
  min-height: 100vh;
72
+ position: relative;
73
+ overflow-x: hidden;
74
+ }
75
+
76
+ .gradio-container::before {
77
+ content: '';
78
+ position: fixed;
79
+ top: 0;
80
+ left: 0;
81
+ right: 0;
82
+ bottom: 0;
83
+ background:
84
+ radial-gradient(circle at 20% 50%, rgba(120, 119, 198, 0.3) 0%, transparent 50%),
85
+ radial-gradient(circle at 80% 20%, rgba(255, 119, 198, 0.3) 0%, transparent 50%),
86
+ radial-gradient(circle at 40% 80%, rgba(120, 219, 255, 0.3) 0%, transparent 50%);
87
+ pointer-events: none;
88
+ z-index: -1;
89
+ }
90
+
91
+ #main-container {
92
+ max-width: 1200px !important;
93
+ margin: 0 auto;
94
+ padding: 20px;
95
+ position: relative;
96
+ z-index: 1;
97
  }
98
 
99
  #title {
100
  text-align: center;
101
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
102
+ -webkit-background-clip: text;
103
+ -webkit-text-fill-color: transparent;
104
+ background-clip: text;
105
+ font-size: 4em;
106
+ font-weight: 700;
107
  margin-bottom: 10px;
108
+ text-shadow: 0 0 30px rgba(102, 126, 234, 0.5);
109
+ animation: titleGlow 3s ease-in-out infinite alternate;
110
+ }
111
+
112
+ @keyframes titleGlow {
113
+ from { filter: drop-shadow(0 0 20px rgba(102, 126, 234, 0.3)); }
114
+ to { filter: drop-shadow(0 0 40px rgba(102, 126, 234, 0.8)); }
115
  }
116
 
117
  #subtitle {
118
  text-align: center;
119
+ color: rgba(255,255,255,0.95);
120
+ font-size: 1.4em;
121
+ font-weight: 300;
122
+ margin-bottom: 40px;
123
+ text-shadow: 0 2px 10px rgba(0,0,0,0.4);
124
+ animation: fadeInUp 1s ease-out;
125
  }
126
 
127
+ @keyframes fadeInUp {
128
+ from { opacity: 0; transform: translateY(30px); }
129
+ to { opacity: 1; transform: translateY(0); }
 
 
 
130
  }
131
 
132
+ .stats-container {
133
+ display: flex;
134
+ justify-content: space-around;
135
+ margin: 40px 0;
136
+ gap: 20px;
137
+ animation: slideInUp 1.2s ease-out;
138
+ }
139
+
140
+ @keyframes slideInUp {
141
+ from { opacity: 0; transform: translateY(50px); }
142
+ to { opacity: 1; transform: translateY(0); }
143
  }
144
 
145
+ .stat-item {
146
+ background: rgba(255,255,255,0.15);
147
+ backdrop-filter: blur(20px);
148
+ border: 1px solid rgba(255,255,255,0.2);
149
+ border-radius: 20px;
150
+ padding: 25px 20px;
151
  color: white;
152
+ text-align: center;
153
+ flex: 1;
154
+ transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
155
+ position: relative;
156
+ overflow: hidden;
157
  }
158
 
159
+ .stat-item::before {
160
+ content: '';
161
+ position: absolute;
162
+ top: 0;
163
+ left: -100%;
164
+ width: 100%;
165
+ height: 100%;
166
+ background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
167
+ transition: left 0.8s;
168
  }
169
 
170
+ .stat-item:hover::before {
171
+ left: 100%;
172
+ }
173
+
174
+ .stat-item:hover {
175
+ transform: translateY(-10px) scale(1.05);
176
+ box-shadow: 0 20px 40px rgba(0,0,0,0.3);
177
+ background: rgba(255,255,255,0.25);
178
+ }
179
+
180
+ .stat-number {
181
+ font-size: 2.5em;
182
+ font-weight: 700;
183
+ background: linear-gradient(135deg, #fff, #e0e0e0);
184
+ -webkit-background-clip: text;
185
+ -webkit-text-fill-color: transparent;
186
+ background-clip: text;
187
+ margin-bottom: 5px;
188
  }
189
 
190
  .guide-box {
191
+ background: rgba(255,255,255,0.12);
192
+ backdrop-filter: blur(20px);
193
+ border: 1px solid rgba(255,255,255,0.2);
194
+ border-radius: 25px;
195
+ padding: 35px;
196
+ margin: 30px 0;
197
+ box-shadow: 0 15px 35px rgba(0,0,0,0.1);
198
+ animation: floatIn 1.5s ease-out;
199
+ position: relative;
200
+ overflow: hidden;
201
  }
202
 
203
+ @keyframes floatIn {
204
+ from { opacity: 0; transform: translateY(30px) scale(0.95); }
205
+ to { opacity: 1; transform: translateY(0) scale(1); }
 
 
 
206
  }
207
 
208
+ .guide-box::before {
209
+ content: '';
210
+ position: absolute;
211
+ top: -50%;
212
+ left: -50%;
213
+ width: 200%;
214
+ height: 200%;
215
+ background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
216
+ animation: rotate 20s linear infinite;
217
+ pointer-events: none;
218
  }
219
 
220
+ @keyframes rotate {
221
+ from { transform: rotate(0deg); }
222
+ to { transform: rotate(360deg); }
 
 
223
  }
224
 
225
+ .guide-box h3 {
 
 
 
226
  color: white;
227
+ margin-bottom: 20px;
228
+ font-size: 1.5em;
229
+ font-weight: 600;
230
+ text-shadow: 0 2px 10px rgba(0,0,0,0.3);
231
  }
232
 
233
+ .guide-box ul {
234
+ color: rgba(255,255,255,0.9);
235
+ line-height: 1.8;
236
+ font-size: 1.1em;
237
+ }
238
+
239
+ .guide-box li {
240
+ margin-bottom: 12px;
241
+ transition: transform 0.2s ease;
242
+ }
243
+
244
+ .guide-box li:hover {
245
+ transform: translateX(10px);
246
+ }
247
+
248
+ .main-interface {
249
+ background: rgba(255,255,255,0.08);
250
+ backdrop-filter: blur(25px);
251
+ border: 1px solid rgba(255,255,255,0.15);
252
+ border-radius: 30px;
253
+ padding: 40px;
254
+ margin: 40px 0;
255
+ box-shadow: 0 25px 50px rgba(0,0,0,0.2);
256
+ animation: materialIn 1.8s ease-out;
257
+ }
258
+
259
+ @keyframes materialIn {
260
+ from { opacity: 0; transform: scale(0.9) translateY(50px); }
261
+ to { opacity: 1; transform: scale(1) translateY(0); }
262
+ }
263
+
264
+ .gr-button {
265
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
266
+ border: none !important;
267
+ border-radius: 15px !important;
268
+ padding: 15px 40px !important;
269
+ color: white !important;
270
+ font-weight: 600 !important;
271
+ font-size: 1.1em !important;
272
+ cursor: pointer !important;
273
+ transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1) !important;
274
+ box-shadow: 0 10px 25px rgba(102, 126, 234, 0.3) !important;
275
+ position: relative !important;
276
+ overflow: hidden !important;
277
+ }
278
+
279
+ .gr-button::before {
280
+ content: '';
281
+ position: absolute;
282
+ top: 0;
283
+ left: -100%;
284
+ width: 100%;
285
+ height: 100%;
286
+ background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
287
+ transition: left 0.6s;
288
+ }
289
+
290
+ .gr-button:hover::before {
291
+ left: 100%;
292
+ }
293
+
294
+ .gr-button:hover {
295
+ transform: translateY(-3px) !important;
296
+ box-shadow: 0 15px 35px rgba(102, 126, 234, 0.4) !important;
297
+ background: linear-gradient(135deg, #5a6fd8 0%, #6a4c93 100%) !important;
298
+ }
299
+
300
+ .gr-button:active {
301
+ transform: translateY(0px) !important;
302
+ }
303
+
304
+ .gr-form {
305
+ background: rgba(255,255,255,0.05) !important;
306
+ backdrop-filter: blur(15px) !important;
307
+ border: 1px solid rgba(255,255,255,0.1) !important;
308
+ border-radius: 20px !important;
309
+ padding: 25px !important;
310
+ }
311
+
312
+ .gr-input, .gr-textbox, .gr-dropdown {
313
+ background: rgba(255,255,255,0.1) !important;
314
+ border: 1px solid rgba(255,255,255,0.2) !important;
315
+ border-radius: 12px !important;
316
+ color: white !important;
317
+ backdrop-filter: blur(10px) !important;
318
+ }
319
+
320
+ .gr-input:focus, .gr-textbox:focus {
321
+ border-color: #667eea !important;
322
+ box-shadow: 0 0 20px rgba(102, 126, 234, 0.3) !important;
323
  }
324
 
325
  .footer {
326
  text-align: center;
327
  color: rgba(255,255,255,0.8);
328
+ margin-top: 50px;
329
+ padding: 30px;
330
+ font-size: 1.1em;
331
+ animation: fadeIn 2s ease-out;
332
+ }
333
+
334
+ @keyframes fadeIn {
335
+ from { opacity: 0; }
336
+ to { opacity: 1; }
337
+ }
338
+
339
+ .footer::before {
340
+ content: '✨';
341
+ display: inline-block;
342
+ margin-right: 10px;
343
+ animation: sparkle 2s ease-in-out infinite;
344
+ }
345
+
346
+ @keyframes sparkle {
347
+ 0%, 100% { transform: scale(1) rotate(0deg); }
348
+ 50% { transform: scale(1.2) rotate(180deg); }
349
+ }
350
+
351
+ /* Responsive Design */
352
+ @media (max-width: 768px) {
353
+ #title { font-size: 2.5em; }
354
+ .stats-container { flex-direction: column; gap: 15px; }
355
+ .main-interface { padding: 25px; margin: 20px 0; }
356
+ .guide-box { padding: 25px; }
357
+ }
358
+
359
+ /* Loading Animation */
360
+ .loading {
361
+ position: relative;
362
+ }
363
+
364
+ .loading::after {
365
+ content: '';
366
+ position: absolute;
367
+ top: 50%;
368
+ left: 50%;
369
+ width: 20px;
370
+ height: 20px;
371
+ border: 2px solid rgba(255,255,255,0.3);
372
+ border-top: 2px solid white;
373
+ border-radius: 50%;
374
+ animation: spin 1s linear infinite;
375
+ transform: translate(-50%, -50%);
376
+ }
377
+
378
+ @keyframes spin {
379
+ 0% { transform: translate(-50%, -50%) rotate(0deg); }
380
+ 100% { transform: translate(-50%, -50%) rotate(360deg); }
381
  }
382
  """
383
 
 
391
  <div class="stats-container">
392
  <div class="stat-item">
393
  <div class="stat-number">95%</div>
394
+ <div>Accuracy Rate</div>
395
  </div>
396
  <div class="stat-item">
397
+ <div class="stat-number">&lt;1s</div>
398
+ <div>Lightning Fast</div>
399
  </div>
400
  <div class="stat-item">
401
+ <div class="stat-number">πŸ€–</div>
402
+ <div>AI Powered</div>
403
+ </div>
404
+ <div class="stat-item">
405
+ <div class="stat-number">∞</div>
406
+ <div>Unlimited Use</div>
407
  </div>
408
  </div>
409
 
410
  <div class="guide-box">
411
+ <h3>πŸš€ How It Works</h3>
412
  <ul>
413
+ <li><strong>🎯 Advanced AI Detection:</strong> Our neural network analyzes facial features, textures, and patterns to detect AI-generated content</li>
414
+ <li><strong>πŸ“Έ Simply Upload:</strong> Drag & drop or click to upload any face image - supports JPG, PNG, WebP formats</li>
415
+ <li><strong>⚑ Real-time Analysis:</strong> Get instant results with confidence scores and processing time</li>
416
+ <li><strong>πŸ”’ Privacy First:</strong> Your images are processed securely and never stored on our servers</li>
417
  </ul>
418
  </div>
419
  </div>
 
429
  with gr.Blocks(css=custom_css, title="Reality Check - AI Face Detector") as demo:
430
  gr.HTML(description)
431
 
432
+ with gr.Row(elem_classes="main-interface"):
433
  with gr.Column(scale=1):
434
  input_image = gr.Image(
435
  type="pil",
 
455
  label="⚑ Processing Time (seconds)",
456
  show_label=True
457
  )
458
+
459
+ # Additional info section
460
+ gr.HTML("""
461
+ <div style="margin-top: 20px; padding: 20px; background: rgba(255,255,255,0.1); border-radius: 15px; backdrop-filter: blur(10px);">
462
+ <h4 style="color: white; margin-bottom: 15px;">πŸ” Detection Insights</h4>
463
+ <div style="color: rgba(255,255,255,0.9); font-size: 0.9em; line-height: 1.6;">
464
+ β€’ <strong>Real faces</strong> show natural imperfections and organic patterns<br>
465
+ β€’ <strong>AI faces</strong> often have subtle artifacts in eyes, teeth, or background<br>
466
+ β€’ Higher confidence scores indicate more certain predictions
467
+ </div>
468
+ </div>
469
+ """)
470
 
471
  # Submit button
472
  submit_btn = gr.Button(
 
493
  # Footer
494
  gr.HTML("""
495
  <div class="footer">
496
+ <p>πŸš€ Powered by Advanced AI Technology | πŸ”’ Privacy-First Design | ⚑ Lightning Fast Results</p>
497
+ <div style="margin-top: 15px; font-size: 0.9em; opacity: 0.8;">
498
+ Built with ❀️ for the AI community | Real Or Fake Detection System
499
+ </div>
500
  </div>
501
  """)
502