Jonny001 commited on
Commit
6638222
Β·
verified Β·
1 Parent(s): e474f3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +173 -97
app.py CHANGED
@@ -50,72 +50,90 @@ def swap_face_image(source_file, target_file, doFaceEnhancer):
50
  # Return output image
51
  return Image.open(output_path)
52
 
53
- # Custom CSS for professional dark theme and online indicator
54
  custom_css = """
55
  :root {
56
- --primary: #6366f1;
57
- --primary-dark: #4f46e5;
58
- --secondary: #1f2937;
59
- --secondary-dark: #111827;
60
- --text: #f3f4f6;
61
- --text-muted: #9ca3af;
62
- --success: #10b981;
63
  }
64
 
65
  body {
66
- background-color: var(--secondary-dark);
67
- color: var(--text);
 
68
  }
69
 
70
  .gr-block {
71
- background-color: var(--secondary) !important;
72
- border-radius: 8px !important;
73
- border: 1px solid #374151 !important;
 
74
  }
75
 
76
  .gr-box {
77
- border-color: #374151 !important;
78
- color: var(--text) !important;
 
79
  }
80
 
81
  h1, h2, h3, label, .gr-label {
82
- color: var(--text) !important;
 
83
  }
84
 
85
  .gr-button {
86
- background: linear-gradient(to right, var(--primary), var(--primary-dark)) !important;
87
- color: white !important;
88
  border: none !important;
89
- border-radius: 6px !important;
90
- padding: 10px 20px !important;
91
- font-weight: 500 !important;
 
 
 
 
92
  }
93
 
94
  .gr-button:not(:disabled):hover {
95
- opacity: 0.9;
96
- transform: translateY(-1px);
97
- box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
98
  }
99
 
100
  .gr-button:disabled {
101
  background: #4b5563 !important;
 
102
  }
103
 
104
  .status-indicator {
105
  display: inline-block;
106
- width: 10px;
107
- height: 10px;
108
  border-radius: 50%;
109
- margin-right: 8px;
 
 
 
110
  }
111
 
112
- .status-online {
113
- background-color: var(--success);
114
- box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
 
 
 
 
 
 
 
115
  }
116
 
117
  .status-text {
118
- color: var(--text-muted);
119
  font-size: 0.9rem;
120
  display: flex;
121
  align-items: center;
@@ -125,31 +143,39 @@ h1, h2, h3, label, .gr-label {
125
  display: flex;
126
  justify-content: space-between;
127
  align-items: center;
128
- margin-bottom: 1.5rem;
129
- padding-bottom: 1rem;
130
- border-bottom: 1px solid #374151;
 
 
 
131
  }
132
 
133
  .title-section h1 {
134
  margin-bottom: 0.25rem;
135
- font-weight: 700;
 
 
 
 
136
  }
137
 
138
  .title-section p {
139
- color: var(--text-muted);
140
  margin: 0;
141
  }
142
 
143
  .instructions {
144
- background: linear-gradient(to right, var(--secondary), var(--secondary-dark)) !important;
145
  padding: 1.5rem !important;
146
- margin-bottom: 1.5rem !important;
 
147
  }
148
 
149
  .instructions h3 {
150
  margin-top: 0;
151
  margin-bottom: 0.75rem;
152
- color: var(--primary) !important;
153
  }
154
 
155
  .instructions ul {
@@ -159,6 +185,7 @@ h1, h2, h3, label, .gr-label {
159
 
160
  .instructions li {
161
  margin-bottom: 0.5rem;
 
162
  }
163
 
164
  .instructions li:last-child {
@@ -169,106 +196,155 @@ h1, h2, h3, label, .gr-label {
169
  text-align: center;
170
  margin-top: 2rem;
171
  padding-top: 1.5rem;
172
- border-top: 1px solid #374151;
173
- color: var(--text-muted);
174
  font-size: 0.875rem;
175
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  """
177
 
178
- # Gradio UI with professional dark theme
179
  with gr.Blocks(
180
- theme=gr.themes.Soft(
181
- primary_hue="indigo",
182
- secondary_hue="gray"
183
- ),
184
  css=custom_css,
185
- title="Professional Face Swap Tool"
 
186
  ) as demo:
187
 
188
- # Header section with title and status indicator
189
  with gr.Row(elem_classes="header"):
190
  with gr.Column(scale=3):
191
  with gr.Row(elem_classes="title-section"):
192
  gr.Markdown("""
193
- # πŸ”„ Professional Face Swap
194
- ### AI-Powered Face Swapping Technology
195
  """)
