lalashechka commited on
Commit
578b424
1 Parent(s): c9c13e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -22
app.py CHANGED
@@ -48,19 +48,20 @@ def animate_img(encoded_string, model):
48
  _ = 1/0
49
  print("f_1")
50
  except:
51
- print("2")
52
- client1 = Client(url_hg1)
53
- result1 = client1.predict(encoded_string, api_name="/resize_image")
54
- client = Client(url_hg1)
55
- result = client.predict(result1, 0, True, 1, 15, api_name="/video")
56
- res = result[0]['video']
57
- print("s_2")
58
- return res
 
59
 
60
- if model == "AnimateDiff":
61
- client = Client(url_hg2)
62
- result = client.predict(encoded_string, "zoom-out", api_name="/predict")
63
- return result
64
 
65
 
66
  def create_video(prompt, model):
@@ -84,12 +85,10 @@ def create_video(prompt, model):
84
  base64_string = photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '')
85
 
86
  image_bytes = base64.b64decode(base64_string)
87
- with tempfile.NamedTemporaryFile(delete=False) as temp:
88
  temp.write(image_bytes)
89
  temp_file_path = temp.name
90
  print("cs_1")
91
-
92
-
93
  except:
94
  print("c_2")
95
  with closing(create_connection(f"{url_sd4}", timeout=120)) as conn:
@@ -103,7 +102,7 @@ def create_video(prompt, model):
103
  base64_string = photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '')
104
 
105
  image_bytes = base64.b64decode(base64_string)
106
- with tempfile.NamedTemporaryFile(delete=False) as temp:
107
  temp.write(image_bytes)
108
  temp_file_path = temp.name
109
  print("cs_2")
@@ -133,11 +132,12 @@ def create_video(prompt, model):
133
  else:
134
  _ = 1/0
135
  except:
136
- client1 = Client("https://emmadrex-stable-video-diffusion.hf.space")
137
- result1 = client1.predict(encoded_string, api_name="/resize_image")
138
- client = Client("https://emmadrex-stable-video-diffusion.hf.space")
139
- result = client.predict(result1, 0, True, 1, 15, api_name="/video")
140
- return result[0]['video']
 
141
 
142
 
143
 
@@ -307,7 +307,7 @@ with gr.Blocks(css=css) as demo:
307
  prompt = gr.Textbox(placeholder="Введите описание видео...", show_label=True, label='Описание:', lines=3)
308
  # motion1 = gr.Dropdown(value="Приближение →←", interactive=True, show_label=True, label="Движение камеры:", choices=["Приближение →←", "Отдаление ←→", "Вверх ↑", "Вниз ↓", "Влево ←", "Вправо →", "По часовой стрелке ⟳", "Против часовой стрелки ⟲"])
309
  model = gr.Radio(interactive=True, value="Stable Video Diffusion", show_label=True,
310
- label="Модель нейросети:", choices=['Stable Video Diffusion', 'AnimateDiff'])
311
  with gr.Column():
312
  text_button = gr.Button("Сгенерировать видео", variant='primary', elem_id="generate")
313
  with gr.Column():
 
48
  _ = 1/0
49
  print("f_1")
50
  except:
51
+ return None
52
+ #print("2")
53
+ #client1 = Client(url_hg1)
54
+ #result1 = client1.predict(encoded_string, api_name="/resize_image")
55
+ #client = Client(url_hg1)
56
+ #result = client.predict(result1, 0, True, 1, 15, api_name="/video")
57
+ #res = result[0]['video']
58
+ #print("s_2")
59
+ #return res
60
 
61
+ #if model == "AnimateDiff":
62
+ # client = Client(url_hg2)
63
+ # result = client.predict(encoded_string, "zoom-out", api_name="/predict")
64
+ # return result
65
 
66
 
67
  def create_video(prompt, model):
 
85
  base64_string = photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '')
86
 
87
  image_bytes = base64.b64decode(base64_string)
88
+ with tempfile.NamedTemporaryFile(delete=True) as temp:
89
  temp.write(image_bytes)
90
  temp_file_path = temp.name
91
  print("cs_1")
 
 
92
  except:
93
  print("c_2")
94
  with closing(create_connection(f"{url_sd4}", timeout=120)) as conn:
 
102
  base64_string = photo.replace('data:image/jpeg;base64,', '').replace('data:image/png;base64,', '')
103
 
104
  image_bytes = base64.b64decode(base64_string)
105
+ with tempfile.NamedTemporaryFile(delete=True) as temp:
106
  temp.write(image_bytes)
107
  temp_file_path = temp.name
108
  print("cs_2")
 
132
  else:
133
  _ = 1/0
134
  except:
135
+ return None
136
+ #client1 = Client("https://emmadrex-stable-video-diffusion.hf.space")
137
+ #result1 = client1.predict(encoded_string, api_name="/resize_image")
138
+ #client = Client("https://emmadrex-stable-video-diffusion.hf.space")
139
+ #result = client.predict(result1, 0, True, 1, 15, api_name="/video")
140
+ #return result[0]['video']
141
 
142
 
143
 
 
307
  prompt = gr.Textbox(placeholder="Введите описание видео...", show_label=True, label='Описание:', lines=3)
308
  # motion1 = gr.Dropdown(value="Приближение →←", interactive=True, show_label=True, label="Движение камеры:", choices=["Приближение →←", "Отдаление ←→", "Вверх ↑", "Вниз ↓", "Влево ←", "Вправо →", "По часовой стрелке ⟳", "Против часовой стрелки ⟲"])
309
  model = gr.Radio(interactive=True, value="Stable Video Diffusion", show_label=True,
310
+ label="Модель нейросети:", choices=['Stable Video Diffusion'])
311
  with gr.Column():
312
  text_button = gr.Button("Сгенерировать видео", variant='primary', elem_id="generate")
313
  with gr.Column():