| | |
| | |
| | import numpy as np |
| | import gradio as gr |
| | import roop.globals |
| | from roop.core import ( |
| | start, |
| | decode_execution_providers, |
| | suggest_max_memory, |
| | suggest_execution_threads, |
| | ) |
| | from roop.processors.frame.core import get_frame_processors_modules |
| | from roop.utilities import normalize_output_path |
| | import os |
| | from PIL import Image |
| |
|
| | article_text = """ |
| | <div style="text-align: center;"> |
| | <p>Enjoying the tool? Buy me a coffee and get exclusive prompt guides!</p> |
| | <p><i>Instantly unlock helpful tips for creating better prompts!</i></p> |
| | <div style="display: flex; justify-content: center;"> |
| | <a href="https://piczify.lemonsqueezy.com/buy/0f5206fa-68e8-42f6-9ca8-4f80c587c83e"> |
| | <img src="https://www.buymeacoffee.com/assets/img/custom_images/yellow_img.png" |
| | alt="Buy Me a Coffee" |
| | style="height: 40px; width: auto; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); border-radius: 10px;"> |
| | </a> |
| | </div> |
| | </div> |
| | """ |
| |
|
| | description_text = """<div style="display:flex;column-gap:4px;"> |
| | <a href="https://huggingface.co/spaces/ovi054/face-swap-pro?duplicate=true"> |
| | <img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/duplicate-this-space-sm.svg" alt="Duplicate this Space"> |
| | </a> |
| | <a href="https://huggingface.co/ovi054"> |
| | <img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/follow-me-on-HF-sm-dark.svg" alt="Follow me on HF"> |
| | </a> |
| | </div>""" |
| |
|
| |
|
| | def swap_face(source_file, target_file,doFaceEnhancer): |
| |
|
| | source_path = "input.jpg" |
| | target_path = "target.jpg" |
| |
|
| | source_image = Image.fromarray(source_file) |
| | source_image.save(source_path) |
| | target_image = Image.fromarray(target_file) |
| | target_image.save(target_path) |
| |
|
| | print("source_path: ", source_path) |
| | print("target_path: ", target_path) |
| |
|
| | roop.globals.source_path = source_path |
| | roop.globals.target_path = target_path |
| | output_path = "output.jpg" |
| | roop.globals.output_path = normalize_output_path( |
| | roop.globals.source_path, roop.globals.target_path, output_path |
| | ) |
| | if doFaceEnhancer == True: |
| | roop.globals.frame_processors = ["face_swapper","face_enhancer"] |
| | else: |
| | roop.globals.frame_processors = ["face_swapper"] |
| | roop.globals.headless = True |
| | roop.globals.keep_fps = True |
| | roop.globals.keep_audio = True |
| | roop.globals.keep_frames = False |
| | roop.globals.many_faces = False |
| | roop.globals.video_encoder = "libx264" |
| | roop.globals.video_quality = 18 |
| | roop.globals.max_memory = suggest_max_memory() |
| | roop.globals.execution_providers = decode_execution_providers(["cuda"]) |
| | roop.globals.execution_threads = suggest_execution_threads() |
| |
|
| | print( |
| | "start process", |
| | roop.globals.source_path, |
| | roop.globals.target_path, |
| | roop.globals.output_path, |
| | ) |
| |
|
| | for frame_processor in get_frame_processors_modules( |
| | roop.globals.frame_processors |
| | ): |
| | if not frame_processor.pre_check(): |
| | return |
| |
|
| | start() |
| | return output_path |
| |
|
| |
|
| | app = gr.Interface( |
| | fn=swap_face, inputs=[gr.Image(), gr.Image(),gr.Checkbox(label="face_enhancer?", info="do face enhancer?")], outputs="image", description = description_text, article = article_text |
| | ) |
| | app.launch() |
| |
|