Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +27 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import insightface
|
| 3 |
+
from insightface.app import FaceAnalysis
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def Swap_Face(image1,image2):
|
| 8 |
+
app = FaceAnalysis(name='buffalo_l')
|
| 9 |
+
app.prepare(ctx_id=0, det_size=(640, 640))
|
| 10 |
+
|
| 11 |
+
swapper = insightface.model_zoo.get_model("inswapper_128.onnx", download=False,
|
| 12 |
+
download_zip=False)
|
| 13 |
+
|
| 14 |
+
# Do the swap
|
| 15 |
+
face1 = app.get(image1)[0]
|
| 16 |
+
face2 = app.get(image2)[0]
|
| 17 |
+
|
| 18 |
+
img1_ = image1.copy()
|
| 19 |
+
img1_ = swapper.get(img1_, face1, face2, paste_back=True)
|
| 20 |
+
|
| 21 |
+
return img1_
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
title = "Swap Faces Using Our Model!!!"
|
| 25 |
+
iface = gr.Interface(fn=Swap_Face,inputs=["image","image"],outputs="image",title=title)
|
| 26 |
+
|
| 27 |
+
iface.launch(share=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
insightface
|
| 2 |
+
onnxruntime
|
| 3 |
+
gradio
|
| 4 |
+
torchvision
|