arxivgpt kim commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,6 @@ import tempfile
|
|
| 7 |
import time
|
| 8 |
import gradio as gr
|
| 9 |
|
| 10 |
-
|
| 11 |
class Predictor:
|
| 12 |
def __init__(self):
|
| 13 |
self.setup()
|
|
@@ -25,7 +24,6 @@ class Predictor:
|
|
| 25 |
)
|
| 26 |
os.chdir('..')
|
| 27 |
|
| 28 |
-
"""Load the model into memory to make running multiple predictions efficient"""
|
| 29 |
self.face_swapper = insightface.model_zoo.get_model('models/inswapper_128.onnx',
|
| 30 |
providers=onnxruntime.get_available_providers())
|
| 31 |
self.face_enhancer = gfpgan.GFPGANer(model_path='models/GFPGANv1.4.pth', upscale=1)
|
|
@@ -42,15 +40,10 @@ class Predictor:
|
|
| 42 |
return None
|
| 43 |
|
| 44 |
def predict(self, input_image, swap_image):
|
| 45 |
-
"""Run a single prediction on the model"""
|
| 46 |
try:
|
| 47 |
frame = cv2.imread(input_image.name)
|
| 48 |
face = self.get_face(frame)
|
| 49 |
source_face = self.get_face(cv2.imread(swap_image.name))
|
| 50 |
-
try:
|
| 51 |
-
print(frame.shape, face.shape, source_face.shape)
|
| 52 |
-
except:
|
| 53 |
-
print("printing shapes failed.")
|
| 54 |
result = self.face_swapper.get(frame, face, source_face, paste_back=True)
|
| 55 |
|
| 56 |
_, _, result = self.face_enhancer.enhance(
|
|
@@ -64,7 +57,6 @@ class Predictor:
|
|
| 64 |
print(f"{e}")
|
| 65 |
return None
|
| 66 |
|
| 67 |
-
|
| 68 |
# Instantiate the Predictor class
|
| 69 |
predictor = Predictor()
|
| 70 |
|
|
@@ -75,15 +67,16 @@ footer {
|
|
| 75 |
"""
|
| 76 |
|
| 77 |
# Create Gradio Interface
|
| 78 |
-
iface = gr.Interface(
|
| 79 |
fn=predictor.predict,
|
| 80 |
inputs=[
|
| 81 |
gr.inputs.Image(type="file", label="Target Image"),
|
| 82 |
gr.inputs.Image(type="file", label="Swap Image")
|
| 83 |
],
|
| 84 |
outputs=gr.outputs.Image(type="file", label="Result"),
|
| 85 |
-
examples=[["input.jpg", "swap img.jpg"]]
|
| 86 |
-
|
|
|
|
| 87 |
|
| 88 |
# Launch the Gradio Interface
|
| 89 |
iface.launch()
|
|
|
|
| 7 |
import time
|
| 8 |
import gradio as gr
|
| 9 |
|
|
|
|
| 10 |
class Predictor:
|
| 11 |
def __init__(self):
|
| 12 |
self.setup()
|
|
|
|
| 24 |
)
|
| 25 |
os.chdir('..')
|
| 26 |
|
|
|
|
| 27 |
self.face_swapper = insightface.model_zoo.get_model('models/inswapper_128.onnx',
|
| 28 |
providers=onnxruntime.get_available_providers())
|
| 29 |
self.face_enhancer = gfpgan.GFPGANer(model_path='models/GFPGANv1.4.pth', upscale=1)
|
|
|
|
| 40 |
return None
|
| 41 |
|
| 42 |
def predict(self, input_image, swap_image):
|
|
|
|
| 43 |
try:
|
| 44 |
frame = cv2.imread(input_image.name)
|
| 45 |
face = self.get_face(frame)
|
| 46 |
source_face = self.get_face(cv2.imread(swap_image.name))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
result = self.face_swapper.get(frame, face, source_face, paste_back=True)
|
| 48 |
|
| 49 |
_, _, result = self.face_enhancer.enhance(
|
|
|
|
| 57 |
print(f"{e}")
|
| 58 |
return None
|
| 59 |
|
|
|
|
| 60 |
# Instantiate the Predictor class
|
| 61 |
predictor = Predictor()
|
| 62 |
|
|
|
|
| 67 |
"""
|
| 68 |
|
| 69 |
# Create Gradio Interface
|
| 70 |
+
iface = gr.Interface(
|
| 71 |
fn=predictor.predict,
|
| 72 |
inputs=[
|
| 73 |
gr.inputs.Image(type="file", label="Target Image"),
|
| 74 |
gr.inputs.Image(type="file", label="Swap Image")
|
| 75 |
],
|
| 76 |
outputs=gr.outputs.Image(type="file", label="Result"),
|
| 77 |
+
examples=[["input.jpg", "swap img.jpg"]],
|
| 78 |
+
css=css
|
| 79 |
+
)
|
| 80 |
|
| 81 |
# Launch the Gradio Interface
|
| 82 |
iface.launch()
|