Arrcttacsrks commited on
Commit
69fbad0
1 Parent(s): 74329f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +83 -74
app.py CHANGED
@@ -184,86 +184,95 @@ def swap_face(source_file, target_file, doFaceEnhancer):
184
  shutil.rmtree(folder_path)
185
  raise gr.Error(f"Face swap failed: {str(e)}")
186
 
187
- # Create custom style
188
- custom_css = """
189
- .container {
190
- max-width: 1200px;
191
- margin: auto;
192
- padding: 20px;
193
- }
194
- .output-image {
195
- min-height: 400px;
196
- border: 1px solid #ccc;
197
- border-radius: 8px;
198
- padding: 10px;
199
- }
200
- """
 
201
 
202
- # Gradio interface setup
203
- title = "Face - Интегратор"
204
- description = r"""
205
- The application will save the image history to Hugging Face dataset using the environment variable token.
206
- Please upload source and target images to begin the face swap process.
207
- """
208
- article = r"""
209
- <div style="text-align: center; max-width: 650px; margin: 40px auto;">
210
- <p>
211
- This tool performs face swapping with optional enhancement.
212
- The processed images are automatically saved to the Hugging Face dataset.
213
- </p>
214
- </div>
215
- """
216
 
217
- # Create Gradio interface with improved layout
218
- with gr.Blocks(title=title, css=custom_css) as app:
219
- gr.Markdown(f"<h1 style='text-align: center;'>{title}</h1>")
220
- gr.Markdown(description)
221
-
222
- with gr.Row():
223
- with gr.Column(scale=1):
224
- source_image = gr.Image(
225
- label="Source Image",
226
- type="numpy",
227
- tool="upload"
228
- )
229
-
230
- with gr.Column(scale=1):
231
- target_image = gr.Image(
232
- label="Target Image",
233
- type="numpy",
234
- tool="upload"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
  )
236
 
237
- with gr.Column(scale=1):
238
- output_image = gr.Image(
239
- label="Output Image",
240
- type="numpy",
241
- elem_classes="output-image"
242
  )
243
-
244
- with gr.Row():
245
- enhance_checkbox = gr.Checkbox(
246
- label="Применить алгоритм?",
247
- info="Улучшение качества изображения",
248
- value=False
249
- )
250
 
251
- with gr.Row():
252
- process_btn = gr.Button(
253
- "Process Face Swap",
254
- variant="primary",
255
- size="lg"
 
256
  )
 
 
257
 
258
- # Set up the processing event
259
- process_btn.click(
260
- fn=swap_face,
261
- inputs=[source_image, target_image, enhance_checkbox],
262
- outputs=output_image,
263
- api_name="swap_face"
264
- )
265
-
266
- gr.Markdown(article)
267
 
268
- # Launch the application
269
- app.launch(share=False)
 
184
  shutil.rmtree(folder_path)
185
  raise gr.Error(f"Face swap failed: {str(e)}")
186
 
187
+ def create_interface():
188
+ # Create custom style
189
+ custom_css = """
190
+ .container {
191
+ max-width: 1200px;
192
+ margin: auto;
193
+ padding: 20px;
194
+ }
195
+ .output-image {
196
+ min-height: 400px;
197
+ border: 1px solid #ccc;
198
+ border-radius: 8px;
199
+ padding: 10px;
200
+ }
201
+ """
202
 
203
+ # Gradio interface setup
204
+ title = "Face - Интегратор"
205
+ description = r"""
206
+ The application will save the image history to Hugging Face dataset using the environment variable token.
207
+ Please upload source and target images to begin the face swap process.
208
+ """
209
+ article = r"""
210
+ <div style="text-align: center; max-width: 650px; margin: 40px auto;">
211
+ <p>
212
+ This tool performs face swapping with optional enhancement.
213
+ The processed images are automatically saved to the Hugging Face dataset.
214
+ </p>
215
+ </div>
216
+ """
217
 
218
+ # Create Gradio interface with improved layout
219
+ with gr.Blocks(title=title, css=custom_css) as app:
220
+ gr.Markdown(f"<h1 style='text-align: center;'>{title}</h1>")
221
+ gr.Markdown(description)
222
+
223
+ with gr.Row():
224
+ with gr.Column(scale=1):
225
+ source_image = gr.Image(
226
+ label="Source Image",
227
+ type="numpy",
228
+ sources=["upload"]
229
+ )
230
+
231
+ with gr.Column(scale=1):
232
+ target_image = gr.Image(
233
+ label="Target Image",
234
+ type="numpy",
235
+ sources=["upload"]
236
+ )
237
+
238
+ with gr.Column(scale=1):
239
+ output_image = gr.Image(
240
+ label="Output Image",
241
+ type="numpy",
242
+ interactive=False,
243
+ elem_classes="output-image"
244
+ )
245
+
246
+ with gr.Row():
247
+ enhance_checkbox = gr.Checkbox(
248
+ label="Применить алгоритм?",
249
+ info="Улучшение качества изображения",
250
+ value=False
251
  )
252
 
253
+ with gr.Row():
254
+ process_btn = gr.Button(
255
+ "Process Face Swap",
256
+ variant="primary",
257
+ size="lg"
258
  )
 
 
 
 
 
 
 
259
 
260
+ # Set up the processing event
261
+ process_btn.click(
262
+ fn=swap_face,
263
+ inputs=[source_image, target_image, enhance_checkbox],
264
+ outputs=output_image,
265
+ api_name="swap_face"
266
  )
267
+
268
+ gr.Markdown(article)
269
 
270
+ return app
271
+
272
+ def main():
273
+ # Create and launch the interface
274
+ app = create_interface()
275
+ app.launch(share=False)
 
 
 
276
 
277
+ if __name__ == "__main__":
278
+ main()