aheedsajid commited on
Commit
57c6123
·
verified ·
1 Parent(s): 0c8c405

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -28
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import numpy as np
2
  import gradio as gr
3
  import roop.globals
@@ -12,8 +14,12 @@ from roop.utilities import normalize_output_path
12
  import os
13
  from PIL import Image
14
 
 
 
 
 
15
 
16
- def swap_face(source_file, target_file,doFaceEnhancer):
17
 
18
  source_path = "input.jpg"
19
  target_path = "target.jpg"
@@ -32,8 +38,8 @@ def swap_face(source_file, target_file,doFaceEnhancer):
32
  roop.globals.output_path = normalize_output_path(
33
  roop.globals.source_path, roop.globals.target_path, output_path
34
  )
35
- if doFaceEnhancer == True:
36
- roop.globals.frame_processors = ["face_swapper","face_enhancer"]
37
  else:
38
  roop.globals.frame_processors = ["face_swapper"]
39
  roop.globals.headless = True
@@ -63,33 +69,14 @@ def swap_face(source_file, target_file,doFaceEnhancer):
63
  start()
64
  return output_path
65
 
66
-
67
  app = gr.Interface(
68
  fn=swap_face,
69
- inputs=[gr.Image(), gr.Image(), gr.Checkbox(label="face_enhancer?", info="do face enhancer?")],
70
  outputs="image",
71
- layout="vertical"
 
 
72
  )
73
 
74
- # Add HTML sections
75
- app.components.insert(0, gr.HTML("""
76
- <div style="background-color: #f0f0f0; padding: 10px; border-radius: 5px;">
77
- <h3>Banner 1: Welcome to Face Swap!</h3>
78
- <p>Upload your source and target images to begin.</p>
79
- </div>
80
- """))
81
-
82
- app.components.insert(2, gr.HTML("""
83
- <div style="background-color: #e0f0e0; padding: 10px; border-radius: 5px;">
84
- <h4>Banner 2: Optional Face Enhancement</h4>
85
- <p>Check the box to apply face enhancement to the output.</p>
86
- </div>
87
- """))
88
-
89
- app.components.append(gr.HTML("""
90
- <div style="background-color: #f0f0f0; padding: 10px; border-radius: 5px;">
91
- <p>Banner 3: Results will appear below.</p>
92
- </div>
93
- """))
94
-
95
- app.launch()
 
1
+ # -* coding:UTF-8 -*
2
+ # !/usr/bin/env python
3
  import numpy as np
4
  import gradio as gr
5
  import roop.globals
 
14
  import os
15
  from PIL import Image
16
 
17
+ # Define HTML content for banners and additional sections
18
+ html_banner = "<h2>Welcome to Face Swapper App</h2>"
19
+ html_section1 = "<h3>Instructions:</h3><p>Upload source and target images, and select 'Face Enhancer' option if desired.</p>"
20
+ html_section2 = "<h3>Additional Info:</h3><p>This app uses CUDA for faster processing.</p>"
21
 
22
+ def swap_face(source_file, target_file, doFaceEnhancer):
23
 
24
  source_path = "input.jpg"
25
  target_path = "target.jpg"
 
38
  roop.globals.output_path = normalize_output_path(
39
  roop.globals.source_path, roop.globals.target_path, output_path
40
  )
41
+ if doFaceEnhancer:
42
+ roop.globals.frame_processors = ["face_swapper", "face_enhancer"]
43
  else:
44
  roop.globals.frame_processors = ["face_swapper"]
45
  roop.globals.headless = True
 
69
  start()
70
  return output_path
71
 
72
+ # Define Gradio interface with HTML banners and sections
73
  app = gr.Interface(
74
  fn=swap_face,
75
+ inputs=[gr.Image(), gr.Image(), gr.Checkbox(label="Enable Face Enhancer", default=False)],
76
  outputs="image",
77
+ title="Face Swapper",
78
+ description="Swap faces between two images with optional face enhancement.",
79
+ html=[html_banner, html_section1, html_section2]
80
  )
81
 
82
+ app.launch()