Update app.py
Browse files
app.py
CHANGED
@@ -25,7 +25,6 @@ import gc
|
|
25 |
import csv
|
26 |
from datetime import datetime
|
27 |
from openai import OpenAI
|
28 |
-
#from gradio import themes
|
29 |
|
30 |
torch.backends.cuda.matmul.allow_tf32 = False
|
31 |
torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction = False
|
@@ -34,7 +33,7 @@ torch.backends.cudnn.allow_tf32 = False
|
|
34 |
torch.backends.cudnn.deterministic = False
|
35 |
#torch.backends.cudnn.benchmark = False
|
36 |
torch.backends.cuda.preferred_blas_library="cublas"
|
37 |
-
torch.backends.cuda.preferred_linalg_library="cusolver"
|
38 |
|
39 |
torch.set_float32_matmul_precision("highest")
|
40 |
|
@@ -67,9 +66,10 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
67 |
|
68 |
request_log = []
|
69 |
|
70 |
-
clip_model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32", cache_dir=model_path).to(
|
71 |
clip_processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32", cache_dir=model_path)
|
72 |
|
|
|
73 |
def compute_clip_embedding(text=None, image=None):
|
74 |
"""
|
75 |
Compute CLIP embedding for a given text or image.
|
@@ -218,7 +218,7 @@ vae = load_vae(vae_dir)
|
|
218 |
unet = load_unet(unet_dir)
|
219 |
scheduler = load_scheduler(scheduler_dir)
|
220 |
patchifier = SymmetricPatchifier(patch_size=1)
|
221 |
-
text_encoder = T5EncoderModel.from_pretrained("PixArt-alpha/PixArt-XL-2-1024-MS", subfolder="text_encoder").to(
|
222 |
tokenizer = T5Tokenizer.from_pretrained("PixArt-alpha/PixArt-XL-2-1024-MS", subfolder="tokenizer")
|
223 |
|
224 |
pipeline = XoraVideoPipeline(
|
@@ -228,7 +228,7 @@ pipeline = XoraVideoPipeline(
|
|
228 |
tokenizer=tokenizer,
|
229 |
scheduler=scheduler,
|
230 |
vae=vae,
|
231 |
-
).to(
|
232 |
|
233 |
@spaces.GPU(duration=90) # Dynamic duration
|
234 |
def generate_video_from_text_90(
|
@@ -319,7 +319,7 @@ def generate_video_from_image_90(
|
|
319 |
frame_rate=20,
|
320 |
seed=random.randint(0, MAX_SEED),
|
321 |
num_inference_steps=35,
|
322 |
-
guidance_scale=
|
323 |
height=768,
|
324 |
width=768,
|
325 |
num_frames=60,
|
@@ -356,7 +356,7 @@ def generate_video_from_image_90(
|
|
356 |
"media_items": media_items,
|
357 |
}
|
358 |
|
359 |
-
generator = torch.Generator(device="
|
360 |
|
361 |
def gradio_progress_callback(self, step, timestep, kwargs):
|
362 |
progress((step + 1) / num_inference_steps)
|
@@ -394,16 +394,18 @@ def generate_video_from_image_90(
|
|
394 |
f"An error occurred while generating the video. Please try again. Error: {e}",
|
395 |
duration=5,
|
396 |
)
|
|
|
397 |
finally:
|
398 |
torch.cuda.empty_cache()
|
399 |
gc.collect()
|
|
|
400 |
return output_path
|
401 |
|
402 |
def create_advanced_options():
|
403 |
with gr.Accordion("Step 4: Advanced Options (Optional)", open=False):
|
404 |
seed = gr.Slider(label="4.1 Seed", minimum=0, maximum=1000000, step=1, value=646373)
|
405 |
inference_steps = gr.Slider(label="4.2 Inference Steps", minimum=5, maximum=150, step=5, value=40)
|
406 |
-
guidance_scale = gr.Slider(label="4.3 Guidance Scale", minimum=1.0, maximum=10.0, step=0.1, value=
|
407 |
|
408 |
height_slider = gr.Slider(
|
409 |
label="4.4 Height",
|
@@ -440,7 +442,7 @@ def create_advanced_options():
|
|
440 |
]
|
441 |
|
442 |
# Define the Gradio interface with tabs
|
443 |
-
with gr.Blocks(theme=gr.themes.
|
444 |
with gr.Row(elem_id="title-row"):
|
445 |
gr.Markdown(
|
446 |
"""
|
@@ -697,4 +699,4 @@ with gr.Blocks(theme=gr.themes.Glass()) as iface:
|
|
697 |
)
|
698 |
|
699 |
if __name__ == "__main__":
|
700 |
-
iface.queue(max_size=64, default_concurrency_limit=1, api_open=False).launch(share=True, show_api=False)
|
|
|
25 |
import csv
|
26 |
from datetime import datetime
|
27 |
from openai import OpenAI
|
|
|
28 |
|
29 |
torch.backends.cuda.matmul.allow_tf32 = False
|
30 |
torch.backends.cuda.matmul.allow_bf16_reduced_precision_reduction = False
|
|
|
33 |
torch.backends.cudnn.deterministic = False
|
34 |
#torch.backends.cudnn.benchmark = False
|
35 |
torch.backends.cuda.preferred_blas_library="cublas"
|
36 |
+
#torch.backends.cuda.preferred_linalg_library="cusolver"
|
37 |
|
38 |
torch.set_float32_matmul_precision("highest")
|
39 |
|
|
|
66 |
|
67 |
request_log = []
|
68 |
|
69 |
+
clip_model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32", cache_dir=model_path).to(device)
|
70 |
clip_processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32", cache_dir=model_path)
|
71 |
|
72 |
+
|
73 |
def compute_clip_embedding(text=None, image=None):
|
74 |
"""
|
75 |
Compute CLIP embedding for a given text or image.
|
|
|
218 |
unet = load_unet(unet_dir)
|
219 |
scheduler = load_scheduler(scheduler_dir)
|
220 |
patchifier = SymmetricPatchifier(patch_size=1)
|
221 |
+
text_encoder = T5EncoderModel.from_pretrained("PixArt-alpha/PixArt-XL-2-1024-MS", subfolder="text_encoder").to(device)
|
222 |
tokenizer = T5Tokenizer.from_pretrained("PixArt-alpha/PixArt-XL-2-1024-MS", subfolder="tokenizer")
|
223 |
|
224 |
pipeline = XoraVideoPipeline(
|
|
|
228 |
tokenizer=tokenizer,
|
229 |
scheduler=scheduler,
|
230 |
vae=vae,
|
231 |
+
).to(device)
|
232 |
|
233 |
@spaces.GPU(duration=90) # Dynamic duration
|
234 |
def generate_video_from_text_90(
|
|
|
319 |
frame_rate=20,
|
320 |
seed=random.randint(0, MAX_SEED),
|
321 |
num_inference_steps=35,
|
322 |
+
guidance_scale=3.2,
|
323 |
height=768,
|
324 |
width=768,
|
325 |
num_frames=60,
|
|
|
356 |
"media_items": media_items,
|
357 |
}
|
358 |
|
359 |
+
generator = torch.Generator(device="cpu").manual_seed(seed)
|
360 |
|
361 |
def gradio_progress_callback(self, step, timestep, kwargs):
|
362 |
progress((step + 1) / num_inference_steps)
|
|
|
394 |
f"An error occurred while generating the video. Please try again. Error: {e}",
|
395 |
duration=5,
|
396 |
)
|
397 |
+
|
398 |
finally:
|
399 |
torch.cuda.empty_cache()
|
400 |
gc.collect()
|
401 |
+
|
402 |
return output_path
|
403 |
|
404 |
def create_advanced_options():
|
405 |
with gr.Accordion("Step 4: Advanced Options (Optional)", open=False):
|
406 |
seed = gr.Slider(label="4.1 Seed", minimum=0, maximum=1000000, step=1, value=646373)
|
407 |
inference_steps = gr.Slider(label="4.2 Inference Steps", minimum=5, maximum=150, step=5, value=40)
|
408 |
+
guidance_scale = gr.Slider(label="4.3 Guidance Scale", minimum=1.0, maximum=10.0, step=0.1, value=3.2)
|
409 |
|
410 |
height_slider = gr.Slider(
|
411 |
label="4.4 Height",
|
|
|
442 |
]
|
443 |
|
444 |
# Define the Gradio interface with tabs
|
445 |
+
with gr.Blocks(theme=gr.themes.Soft()) as iface:
|
446 |
with gr.Row(elem_id="title-row"):
|
447 |
gr.Markdown(
|
448 |
"""
|
|
|
699 |
)
|
700 |
|
701 |
if __name__ == "__main__":
|
702 |
+
iface.queue(max_size=64, default_concurrency_limit=1, api_open=False).launch(share=True, show_api=False)
|