Update gradio_app.py
Browse files- gradio_app.py +17 -2
gradio_app.py
CHANGED
@@ -2,6 +2,8 @@ import torch
|
|
2 |
import imageio
|
3 |
import os
|
4 |
import gradio as gr
|
|
|
|
|
5 |
from diffusers.schedulers import EulerAncestralDiscreteScheduler
|
6 |
from transformers import T5EncoderModel, T5Tokenizer
|
7 |
from allegro.pipelines.pipeline_allegro import AllegroPipeline
|
@@ -29,6 +31,8 @@ if not is_shared_ui:
|
|
29 |
local_dir=weights_dir,
|
30 |
)
|
31 |
|
|
|
|
|
32 |
|
33 |
def single_inference(user_prompt, save_path, guidance_scale, num_sampling_steps, seed, enable_cpu_offload):
|
34 |
dtype = torch.bfloat16
|
@@ -184,21 +188,32 @@ with gr.Blocks(css=css) as demo:
|
|
184 |
</p>
|
185 |
</div>
|
186 |
''', elem_id="warning-duplicate")
|
|
|
187 |
else:
|
188 |
if(is_gpu_associated):
|
189 |
-
submit_btn = gr.Button("Generate Video", visible=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
else:
|
191 |
top_description = gr.HTML(f'''
|
192 |
<div class="gr-prose">
|
193 |
<h2><svg xmlns="http://www.w3.org/2000/svg" width="18px" height="18px" style="margin-right: 0px;display: inline-block;"fill="none"><path fill="#fff" d="M7 13.2a6.3 6.3 0 0 0 4.4-10.7A6.3 6.3 0 0 0 .6 6.9 6.3 6.3 0 0 0 7 13.2Z"/><path fill="#fff" fill-rule="evenodd" d="M7 0a6.9 6.9 0 0 1 4.8 11.8A6.9 6.9 0 0 1 0 7 6.9 6.9 0 0 1 7 0Zm0 0v.7V0ZM0 7h.6H0Zm7 6.8v-.6.6ZM13.7 7h-.6.6ZM9.1 1.7c-.7-.3-1.4-.4-2.2-.4a5.6 5.6 0 0 0-4 1.6 5.6 5.6 0 0 0-1.6 4 5.6 5.6 0 0 0 1.6 4 5.6 5.6 0 0 0 4 1.7 5.6 5.6 0 0 0 4-1.7 5.6 5.6 0 0 0 1.7-4 5.6 5.6 0 0 0-1.7-4c-.5-.5-1.1-.9-1.8-1.2Z" clip-rule="evenodd"/><path fill="#000" fill-rule="evenodd" d="M7 2.9a.8.8 0 1 1 0 1.5A.8.8 0 0 1 7 3ZM5.8 5.7c0-.4.3-.6.6-.6h.7c.3 0 .6.2.6.6v3.7h.5a.6.6 0 0 1 0 1.3H6a.6.6 0 0 1 0-1.3h.4v-3a.6.6 0 0 1-.6-.7Z" clip-rule="evenodd"/></svg>
|
194 |
You have successfully duplicated the Allegro Video Generation Space π</h2>
|
195 |
-
<p>There's only one step left before you can generate a video: <a href="https://huggingface.co/spaces/{os.environ['SPACE_ID']}/settings" style="text-decoration: underline" target="_blank">attribute a GPU</b> to it (via the Settings tab)</a>.
|
196 |
You will be billed by the minute from when you activate the GPU until when it is turned off.</p>
|
197 |
<p class="actions">
|
198 |
<a href="https://huggingface.co/spaces/{os.environ['SPACE_ID']}/settings">π₯ Set recommended GPU</a>
|
199 |
</p>
|
200 |
</div>
|
201 |
''', elem_id="warning-setgpu")
|
|
|
202 |
|
203 |
with gr.Column():
|
204 |
video_output=gr.Video(label="Generated Video")
|
|
|
2 |
import imageio
|
3 |
import os
|
4 |
import gradio as gr
|
5 |
+
import subprocess
|
6 |
+
from subprocess import getoutput
|
7 |
from diffusers.schedulers import EulerAncestralDiscreteScheduler
|
8 |
from transformers import T5EncoderModel, T5Tokenizer
|
9 |
from allegro.pipelines.pipeline_allegro import AllegroPipeline
|
|
|
31 |
local_dir=weights_dir,
|
32 |
)
|
33 |
|
34 |
+
if is_gpu_associated:
|
35 |
+
gpu_info = getoutput('nvidia-smi')
|
36 |
|
37 |
def single_inference(user_prompt, save_path, guidance_scale, num_sampling_steps, seed, enable_cpu_offload):
|
38 |
dtype = torch.bfloat16
|
|
|
188 |
</p>
|
189 |
</div>
|
190 |
''', elem_id="warning-duplicate")
|
191 |
+
submit_btn = gr.Button("Generate Video", visible=False)
|
192 |
else:
|
193 |
if(is_gpu_associated):
|
194 |
+
submit_btn = gr.Button("Generate Video", visible=True)
|
195 |
+
top_description = gr.HTML(f'''
|
196 |
+
<div class="gr-prose">
|
197 |
+
<h2><svg xmlns="http://www.w3.org/2000/svg" width="18px" height="18px" style="margin-right: 0px;display: inline-block;"fill="none"><path fill="#fff" d="M7 13.2a6.3 6.3 0 0 0 4.4-10.7A6.3 6.3 0 0 0 .6 6.9 6.3 6.3 0 0 0 7 13.2Z"/><path fill="#fff" fill-rule="evenodd" d="M7 0a6.9 6.9 0 0 1 4.8 11.8A6.9 6.9 0 0 1 0 7 6.9 6.9 0 0 1 7 0Zm0 0v.7V0ZM0 7h.6H0Zm7 6.8v-.6.6ZM13.7 7h-.6.6ZM9.1 1.7c-.7-.3-1.4-.4-2.2-.4a5.6 5.6 0 0 0-4 1.6 5.6 5.6 0 0 0-1.6 4 5.6 5.6 0 0 0 1.6 4 5.6 5.6 0 0 0 4 1.7 5.6 5.6 0 0 0 4-1.7 5.6 5.6 0 0 0 1.7-4 5.6 5.6 0 0 0-1.7-4c-.5-.5-1.1-.9-1.8-1.2Z" clip-rule="evenodd"/><path fill="#000" fill-rule="evenodd" d="M7 2.9a.8.8 0 1 1 0 1.5A.8.8 0 0 1 7 3ZM5.8 5.7c0-.4.3-.6.6-.6h.7c.3 0 .6.2.6.6v3.7h.5a.6.6 0 0 1 0 1.3H6a.6.6 0 0 1 0-1.3h.4v-3a.6.6 0 0 1-.6-.7Z" clip-rule="evenodd"/></svg>
|
198 |
+
You have successfully associated a {gpu_info} GPU to this Space π</h2>
|
199 |
+
<p>
|
200 |
+
You can now generate a video! You will be billed by the minute from when you activated the GPU until when it is turned off.
|
201 |
+
</p>
|
202 |
+
</div>
|
203 |
+
''', elem_id="warning-ready")
|
204 |
else:
|
205 |
top_description = gr.HTML(f'''
|
206 |
<div class="gr-prose">
|
207 |
<h2><svg xmlns="http://www.w3.org/2000/svg" width="18px" height="18px" style="margin-right: 0px;display: inline-block;"fill="none"><path fill="#fff" d="M7 13.2a6.3 6.3 0 0 0 4.4-10.7A6.3 6.3 0 0 0 .6 6.9 6.3 6.3 0 0 0 7 13.2Z"/><path fill="#fff" fill-rule="evenodd" d="M7 0a6.9 6.9 0 0 1 4.8 11.8A6.9 6.9 0 0 1 0 7 6.9 6.9 0 0 1 7 0Zm0 0v.7V0ZM0 7h.6H0Zm7 6.8v-.6.6ZM13.7 7h-.6.6ZM9.1 1.7c-.7-.3-1.4-.4-2.2-.4a5.6 5.6 0 0 0-4 1.6 5.6 5.6 0 0 0-1.6 4 5.6 5.6 0 0 0 1.6 4 5.6 5.6 0 0 0 4 1.7 5.6 5.6 0 0 0 4-1.7 5.6 5.6 0 0 0 1.7-4 5.6 5.6 0 0 0-1.7-4c-.5-.5-1.1-.9-1.8-1.2Z" clip-rule="evenodd"/><path fill="#000" fill-rule="evenodd" d="M7 2.9a.8.8 0 1 1 0 1.5A.8.8 0 0 1 7 3ZM5.8 5.7c0-.4.3-.6.6-.6h.7c.3 0 .6.2.6.6v3.7h.5a.6.6 0 0 1 0 1.3H6a.6.6 0 0 1 0-1.3h.4v-3a.6.6 0 0 1-.6-.7Z" clip-rule="evenodd"/></svg>
|
208 |
You have successfully duplicated the Allegro Video Generation Space π</h2>
|
209 |
+
<p>There's only one step left before you can generate a video: we recommend to <a href="https://huggingface.co/spaces/{os.environ['SPACE_ID']}/settings" style="text-decoration: underline" target="_blank">attribute a L40S GPU</b> to it (via the Settings tab)</a>.
|
210 |
You will be billed by the minute from when you activate the GPU until when it is turned off.</p>
|
211 |
<p class="actions">
|
212 |
<a href="https://huggingface.co/spaces/{os.environ['SPACE_ID']}/settings">π₯ Set recommended GPU</a>
|
213 |
</p>
|
214 |
</div>
|
215 |
''', elem_id="warning-setgpu")
|
216 |
+
submit_btn = gr.Button("Generate Video", visible=False)
|
217 |
|
218 |
with gr.Column():
|
219 |
video_output=gr.Video(label="Generated Video")
|