196
  with gr.Column(scale=1):
197
  with gr.Row():
198
  gr.Markdown("""
199
  <div class="status-text">
200
- <div class="status-indicator status-online"></div>
201
  System Online
202
  </div>
203
  """)
204
 
205
- # Instructions section
206
  with gr.Row():
207
- with gr.Column():
208
- gr.Markdown("""
209
- <div class="instructions">
210
- <h3>πŸ“‹ How to Use</h3>
211
- <ul>
212
- <li><strong>Source Face:</strong> Select an image containing the face you want to use</li>
213
- <li><strong>Target Face:</strong> Select an image where you want to place the source face</li>
214
- <li><strong>Face Enhancer:</strong> Enable for higher quality results (takes longer)</li>
215
- <li>Click <strong>Swap Faces</strong> to process the images</li>
216
- </ul>
217
- </div>
218
- """)
219
-
220
- # Main content
221
- with gr.Row():
222
- with gr.Column(scale=1):
223
- gr.Markdown("### πŸ“€ Input Images")
224
- with gr.Group():
225
  source_image = gr.Image(
226
- label="Source Face Image",
227
  type="numpy",
228
  height=300,
229
  elem_classes="gr-box"
230
  )
 
 
 
231
  target_image = gr.Image(
232
- label="Target Face Image",
233
  type="numpy",
234
  height=300,
235
  elem_classes="gr-box"
236
  )
237
-
238
- with gr.Group():
 
 
 
 
239
  face_enhancer = gr.Checkbox(
240
- label="Enable Face Enhancer (Higher Quality)",
241
  value=True,
242
  info="Improves face quality but increases processing time"
243
  )
244
 
245
- submit = gr.Button(
246
- "πŸ”„ Swap Faces",
247
- variant="primary",
248
- size="lg"
249
- )
250
-
251
- with gr.Column(scale=1):
252
- gr.Markdown("### πŸ“₯ Output Image")
253
- output_image = gr.Image(
254
- label="Output Image",
255
- interactive=False,
256
- height=500,
257
- elem_classes="gr-box"
258
- )
259
-
260
- with gr.Group():
261
- gr.Markdown("### πŸ“Š Processing Info")
262
- info_text = gr.Textbox(
263
- label="Status",
264
- value="Ready to process images",
265
- interactive=False
 
 
 
 
 
 
 
 
266
  )
267
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
268
  # Footer
269
  gr.Markdown("""
270
  <div class="footer">
271
- <p>Powered by Roop β€’ Professional Face Swap Tool v1.0</p>
272
  </div>
273
  """)
274
 
 
50
  # Return output image
51
  return Image.open(output_path)
52
 
