Spaces:
Runtime error
Runtime error
lalashechka
commited on
Commit
•
0e406cc
1
Parent(s):
83a8130
Update app.py
Browse files
app.py
CHANGED
@@ -14,27 +14,37 @@ import os
|
|
14 |
import random
|
15 |
import tempfile
|
16 |
import re
|
|
|
17 |
|
18 |
|
19 |
def animate_img(encoded_string):
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
|
40 |
def create_video(prompt):
|
@@ -42,7 +52,7 @@ def create_video(prompt):
|
|
42 |
url_sd4 = os.getenv("url_sd4")
|
43 |
|
44 |
try:
|
45 |
-
with closing(create_connection(f"{url_sd3}", timeout=
|
46 |
conn.send('{"fn_index":3,"session_hash":""}')
|
47 |
conn.send(f'{{"data":["{prompt}","[deformed | disfigured], poorly drawn, [bad : wrong] anatomy, [extra | missing | floating | disconnected] limb, (mutated hands and fingers), blurry",7.5,"(No style)"],"event_data":null,"fn_index":3,"session_hash":""}}')
|
48 |
while True:
|
@@ -60,7 +70,7 @@ def create_video(prompt):
|
|
60 |
temp_file_path = temp.name
|
61 |
|
62 |
except:
|
63 |
-
with closing(create_connection(f"{url_sd4}", timeout=
|
64 |
conn.send('{"fn_index":0,"session_hash":""}')
|
65 |
conn.send(f'{{"data":["{prompt}","[deformed | disfigured], poorly drawn, [bad : wrong] anatomy, [extra | missing | floating | disconnected] limb, (mutated hands and fingers), blurry","dreamshaperXL10_alpha2.safetensors [c8afe2ef]",30,"DPM++ 2M Karras",7,1024,1024,-1],"event_data":null,"fn_index":0,"session_hash":""}}')
|
66 |
conn.recv()
|
@@ -75,29 +85,35 @@ def create_video(prompt):
|
|
75 |
temp.write(image_bytes)
|
76 |
temp_file_path = temp.name
|
77 |
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
sd_video
|
95 |
-
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
|
99 |
-
|
100 |
-
|
101 |
def flip_text1(prompt, motion):
|
102 |
try:
|
103 |
language = detect(prompt)
|
|
|
14 |
import random
|
15 |
import tempfile
|
16 |
import re
|
17 |
+
from gradio_client import Client
|
18 |
|
19 |
|
20 |
def animate_img(encoded_string):
|
21 |
+
try:
|
22 |
+
r = requests.post("https://stable-video-diffusion.com/api/upload", files={"file": open(encoded_string, 'rb')})
|
23 |
+
print(r.text)
|
24 |
+
hash_ = r.json()['hash']
|
25 |
+
time.sleep(10)
|
26 |
+
c = 0
|
27 |
+
while c < 10:
|
28 |
+
r2 = requests.get(f"https://stable-video-diffusion.com/result?hash={hash_}")
|
29 |
+
source_string = r2.text
|
30 |
+
if "Generation has been in progress for" in source_string:
|
31 |
+
time.sleep(10)
|
32 |
+
c += 1
|
33 |
+
continue
|
34 |
+
if "Generation has been in progress for" not in source_string:
|
35 |
+
pattern = r'https://storage.stable-video-diffusion.com/([a-f0-9]{32})\.mp4'
|
36 |
+
matches = re.findall(pattern, source_string)
|
37 |
+
sd_video = []
|
38 |
+
for match in matches:
|
39 |
+
sd_video.append(f"https://storage.stable-video-diffusion.com/{match}.mp4")
|
40 |
+
print(sd_video[0])
|
41 |
+
return sd_video[0]
|
42 |
+
except:
|
43 |
+
client1 = Client("https://emmadrex-stable-video-diffusion.hf.space/--replicas/c2gnj/")
|
44 |
+
result1 = client1.predict(encoded_string, api_name="/resize_image")
|
45 |
+
client = Client("https://emmadrex-stable-video-diffusion.hf.space/--replicas/c2gnj/")
|
46 |
+
result = client.predict(result1, 0, True, 1, 15, api_name="/video")
|
47 |
+
return result[0]['video']
|
48 |
|
49 |
|
50 |
def create_video(prompt):
|
|
|
52 |
url_sd4 = os.getenv("url_sd4")
|
53 |
|
54 |
try:
|
55 |
+
with closing(create_connection(f"{url_sd3}", timeout=120)) as conn:
|
56 |
conn.send('{"fn_index":3,"session_hash":""}')
|
57 |
conn.send(f'{{"data":["{prompt}","[deformed | disfigured], poorly drawn, [bad : wrong] anatomy, [extra | missing | floating | disconnected] limb, (mutated hands and fingers), blurry",7.5,"(No style)"],"event_data":null,"fn_index":3,"session_hash":""}}')
|
58 |
while True:
|
|
|
70 |
temp_file_path = temp.name
|
71 |
|
72 |
except:
|
73 |
+
with closing(create_connection(f"{url_sd4}", timeout=120)) as conn:
|
74 |
conn.send('{"fn_index":0,"session_hash":""}')
|
75 |
conn.send(f'{{"data":["{prompt}","[deformed | disfigured], poorly drawn, [bad : wrong] anatomy, [extra | missing | floating | disconnected] limb, (mutated hands and fingers), blurry","dreamshaperXL10_alpha2.safetensors [c8afe2ef]",30,"DPM++ 2M Karras",7,1024,1024,-1],"event_data":null,"fn_index":0,"session_hash":""}}')
|
76 |
conn.recv()
|
|
|
85 |
temp.write(image_bytes)
|
86 |
temp_file_path = temp.name
|
87 |
|
88 |
+
try:
|
89 |
+
r = requests.post("https://stable-video-diffusion.com/api/upload", files={"file": open(temp_file_path, 'rb')})
|
90 |
+
print(r.text)
|
91 |
+
hash_ = r.json()['hash']
|
92 |
+
time.sleep(10)
|
93 |
+
c = 0
|
94 |
+
while c < 10:
|
95 |
+
r2 = requests.get(f"https://stable-video-diffusion.com/result?hash={hash_}")
|
96 |
+
source_string = r2.text
|
97 |
+
if "Generation has been in progress for" in source_string:
|
98 |
+
time.sleep(10)
|
99 |
+
c += 1
|
100 |
+
continue
|
101 |
+
if "Generation has been in progress for" not in source_string:
|
102 |
+
pattern = r'https://storage.stable-video-diffusion.com/([a-f0-9]{32})\.mp4'
|
103 |
+
matches = re.findall(pattern, source_string)
|
104 |
+
sd_video = []
|
105 |
+
for match in matches:
|
106 |
+
sd_video.append(f"https://storage.stable-video-diffusion.com/{match}.mp4")
|
107 |
+
print(sd_video[0])
|
108 |
+
return sd_video[0]
|
109 |
+
except:
|
110 |
+
client1 = Client("https://emmadrex-stable-video-diffusion.hf.space/--replicas/c2gnj/")
|
111 |
+
result1 = client1.predict(encoded_string, api_name="/resize_image")
|
112 |
+
client = Client("https://emmadrex-stable-video-diffusion.hf.space/--replicas/c2gnj/")
|
113 |
+
result = client.predict(result1, 0, True, 1, 15, api_name="/video")
|
114 |
+
return result[0]['video']
|
115 |
|
116 |
|
|
|
|
|
117 |
def flip_text1(prompt, motion):
|
118 |
try:
|
119 |
language = detect(prompt)
|