Commit
Β·
bc0e10a
1
Parent(s):
958c54f
ui: simplify to minimal inputs and result; remove promos and gender
Browse files
app.py
CHANGED
|
@@ -37,12 +37,7 @@ def preprocess_video(path: str, target_fps: int = 12,
|
|
| 37 |
return out_path
|
| 38 |
|
| 39 |
# ββ main generate ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 40 |
-
def generate(input_image, input_video
|
| 41 |
-
# Pre-run nudge (small)
|
| 42 |
-
gr.Warning(
|
| 43 |
-
f'Skip the line β HD, no watermark, priority queue at '
|
| 44 |
-
f'<a href="https://www.face-swap.co/?utm_source=hfspace_videofaceswap&utm_medium=warning" target="_blank" rel="noopener">face-swap.co</a>'
|
| 45 |
-
)
|
| 46 |
|
| 47 |
# If backend client failed to initialize, show a clear error and bail
|
| 48 |
if client is None:
|
|
@@ -53,8 +48,7 @@ def generate(input_image, input_video, gender):
|
|
| 53 |
gr.Error(msg)
|
| 54 |
return None
|
| 55 |
|
| 56 |
-
|
| 57 |
-
gender = None
|
| 58 |
|
| 59 |
try:
|
| 60 |
pre_video = preprocess_video(input_video)
|
|
@@ -63,7 +57,7 @@ def generate(input_image, input_video, gender):
|
|
| 63 |
input_video={"video": handle_file(pre_video)},
|
| 64 |
device='cpu',
|
| 65 |
selector='many',
|
| 66 |
-
gender=
|
| 67 |
race=None,
|
| 68 |
order=None,
|
| 69 |
api_name="/predict"
|
|
@@ -74,14 +68,6 @@ def generate(input_image, input_video, gender):
|
|
| 74 |
if not job.status().success:
|
| 75 |
return None
|
| 76 |
|
| 77 |
-
# Post-success modal (big)
|
| 78 |
-
gr.Info(
|
| 79 |
-
f"β¨ Your preview is ready.<br>"
|
| 80 |
-
f"<strong>Get HD</strong> (4Γ quality, no watermark, priority) β "
|
| 81 |
-
f'<a href="https://www.face-swap.co/?utm_source=hfspace_videofaceswap&utm_medium=info" target="_blank" rel="noopener">Upgrade on face-swap.co</a>',
|
| 82 |
-
duration=8
|
| 83 |
-
)
|
| 84 |
-
|
| 85 |
video_path = job.outputs()[0]["video"]
|
| 86 |
return video_path
|
| 87 |
|
|
@@ -165,99 +151,19 @@ CUSTOM_CSS = """
|
|
| 165 |
|
| 166 |
"""
|
| 167 |
|
| 168 |
-
with gr.Blocks(title="Video Face Swap", theme=gr.themes.Soft()
|
| 169 |
-
# Sticky banner
|
| 170 |
-
gr.HTML(
|
| 171 |
-
f"""<a class="sticky-cta" href="https://www.face-swap.co/?utm_source=hfspace_videofaceswap&utm_medium=banner" target="_blank" rel="noopener"
|
| 172 |
-
aria-label="Upgrade to Pro on face-swap.co">
|
| 173 |
-
β‘ <strong>Upgrade to HD</strong> β priority queue & no duration limit!
|
| 174 |
-
<span class="pill">GPU</span>
|
| 175 |
-
</a>"""
|
| 176 |
-
)
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
gr.Markdown(
|
| 180 |
-
f"""
|
| 181 |
-
### Video Face Swap (Preview)
|
| 182 |
-
[face-swap.co](https://www.face-swap.co/?utm_source=hfspace_videofaceswap&utm_medium=subtitle)
|
| 183 |
-
|
| 184 |
-
**Free preview** is downsampled to 800px β’ 4s β’ 12fps to reduce wait time.
|
| 185 |
-
Want full-length **HD deep fake video** with GPU speed? **[Go Pro β](https://www.face-swap.co/?utm_source=hfspace_videofaceswap&utm_medium=go_pro)**
|
| 186 |
-
""",
|
| 187 |
-
elem_id="hero-md"
|
| 188 |
-
)
|
| 189 |
-
|
| 190 |
-
gr.HTML(
|
| 191 |
-
"""
|
| 192 |
-
<div class="api-cta-wrap">
|
| 193 |
-
<a class="api-cta-hero"
|
| 194 |
-
href="https://www.face-swap.co/api?utm_source=hfspace_videofaceswap&utm_medium=hero_api_new"
|
| 195 |
-
target="_blank" rel="noopener" aria-label="Face Swap API">
|
| 196 |
-
<span class="new">NEW</span>
|
| 197 |
-
<span class="txt">Face Swap API</span>
|
| 198 |
-
<span class="chev">β</span>
|
| 199 |
-
</a>
|
| 200 |
-
</div>
|
| 201 |
-
"""
|
| 202 |
-
)
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
with gr.Row():
|
| 207 |
with gr.Column(scale=5):
|
| 208 |
-
|
| 209 |
in_img = gr.Image(type="filepath", label="Source Image")
|
| 210 |
in_vid = gr.Video(label="Target Video")
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
go = gr.Button("Generate Preview", variant="primary")
|
| 214 |
-
pro = gr.Button("β‘ Upgrade to HD on face-swap.co", elem_classes=["upgrade-btn"])
|
| 215 |
-
|
| 216 |
with gr.Column(scale=5):
|
| 217 |
out_vid = gr.Video(label="Result")
|
| 218 |
|
| 219 |
-
gr.Examples(
|
| 220 |
-
examples=[["elon.png", "ironman.mp4", "all"], ["bella.jpg", "wizard.mp4", "all"]],
|
| 221 |
-
inputs=[in_img, in_vid, in_gen],
|
| 222 |
-
outputs=[out_vid],
|
| 223 |
-
fn=generate,
|
| 224 |
-
cache_examples=False, # disable caching to avoid JSON decode errors when backend fails
|
| 225 |
-
run_on_click=True, # clicking the example triggers generate()
|
| 226 |
-
label="Try an example"
|
| 227 |
-
)
|
| 228 |
-
|
| 229 |
-
# Sidebar CTA
|
| 230 |
-
with gr.Sidebar(open=False) as side:
|
| 231 |
-
gr.Markdown("### Upgrade to HD 1920x1080\n- 4Γ quality\n- Priority queue\n- 1-5 minute video duration\n- GPU speed")
|
| 232 |
-
pro_pro = gr.Button("Open Pro Checkout", variant="primary")
|
| 233 |
-
#pro_subscription = gr.Button("Monthly Subscription", variant="primary")
|
| 234 |
-
pro_api = gr.Button("API Access", variant="primary")
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
# Floating bottom promo
|
| 238 |
-
gr.HTML(
|
| 239 |
-
f'<div class="bottom-promo">'
|
| 240 |
-
f'Want HD & no duration limits? <a href="https://www.face-swap.co/?utm_source=hfspace_videofaceswap&utm_medium=upgrade" target="_blank" rel="noopener">Upgrade</a>'
|
| 241 |
-
f'</div>'
|
| 242 |
-
)
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
go.click(fn=open_side, inputs=None, outputs=side, queue=False) # fire instantly
|
| 246 |
-
|
| 247 |
# Wire events
|
| 248 |
-
go.click(fn=generate, inputs=[in_img, in_vid
|
| 249 |
-
|
| 250 |
-
# Open Pro in new tab via JS (no Python call)
|
| 251 |
-
pro.click(fn=None, inputs=None, outputs=None,
|
| 252 |
-
js=f"()=>window.open('https://www.face-swap.co/?utm_source=hfspace_videofaceswap&utm_medium=upgrade_to_hd','_blank')")
|
| 253 |
-
pro_pro.click(fn=None, inputs=None, outputs=None,
|
| 254 |
-
js=f"()=>window.open('https://www.face-swap.co/?utm_source=hfspace_videofaceswap&utm_medium=sidebar_pro','_blank')")
|
| 255 |
-
#pro_subscription.click(fn=None, inputs=None, outputs=None,
|
| 256 |
-
# js=f"()=>window.open('https://www.face-swap.co/?utm_source=hfspace_videofaceswap&utm_medium=sidebar_subscription','_blank')")
|
| 257 |
-
pro_api.click(fn=None, inputs=None, outputs=None,
|
| 258 |
-
js=f"()=>window.open('https://www.face-swap.co/api?utm_source=hfspace_videofaceswap&utm_medium=sidebar_api','_blank')")
|
| 259 |
|
| 260 |
-
# Queue for long jobs
|
| 261 |
demo.queue()
|
| 262 |
|
| 263 |
if __name__ == "__main__":
|
|
|
|
| 37 |
return out_path
|
| 38 |
|
| 39 |
# ββ main generate ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 40 |
+
def generate(input_image, input_video):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
# If backend client failed to initialize, show a clear error and bail
|
| 43 |
if client is None:
|
|
|
|
| 48 |
gr.Error(msg)
|
| 49 |
return None
|
| 50 |
|
| 51 |
+
# Minimal mode: no gender selector
|
|
|
|
| 52 |
|
| 53 |
try:
|
| 54 |
pre_video = preprocess_video(input_video)
|
|
|
|
| 57 |
input_video={"video": handle_file(pre_video)},
|
| 58 |
device='cpu',
|
| 59 |
selector='many',
|
| 60 |
+
gender=None,
|
| 61 |
race=None,
|
| 62 |
order=None,
|
| 63 |
api_name="/predict"
|
|
|
|
| 68 |
if not job.status().success:
|
| 69 |
return None
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
video_path = job.outputs()[0]["video"]
|
| 72 |
return video_path
|
| 73 |
|
|
|
|
| 151 |
|
| 152 |
"""
|
| 153 |
|
| 154 |
+
with gr.Blocks(title="Video Face Swap", theme=gr.themes.Soft()) as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
with gr.Row():
|
| 156 |
with gr.Column(scale=5):
|
|
|
|
| 157 |
in_img = gr.Image(type="filepath", label="Source Image")
|
| 158 |
in_vid = gr.Video(label="Target Video")
|
| 159 |
+
go = gr.Button("Generate", variant="primary")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
with gr.Column(scale=5):
|
| 161 |
out_vid = gr.Video(label="Result")
|
| 162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
# Wire events
|
| 164 |
+
go.click(fn=generate, inputs=[in_img, in_vid], outputs=out_vid)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
+
# Queue for long jobs
|
| 167 |
demo.queue()
|
| 168 |
|
| 169 |
if __name__ == "__main__":
|