File size: 2,856 Bytes
1f5f680
f2c9245
ced9582
 
7310428
1f5f680
5b71a2f
f2c9245
3bca149
 
f2c9245
3bca149
 
 
 
5739d02
3bca149
78f1c7e
 
 
e23e921
08e132f
e634bf6
 
f2c9245
3bca149
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
faa2cc3
 
 
3bca149
 
 
 
 
 
 
 
 
 
 
f2c9245
3bca149
faa2cc3
 
f2c9245
3bca149
ced9582
 
 
 
 
3bca149
 
ced9582
3bca149
1f5f680
7e398ae
 
 
 
 
3bca149
 
 
 
 
 
 
 
 
f1a3cbd
faa2cc3
3bca149
faa2cc3
f1a3cbd
410276e
 
3bca149
410276e
 
b1b5fc5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import gradio as gr
from PIL import Image
import time
import os
import pathlib

def greet(input1, input2):

    modo = "video"
    print("Inicio: Estamos en modo ", modo)

    print("Input1:")
    print(input1)
    print("Input2:")
    print(input2)

    path_video = input2
    #Para local.
    #path_parts = path_video.split("\\")
    #Para HuggingFace
    path_parts = path_video.split("/")
    print("Imprimiendo path_parts: ", path_parts)
    path_bueno = "/".join(path_parts[0:len(path_parts) - 2])
    #path_bueno = path_bueno.replace("\\", "/")

    print("Path bueno:")
    print(path_bueno)

    files = os.listdir(path_bueno)
    print("Estos son los files que hay:")
    print(files)

    time.sleep(10)

    ext_imagen = "png"
    ext_video = "mp4"

    #Selector de modo.
    if modo == "video": 
        print("Se asigno la extensi贸n de video:", ext_video)
        extension = ext_video
    else:
        print("Se asigno la extensi贸n de video:", ext_video)
        extension = ext_imagen

    #El source siempre es una imagen.
    source_path = "source.png"
    target_path = "target." + extension
    result_path = "result." + extension

    #La primera siempre ser谩 una imagen, por eso no entra en el modo selector.
    source_image = Image.fromarray(input1)
    print("Esto es source_image: ", source_image)
    source_image.save(source_path)
        
    #Aqu铆 trabajaremos solo el target.
    if modo == "video":
        #Para Video
        target_path = input2
    else:
        #Es decir si es modo imagen
        #Para Imagenes
        target_image = Image.fromarray(input2)
        print("Esto es target_image: ", target_image)
        target_image.save(target_path)

    print("Despu茅s de los selectores de modo los paths quedaron as铆:")
    print("source_path: ", source_path)
    print("target_path: ", target_path)

    command = f"python run.py -s {source_path}  -t {target_path} -o {result_path} --frame-processor face_swapper"
    print(command)
    time.sleep(1)
    proc = os.popen(command)
    output = proc.read()

    print("Output (resultado de la ejecuci贸n del c贸digo):")
    time.sleep(2)
    print(output)
    print("Termin贸 la impresi贸n del output...")

    print("Ahora estamos imprimiendo las rutas para ver si apareci贸 una nueva:")
    files = os.listdir(path_bueno)
    print("Estos son los files que hay:")
    print(files)

    if modo == "video":
        #Para video
        path = pathlib.Path("result.mp4")
        return path, path
    else:
        #Para imagen
        path = pathlib.Path("result.png")
        return path, path
     
#As铆 para imagenes
# demo = gr.Interface(
# fn=greet, inputs=[gr.Image(), gr.Image()], outputs=[gr.Image(), gr.Image()]
# )

#As铆 para video
demo = gr.Interface(
fn=greet, inputs=[gr.Image(), gr.Video()], outputs=[gr.Video(), gr.Video()]
)

demo.launch()