53
+ # Custom CSS for neon style with animated online indicator
54
  custom_css = """
55
  :root {
56
+ --neon-primary: #00f3ff;
57
+ --neon-secondary: #ff00ff;
58
+ --neon-accent: #00ff87;
59
+ --dark-bg: #0a0a1a;
60
+ --dark-panel: #13132b;
61
+ --text-primary: #ffffff;
62
+ --text-secondary: #a0a0c0;
63
  }
64
 
65
  body {
66
+ background: var(--dark-bg) !important;
67
+ color: var(--text-primary) !important;
68
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif !important;
69
  }
70
 
71
  .gr-block {
72
+ background: var(--dark-panel) !important;
73
+ border-radius: 12px !important;
74
+ border: 1px solid rgba(0, 243, 255, 0.2) !important;
75
+ box-shadow: 0 0 15px rgba(0, 243, 255, 0.1) !important;
76
  }
77
 
78
  .gr-box {
79
+ border-color: rgba(0, 243, 255, 0.3) !important;
80
+ color: var(--text-primary) !important;
81
+ background: rgba(10, 10, 26, 0.7) !important;
82
  }
83
 
84
  h1, h2, h3, label, .gr-label {
85
+ color: var(--text-primary) !important;
86
+ text-shadow: 0 0 5px rgba(0, 243, 255, 0.5);
87
  }
88
 
89
  .gr-button {
90
+ background: linear-gradient(45deg, var(--neon-primary), var(--neon-secondary)) !important;
91
+ color: black !important;
92
  border: none !important;
93
+ border-radius: 8px !important;
94
+ padding: 12px 28px !important;
95
+ font-weight: 600 !important;
96
+ text-transform: uppercase !important;
97
+ letter-spacing: 1px !important;
98
+ box-shadow: 0 0 10px var(--neon-primary), 0 0 20px rgba(0, 243, 255, 0.3) !important;
99
+ transition: all 0.3s ease !important;
100
  }
101
 
102
  .gr-button:not(:disabled):hover {
103
+ transform: translateY(-2px);
104
+ box-shadow: 0 0 15px var(--neon-primary), 0 0 30px rgba(0, 243, 255, 0.5) !important;
 
105
  }
106
 
107
  .gr-button:disabled {
108
  background: #4b5563 !important;
109
+ box-shadow: none !important;
110
  }
111
 
112
  .status-indicator {
113
  display: inline-block;
114
+ width: 12px;
115
+ height: 12px;
116
  border-radius: 50%;
117
+ margin-right: 10px;
118
+ background-color: var(--neon-accent);
119
+ box-shadow: 0 0 0 0 rgba(0, 255, 135, 0.7);
120
+ animation: pulse 2s infinite;
121
  }
122
 
123
+ @keyframes pulse {
124
+ 0% {
125
+ box-shadow: 0 0 0 0 rgba(0, 255, 135, 0.7);
126
+ }
127
+ 70% {
128
+ box-shadow: 0 0 0 10px rgba(0, 255, 135, 0);
129
+ }
130
+ 100% {
131
+ box-shadow: 0 0 0 0 rgba(0, 255, 135, 0);
132
+ }
133
  }
134
 
135
  .status-text {
136
+ color: var(--text-secondary);
137
  font-size: 0.9rem;
138
  display: flex;
139
  align-items: center;
 
143
  display: flex;
144
  justify-content: space-between;
145
  align-items: center;
146
+ margin-bottom: 2rem;
147
+ padding: 1.5rem;
148
+ background: linear-gradient(90deg, rgba(0,243,255,0.1) 0%, rgba(255,0,255,0.1) 100%);
149
+ border-radius: 12px;
150
+ border: 1px solid rgba(0, 243, 255, 0.3);
151
+ box-shadow: 0 0 20px rgba(0, 243, 255, 0.2);
152
  }
153
 
154
  .title-section h1 {
155
  margin-bottom: 0.25rem;
156
+ font-weight: 800;
157
+ background: linear-gradient(45deg, var(--neon-primary), var(--neon-secondary));
158
+ -webkit-background-clip: text;
159
+ -webkit-text-fill-color: transparent;
160
+ text-shadow: 0 0 10px rgba(0, 243, 255, 0.5);
161
  }
162
 
163
  .title-section p {
164
+ color: var(--text-secondary);
165
  margin: 0;
166
  }
167
 
168
  .instructions {
169
+ background: linear-gradient(90deg, rgba(0,243,255,0.05) 0%, rgba(255,0,255,0.05) 100%) !important;
170
  padding: 1.5rem !important;
171
+ margin-bottom: 2rem !important;
172
+ border: 1px solid rgba(0, 243, 255, 0.2) !important;
173
  }
174
 
175
  .instructions h3 {
176
  margin-top: 0;
177
  margin-bottom: 0.75rem;
178
+ color: var(--neon-primary) !important;
179
  }
180
 
181
  .instructions ul {
 
185
 
186
  .instructions li {
187
  margin-bottom: 0.5rem;
188
+ color: var(--text-secondary);
189
  }
190
 
191
  .instructions li:last-child {
 
196
  text-align: center;
197
  margin-top: 2rem;
198
  padding-top: 1.5rem;
199
+ border-top: 1px solid rgba(0, 243, 255, 0.2);
200
+ color: var(--text-secondary);
201
  font-size: 0.875rem;
202
  }
203
+
204
+ .image-container {
205
+ border: 2px solid rgba(0, 243, 255, 0.3);
206
+ border-radius: 12px;
207
+ padding: 8px;
208
+ background: rgba(0, 0, 0, 0.2);
209
+ margin-bottom: 1.5rem;
210
+ box-shadow: 0 0 15px rgba(0, 243, 255, 0.1);
211
+ }
212
+
213
+ .image-container .gr-label {
214
+ background: rgba(0, 243, 255, 0.1);
215
+ padding: 8px 12px;
216
+ border-radius: 8px;
217
+ margin-bottom: 10px;
218
+ display: inline-block;
219
+ }
220
+
221
+ .control-panel {
222
+ background: linear-gradient(90deg, rgba(0,243,255,0.05) 0%, rgba(255,0,255,0.05) 100%) !important;
223
+ padding: 1.5rem !important;
224
+ border: 1px solid rgba(0, 243, 255, 0.2) !important;
225
+ border-radius: 12px !important;
226
+ }
227
+
228
+ .output-highlight {
229
+ border: 2px solid var(--neon-accent) !important;
230
+ box-shadow: 0 0 20px rgba(0, 255, 135, 0.3) !important;
231
+ }
232
+
233
+ .upload-text {
234
+ color: var(--text-secondary);
235
+ text-align: center;
236
+ padding: 20px;
237
+ }
238
  """
