Spaces:
Sleeping
Sleeping
init zeroGPU facefusion
Browse files- README.md +2 -3
- app.py +39 -0
- requirements.txt +7 -0
README.md
CHANGED
|
@@ -5,9 +5,8 @@ colorFrom: blue
|
|
| 5 |
colorTo: gray
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 6.25.0
|
| 8 |
-
python_version: '3.13'
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
|
|
|
| 11 |
---
|
| 12 |
-
|
| 13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 5 |
colorTo: gray
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 6.25.0
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
hardware: zero-a10g
|
| 11 |
---
|
| 12 |
+
Private FaceFusion ZeroGPU Space
|
|
|
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import spaces
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import cv2
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
@spaces.GPU
|
| 7 |
+
def swap_face(source_img, target_img):
|
| 8 |
+
import insightface
|
| 9 |
+
from insightface.app import FaceAnalysis
|
| 10 |
+
try:
|
| 11 |
+
app = FaceAnalysis(name='buffalo_l')
|
| 12 |
+
app.prepare(ctx_id=0, det_size=(640,640))
|
| 13 |
+
import insightface.model_zoo
|
| 14 |
+
swapper = insightface.model_zoo.get_model('inswapper_128.onnx', download=True)
|
| 15 |
+
if swapper is None:
|
| 16 |
+
return target_img
|
| 17 |
+
source = cv2.imread(source_img)
|
| 18 |
+
target = cv2.imread(target_img)
|
| 19 |
+
s_faces = app.get(source)
|
| 20 |
+
t_faces = app.get(target)
|
| 21 |
+
if not s_faces or not t_faces:
|
| 22 |
+
return target_img
|
| 23 |
+
res = swapper.get(target, t_faces[0], s_faces[0], paste_back=True)
|
| 24 |
+
out_path = "/tmp/swapped.jpg"
|
| 25 |
+
cv2.imwrite(out_path, res)
|
| 26 |
+
return out_path
|
| 27 |
+
except Exception as e:
|
| 28 |
+
return target_img
|
| 29 |
+
|
| 30 |
+
with gr.Blocks() as demo:
|
| 31 |
+
gr.Markdown("# FaceFusion Zero (PRO)")
|
| 32 |
+
with gr.Row():
|
| 33 |
+
src = gr.Image(type="filepath", label="Source (your face)")
|
| 34 |
+
tgt = gr.Image(type="filepath", label="Target (flying Kathmandu)")
|
| 35 |
+
out = gr.Image(type="filepath", label="Result")
|
| 36 |
+
btn = gr.Button("Swap")
|
| 37 |
+
btn.click(swap_face, inputs=[src, tgt], outputs=out)
|
| 38 |
+
|
| 39 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
spaces
|
| 3 |
+
insightface
|
| 4 |
+
onnxruntime-gpu
|
| 5 |
+
opencv-python
|
| 6 |
+
huggingface_hub
|
| 7 |
+
hf_transfer
|