Spaces:
Sleeping
Sleeping
Moibe
commited on
Commit
•
3bca149
1
Parent(s):
410276e
Operaciones en OS
Browse files- .gitignore +5 -4
- app.py +64 -38
- local-filename.jpg +0 -0
- retriever.py +26 -0
.gitignore
CHANGED
@@ -1,9 +1,11 @@
|
|
1 |
-
|
2 |
-
|
3 |
target.jpg
|
|
|
|
|
|
|
4 |
result.mp4
|
5 |
|
6 |
-
|
7 |
inswapper_128.onnx
|
8 |
|
9 |
.idea
|
@@ -11,7 +13,6 @@ models
|
|
11 |
temp
|
12 |
__pycache__
|
13 |
|
14 |
-
|
15 |
# Byte-compiled / optimized / DLL files
|
16 |
__pycache__/
|
17 |
*.py[cod]
|
|
|
1 |
+
source.jpg
|
2 |
+
source.png
|
3 |
target.jpg
|
4 |
+
target.png
|
5 |
+
result.jpg
|
6 |
+
result.png
|
7 |
result.mp4
|
8 |
|
|
|
9 |
inswapper_128.onnx
|
10 |
|
11 |
.idea
|
|
|
13 |
temp
|
14 |
__pycache__
|
15 |
|
|
|
16 |
# Byte-compiled / optimized / DLL files
|
17 |
__pycache__/
|
18 |
*.py[cod]
|
app.py
CHANGED
@@ -4,69 +4,95 @@ import time
|
|
4 |
import os
|
5 |
import pathlib
|
6 |
|
7 |
-
#Greet es una función de ejemplo para usar.
|
8 |
def greet(input1, input2):
|
9 |
-
print("Imprimiendo en Consola")
|
10 |
-
print("Ésto es el input1 al día de hoy: ", input1)
|
11 |
-
print("Ésto es el input2 al día de hoy: ", input2)
|
12 |
|
13 |
-
|
14 |
-
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
23 |
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
source_image = Image.fromarray(input1)
|
26 |
print("Esto es source_image: ", source_image)
|
27 |
source_image.save(source_path)
|
28 |
-
|
29 |
-
#
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
35 |
|
|
|
36 |
print("source_path: ", source_path)
|
37 |
print("target_path: ", target_path)
|
38 |
|
39 |
-
|
40 |
-
target = target_path
|
41 |
-
output = result_path
|
42 |
-
|
43 |
-
#command = "adios.py"
|
44 |
-
command = f"python run.py -s {source} -t {target} -o {output} --frame-processor face_swapper"
|
45 |
print(command)
|
46 |
time.sleep(1)
|
47 |
proc = os.popen(command)
|
48 |
output = proc.read()
|
49 |
|
50 |
-
print("
|
51 |
-
time.sleep(
|
52 |
print(output)
|
53 |
-
print("
|
54 |
-
|
55 |
-
#Para imagen
|
56 |
-
path = pathlib.Path("result.jpg")
|
57 |
-
#Para video
|
58 |
-
path = pathlib.Path("result.mp4")
|
59 |
-
|
60 |
-
return path
|
61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
#Así para imagenes
|
63 |
# demo = gr.Interface(
|
64 |
-
# fn=greet, inputs=[gr.Image(), gr.Image()], outputs=
|
65 |
# )
|
66 |
|
67 |
#Así para video
|
68 |
demo = gr.Interface(
|
69 |
-
fn=greet, inputs=[gr.Image(), gr.Video()], outputs=
|
70 |
)
|
71 |
|
72 |
demo.launch()
|
|
|
4 |
import os
|
5 |
import pathlib
|
6 |
|
|
|
7 |
def greet(input1, input2):
|
|
|
|
|
|
|
8 |
|
9 |
+
modo = "video"
|
10 |
+
print("Inicio: Estamos en modo ", modo)
|
11 |
|
12 |
+
print("Input1:")
|
13 |
+
print(input1)
|
14 |
+
print("Input2:")
|
15 |
+
print(input2)
|
16 |
|
17 |
+
path_video = input2
|
18 |
+
path_parts = path_video.split("\\")
|
19 |
+
# Imprimimos todos los segmentos EXCEPTO el último
|
20 |
+
# Obtenemos todos los segmentos de la dirección separados por "\"
|
21 |
+
path_bueno = "\\".join(path_parts[0:len(path_parts) - 2])
|
22 |
|
23 |
+
print("Path bueno:")
|
24 |
+
print(path_bueno)
|
25 |
+
|
26 |
+
files = os.listdir(path_bueno)
|
27 |
+
print("Estos son los files que hay:")
|
28 |
+
print(files)
|
29 |
+
|
30 |
+
time.sleep(10)
|
31 |
+
|
32 |
+
ext_imagen = "png"
|
33 |
+
ext_video = "mp4"
|
34 |
+
|
35 |
+
#Selector de modo.
|
36 |
+
if modo == "video":
|
37 |
+
print("Se asigno la extensión de video:", ext_video)
|
38 |
+
extension = ext_video
|
39 |
+
else:
|
40 |
+
print("Se asigno la extensión de video:", ext_video)
|
41 |
+
extension = ext_imagen
|
42 |
+
|
43 |
+
#El source siempre es una imagen.
|
44 |
+
source_path = "source.png"
|
45 |
+
target_path = "target." + extension
|
46 |
+
result_path = "result." + extension
|
47 |
+
|
48 |
+
#La primera siempre será una imagen, por eso no entra en el modo selector.
|
49 |
source_image = Image.fromarray(input1)
|
50 |
print("Esto es source_image: ", source_image)
|
51 |
source_image.save(source_path)
|
52 |
+
|
53 |
+
#Aquí trabajaremos solo el target.
|
54 |
+
if modo == "video":
|
55 |
+
#Para Video
|
56 |
+
target_path = input2
|
57 |
+
else:
|
58 |
+
#Es decir si es modo imagen
|
59 |
+
#Para Imagenes
|
60 |
+
target_image = Image.fromarray(input2)
|
61 |
+
print("Esto es target_image: ", target_image)
|
62 |
+
target_image.save(target_path)
|
63 |
|
64 |
+
print("Después de los selectores de modo los paths quedaron así:")
|
65 |
print("source_path: ", source_path)
|
66 |
print("target_path: ", target_path)
|
67 |
|
68 |
+
command = f"python run.py -s {source_path} -t {target_path} -o {result_path} --frame-processor face_swapper"
|
|
|
|
|
|
|
|
|
|
|
69 |
print(command)
|
70 |
time.sleep(1)
|
71 |
proc = os.popen(command)
|
72 |
output = proc.read()
|
73 |
|
74 |
+
print("Output (resultado de la ejecución del código):")
|
75 |
+
time.sleep(2)
|
76 |
print(output)
|
77 |
+
print("Terminó la impresión del output...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
|
79 |
+
if modo == "video":
|
80 |
+
#Para video
|
81 |
+
path = pathlib.Path("result.mp4")
|
82 |
+
return path, path
|
83 |
+
else:
|
84 |
+
#Para imagen
|
85 |
+
path = pathlib.Path("result.png")
|
86 |
+
return path, path
|
87 |
+
|
88 |
#Así para imagenes
|
89 |
# demo = gr.Interface(
|
90 |
+
# fn=greet, inputs=[gr.Image(), gr.Image()], outputs=[gr.Image(), gr.Image()]
|
91 |
# )
|
92 |
|
93 |
#Así para video
|
94 |
demo = gr.Interface(
|
95 |
+
fn=greet, inputs=[gr.Image(), gr.Video()], outputs=[gr.Video(), gr.Video()]
|
96 |
)
|
97 |
|
98 |
demo.launch()
|
local-filename.jpg
ADDED
retriever.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import http.cookiejar
|
2 |
+
import urllib
|
3 |
+
|
4 |
+
cookiejar = http.cookiejar.CookieJar()
|
5 |
+
|
6 |
+
cookie_handler = urllib.request.HTTPCookieProcessor(cookiejar)
|
7 |
+
|
8 |
+
# Abra la URL en su navegador para generar la cookie necesaria.
|
9 |
+
|
10 |
+
# Copie la cookie desde su navegador.
|
11 |
+
|
12 |
+
cookie_value = "eyJhbGciOiJFZERTQSJ9.eyJyZWFkIjp0cnVlLCJvbkJlaGFsZk9mIjp7Il9pZCI6IjYzZTNjYTVmYzY1Zjk3NWI0MzZlMzM2NCIsInVzZXIiOiJNb2liZSJ9LCJpYXQiOjE3MDUyMjIwMTksInN1YiI6Ii9zcGFjZXMvTW9pYmUvdmlkZW8iLCJleHAiOjE3MDUzMDg0MTksImlzcyI6Imh0dHBzOi8vaHVnZ2luZ2ZhY2UuY28ifQ.haEkPgrbQZ0TEAiOGH5_C-LVpbtL_K6d5pys2HjXlc-zb6M30iGJh79cRmBrM2VqPehfODhXfdD8TLtq_VI0DA"
|
13 |
+
|
14 |
+
cookie_value = bytes(cookie_value, "utf-8")
|
15 |
+
|
16 |
+
url = "https://moibe-video.hf.space/--replicas/rzjof/file=/tmp/gradio/24ac48bd3028fc69e1c09d7f9819c6435e1326c5/temp/stockings/0015.png"
|
17 |
+
|
18 |
+
request = urllib.request.Request(url)
|
19 |
+
|
20 |
+
request.add_header("Cookie", cookie_value)
|
21 |
+
|
22 |
+
opener = urllib.request.build_opener(cookie_handler)
|
23 |
+
|
24 |
+
urllib.request.install_opener(opener)
|
25 |
+
|
26 |
+
urllib.request.urlretrieve(request, "local-filename.jpg")
|