239
 
240
+ # Gradio UI with neon style theme
241
  with gr.Blocks(
 
 
 
 
242
  css=custom_css,
243
+ title="Neon Face Swap AI",
244
+ theme=gr.themes.Default(primary_hue="cyan", secondary_hue="pink")
245
  ) as demo:
246
 
247
+ # Header section with title and animated status indicator
248
  with gr.Row(elem_classes="header"):
249
  with gr.Column(scale=3):
250
  with gr.Row(elem_classes="title-section"):
251
  gr.Markdown("""
252
+ # 🌌 NEON FACE SWAP
253
+ ### Next-Generation AI Face Swapping Technology
254
  """)
255
  with gr.Column(scale=1):
256
  with gr.Row():
257
  gr.Markdown("""
258
  <div class="status-text">
259
+ <div class="status-indicator"></div>
260
  System Online
261
  </div>
262
  """)
263
 
264
+ # Main content - unique arrangement
265
  with gr.Row():
266
+ # Left column - inputs
267
+ with gr.Column(scale=1, min_width=400):
268
+ gr.Markdown("### πŸ“€ SOURCE IMAGE")
269
+ with gr.Group(elem_classes="image-container"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
270
  source_image = gr.Image(
271
+ label="Upload Source Face",
272
  type="numpy",
273
  height=300,
274
  elem_classes="gr-box"
275
  )
276
+
277
+ gr.Markdown("### 🎯 TARGET IMAGE")
278
+ with gr.Group(elem_classes="image-container"):
279
  target_image = gr.Image(
280
+ label="Upload Target Face",
281
  type="numpy",
282
  height=300,
283
  elem_classes="gr-box"
284
  )
285
+
286
+ # Middle column - controls
287
+ with gr.Column(scale=1, min_width=300):
288
+ with gr.Group(elem_classes="control-panel"):
289
+ gr.Markdown("### βš™οΈ PROCESSING CONTROLS")
290
+
291
  face_enhancer = gr.Checkbox(
292
+ label="Enable Face Enhancer",
293
  value=True,
294
  info="Improves face quality but increases processing time"
295
  )
296
 
297
+ gr.Markdown("---")
298
+
299
+ with gr.Row():
300
+ submit = gr.Button(
301
+ "πŸ”„ SWAP FACES",
302
+ variant="primary",
303
+ size="lg",
304
+ scale=2
305
+ )
306
+
307
+ gr.Markdown("---")
308
+
309
+ with gr.Group():
310
+ gr.Markdown("### πŸ“Š STATUS")
311
+ info_text = gr.Textbox(
312
+ label="Processing Status",
313
+ value="Ready to process images",
314
+ interactive=False
315
+ )
316
+
317
+ # Right column - output
318
+ with gr.Column(scale=1, min_width=400):
319
+ gr.Markdown("### πŸ“₯ RESULT")
320
+ with gr.Group(elem_classes="image-container output-highlight"):
321
+ output_image = gr.Image(
322
+ label="Swapped Result",
323
+ interactive=False,
324
+ height=500,
325
+ elem_classes="gr-box"
326
  )
327
 
328
+ # Instructions at the bottom
329
+ with gr.Row():
330
+ with gr.Column():
331
+ gr.Markdown("""
332
+ <div class="instructions">
333
+ <h3>πŸš€ HOW TO USE</h3>
334
+ <ul>
335
+ <li><strong>Source Face:</strong> Select an image containing the face you want to use</li>
336
+ <li><strong>Target Face:</strong> Select an image where you want to place the source face</li>
337
+ <li><strong>Face Enhancer:</strong> Enable for higher quality results (takes longer)</li>
338
+ <li>Click <strong>SWAP FACES</strong> to process the images</li>
339
+ <li>Download your result when processing is complete</li>
340
+ </ul>
341
+ </div>
342
+ """)
343
+
344
  # Footer
345
  gr.Markdown("""
346
  <div class="footer">
347
+ <p>Powered by Roop β€’ Neon Face Swap AI v2.0</p>
348
  </div>
349
  """)
350