lalashechka commited on
Commit
9c88c69
1 Parent(s): 3b4ef39

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -3
app.py CHANGED
@@ -15,7 +15,28 @@ import random
15
  import tempfile
16
 
17
 
18
- def flip_text(prompt, motion):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  try:
20
  language = detect(prompt)
21
  if language == 'ru':
@@ -68,7 +89,9 @@ def flip_text(prompt, motion):
68
  break
69
 
70
 
71
- def flip_text2(encoded_string, prompt, motion):
 
 
72
 
73
  url_video_g = os.getenv("url_video_g")
74
  url_video_c = os.getenv("url_video_c")
@@ -126,6 +149,8 @@ def flip_text2(encoded_string, prompt, motion):
126
  break
127
 
128
 
 
 
129
  css = """
130
  #generate {
131
  width: 100%;
@@ -166,7 +191,7 @@ with gr.Blocks(css=css) as demo:
166
  text_button2 = gr.Button("Анимировать изображение", variant='primary', elem_id="generate")
167
  with gr.Column():
168
  video_output2 = gr.Video(show_label=True, label='Результат:', type="file")
169
- text_button2.click(flip_text2, inputs=[prompt2, prompt12, motion2], outputs=video_output2)
170
 
171
  demo.queue(concurrency_count=12)
172
  demo.launch()
 
15
  import tempfile
16
 
17
 
18
+ def animate_img(encoded_string):
19
+ r = requests.post("https://stable-video-diffusion.com/api/upload", files={"file": open(encoded_string, 'rb')})
20
+ print(r.text)
21
+ hash_ = r.json()['hash']
22
+ time.sleep(10)
23
+ while True:
24
+ r2 = requests.get(f"https://stable-video-diffusion.com/result?hash={hash_}")
25
+ source_string = r2.text
26
+ if "Generation has been in progress for" in source_string:
27
+ time.sleep(10)
28
+ continue
29
+ if "Generation has been in progress for" not in source_string:
30
+ pattern = r'https://storage.stable-video-diffusion.com/([a-f0-9]{32})\.mp4'
31
+ matches = re.findall(pattern, source_string)
32
+ sd_video = []
33
+ for match in matches:
34
+ sd_video.append(f"https://storage.stable-video-diffusion.com/{match}.mp4")
35
+ print(sd_video[0])
36
+ return sd_video[0]
37
+
38
+
39
+ def flip_text1(prompt, motion):
40
  try:
41
  language = detect(prompt)
42
  if language == 'ru':
 
89
  break
90
 
91
 
92
+
93
+
94
+ def flip_text21(encoded_string, prompt, motion):
95
 
96
  url_video_g = os.getenv("url_video_g")
97
  url_video_c = os.getenv("url_video_c")
 
149
  break
150
 
151
 
152
+
153
+
154
  css = """
155
  #generate {
156
  width: 100%;
 
191
  text_button2 = gr.Button("Анимировать изображение", variant='primary', elem_id="generate")
192
  with gr.Column():
193
  video_output2 = gr.Video(show_label=True, label='Результат:', type="file")
194
+ text_button2.click(animate_img, inputs=[prompt2], outputs=video_output2)
195
 
196
  demo.queue(concurrency_count=12)
197
  demo.launch()