lalashechka commited on
Commit
feb87be
1 Parent(s): 21d4393

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -1
app.py CHANGED
@@ -37,7 +37,68 @@ def animate_img(encoded_string):
37
  return sd_video[0]
38
 
39
 
40
- def flip_text(prompt, motion):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  try:
42
  language = detect(prompt)
43
  if language == 'ru':
@@ -92,6 +153,7 @@ def flip_text(prompt, motion):
92
 
93
 
94
 
 
95
  def flip_text2(encoded_string, prompt, motion):
96
 
97
  url_video_g = os.getenv("url_video_g")
@@ -152,6 +214,7 @@ def flip_text2(encoded_string, prompt, motion):
152
 
153
 
154
 
 
155
  css = """
156
  #generate {
157
  width: 100%;
 
37
  return sd_video[0]
38
 
39
 
40
+ def create_video(prompt):
41
+ url_sd3 = os.getenv("url_sd3")
42
+ url_sd4 = os.getenv("url_sd4")
43
+
44
+ try:
45
+ with closing(create_connection(f"{url_sd3}", timeout=60)) as conn:
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:
49
+ status = json.loads(conn.recv())['msg']
50
+ if status == 'estimation':
51
+ continue
52
+ if status == 'process_starts':
53
+ break
54
+ photo = json.loads(conn.recv())['output']['data'][0][0]
55
+ base64_string = photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '')
56
+
57
+ image_bytes = base64.b64decode(base64_string)
58
+ with tempfile.NamedTemporaryFile(delete=False) as temp:
59
+ temp.write(image_bytes)
60
+ temp_file_path = temp.name
61
+
62
+ except:
63
+ with closing(create_connection(f"{url_sd4}", timeout=60)) as conn:
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()
67
+ conn.recv()
68
+ conn.recv()
69
+ conn.recv()
70
+ photo = json.loads(conn.recv())['output']['data'][0]
71
+ photo = photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '')
72
+
73
+ image_bytes = base64.b64decode(base64_string)
74
+ with tempfile.NamedTemporaryFile(delete=False) as temp:
75
+ temp.write(image_bytes)
76
+ temp_file_path = temp.name
77
+
78
+
79
+ r = requests.post("https://stable-video-diffusion.com/api/upload", files={"file": open(temp_file_path, 'rb')})
80
+ print(r.text)
81
+ hash_ = r.json()['hash']
82
+ time.sleep(10)
83
+ while True:
84
+ r2 = requests.get(f"https://stable-video-diffusion.com/result?hash={hash_}")
85
+ source_string = r2.text
86
+ if "Generation has been in progress for" in source_string:
87
+ time.sleep(10)
88
+ continue
89
+ if "Generation has been in progress for" not in source_string:
90
+ pattern = r'https://storage.stable-video-diffusion.com/([a-f0-9]{32})\.mp4'
91
+ matches = re.findall(pattern, source_string)
92
+ sd_video = []
93
+ for match in matches:
94
+ sd_video.append(f"https://storage.stable-video-diffusion.com/{match}.mp4")
95
+ print(sd_video[0])
96
+ return sd_video[0]
97
+
98
+
99
+
100
+
101
+ def flip_text1(prompt, motion):
102
  try:
103
  language = detect(prompt)
104
  if language == 'ru':
 
153
 
154
 
155
 
156
+
157
  def flip_text2(encoded_string, prompt, motion):
158
 
159
  url_video_g = os.getenv("url_video_g")
 
214
 
215
 
216
 
217
+
218
  css = """
219
  #generate {
220
  width: 100%;