Spaces:
Paused
Paused
Update Main.py
Browse files
Main.py
CHANGED
|
@@ -1,9 +1,15 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import insightface
|
| 3 |
from insightface.app import FaceAnalysis
|
| 4 |
|
| 5 |
assert insightface.__version__ >= '0.7'
|
| 6 |
|
|
|
|
|
|
|
| 7 |
def prepare_app():
|
| 8 |
app = FaceAnalysis(name='buffalo_l')
|
| 9 |
app.prepare(ctx_id=0, det_size=(640, 640))
|
|
@@ -34,21 +40,3 @@ def swap_faces(sourceImage, sourceFaceIndex, destinationImage, destinationFaceIn
|
|
| 34 |
result = swapper.get(destinationImage, res_face, source_face, paste_back=True)
|
| 35 |
return result
|
| 36 |
|
| 37 |
-
gr.Interface(
|
| 38 |
-
swap_faces,
|
| 39 |
-
[
|
| 40 |
-
gr.Image(label="Source Image (the image with the face that you want to use)"),
|
| 41 |
-
gr.Number(precision=0, value=1, label='Source Face Position', info='In case there are multiple faces on the image specify which should be used from the left, starting at 1'),
|
| 42 |
-
gr.Image(label="Destination Image (the image with the face that you want to replace)"),
|
| 43 |
-
gr.Number(precision=0, value=1, label='Destination Face Position', info='In case there are multiple faces on the image specify which should be replaced from the left, starting at 1')
|
| 44 |
-
],
|
| 45 |
-
gr.Image(),
|
| 46 |
-
examples=[
|
| 47 |
-
['./examples/rihanna.jpg', 1, './examples/margaret_thatcher.jpg', 3],
|
| 48 |
-
['./examples/game_of_thrones.jpg', 5, './examples/game_of_thrones.jpg', 4],
|
| 49 |
-
],
|
| 50 |
-
theme=gr.themes.Base(),
|
| 51 |
-
title="Face Swapper App 🔄",
|
| 52 |
-
description="🌀 This app allows you to swap faces between images. <br>➡️ Upload a source image and a destination image, and specify the positions of the faces you'd like to swap! <br>⚡️ Try it out quickly by using the examples below. <br>💡 At [Dentro](https://dentro-innovation.com), we help you to discover, develop and implement AI within your organisation! <br>📖 The original authors of the face swap model can be found [here](https://github.com/deepinsight/insightface/blob/master/examples/in_swapper/README.md).<br>❤️ Feel free to like or duplicate this space!",
|
| 53 |
-
thumbnail='./examples/rihatcher.jpg'
|
| 54 |
-
).launch()
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from fastapi.staticfiles import StaticFiles
|
| 3 |
+
from fastapi.responses import FileResponse
|
| 4 |
+
|
| 5 |
+
|
| 6 |
import insightface
|
| 7 |
from insightface.app import FaceAnalysis
|
| 8 |
|
| 9 |
assert insightface.__version__ >= '0.7'
|
| 10 |
|
| 11 |
+
app = FastAPI()
|
| 12 |
+
|
| 13 |
def prepare_app():
|
| 14 |
app = FaceAnalysis(name='buffalo_l')
|
| 15 |
app.prepare(ctx_id=0, det_size=(640, 640))
|
|
|
|
| 40 |
result = swapper.get(destinationImage, res_face, source_face, paste_back=True)
|
| 41 |
return result
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|