Spaces:
Runtime error
Runtime error
import gradio as gr | |
from text_to_video import model_t2v_fun,setup_seed | |
from omegaconf import OmegaConf | |
import torch | |
import imageio | |
import os | |
import cv2 | |
import torchvision | |
config_path = "./base/configs/sample.yaml" | |
args = OmegaConf.load("./base/configs/sample.yaml") | |
device = "cuda" if torch.cuda.is_available() else "cpu" | |
# ------- get model --------------- | |
model_t2V = model_t2v_fun(args) | |
model_t2V.to(device) | |
if device == "cuda": | |
model_t2V.enable_xformers_memory_efficient_attention() | |
# model_t2V.enable_xformers_memory_efficient_attention() | |
css = """ | |
h1 { | |
text-align: center; | |
} | |
#component-0 { | |
max-width: 730px; | |
margin: auto; | |
} | |
""" | |
def infer(prompt, seed_inp, ddim_steps): | |
setup_seed(seed_inp) | |
videos = model_t2V(prompt, video_length=16, height = 320, width= 512, num_inference_steps=ddim_steps, guidance_scale=7).video | |
print(videos[0].shape) | |
if not os.path.exists(args.output_folder): | |
os.mkdir(args.output_folder) | |
torchvision.io.write_video(args.output_folder + prompt.replace(' ', '_') + '-.mp4', videos[0], fps=8) | |
# imageio.mimwrite(args.output_folder + prompt.replace(' ', '_') + '.mp4', videos[0], fps=8) | |
# video = cv2.VideoCapture(args.output_folder + prompt.replace(' ', '_') + '.mp4') | |
# video = imageio.get_reader(args.output_folder + prompt.replace(' ', '_') + '.mp4', 'ffmpeg') | |
# video = model_t2V(prompt, seed_inp, ddim_steps) | |
return args.output_folder + prompt.replace(' ', '_') + '-.mp4' | |
print(1) | |
# def clean(): | |
# return gr.Image.update(value=None, visible=False), gr.Video.update(value=None) | |
def clean(): | |
return gr.Video.update(value=None) | |
title = """ | |
<div style="text-align: center; max-width: 700px; margin: 0 auto;"> | |
<div | |
style=" | |
display: inline-flex; | |
align-items: center; | |
gap: 0.8rem; | |
font-size: 1.75rem; | |
" | |
> | |
<h1 style="font-weight: 900; margin-bottom: 7px; margin-top: 5px;"> | |
Intern路Vchitect (Text-to-Video) | |
</h1> | |
</div> | |
<p style="margin-bottom: 10px; font-size: 94%"> | |
Apply Intern路Vchitect to generate a video | |
</p> | |
</div> | |
""" | |
# print(1) | |
with gr.Blocks(css='style.css') as demo: | |
gr.Markdown("<font color=red size=10><center>LaVie</center></font>") | |
with gr.Row(elem_id="col-container"): | |
with gr.Column(): | |
prompt = gr.Textbox(value="a teddy bear walking on the street", label="Prompt", placeholder="enter prompt", show_label=True, elem_id="prompt-in", min_width=200, lines=2) | |
ddim_steps = gr.Slider(label='Steps', minimum=50, maximum=300, value=50, step=1) | |
seed_inp = gr.Slider(label="Seed", minimum=0, maximum=2147483647, step=1, value=400, elem_id="seed-in") | |
# with gr.Row(): | |
# # control_task = gr.Dropdown(label="Task", choices=["Text-2-video", "Image-2-video"], value="Text-2-video", multiselect=False, elem_id="controltask-in") | |
# ddim_steps = gr.Slider(label='Steps', minimum=50, maximum=300, value=250, step=1) | |
# seed_inp = gr.Slider(label="Seed", minimum=0, maximum=2147483647, step=1, value=123456, elem_id="seed-in") | |
# ddim_steps = gr.Slider(label='Steps', minimum=50, maximum=300, value=250, step=1) | |
with gr.Column(): | |
submit_btn = gr.Button("Generate video") | |
clean_btn = gr.Button("Clean video") | |
# submit_btn = gr.Button("Generate video", size='sm') | |
# video_out = gr.Video(label="Video result", elem_id="video-output", height=320, width=512) | |
video_out = gr.Video(label="Video result", elem_id="video-output") | |
# with gr.Row(): | |
# video_out = gr.Video(label="Video result", elem_id="video-output", height=320, width=512) | |
# submit_btn = gr.Button("Generate video", size='sm') | |
# video_out = gr.Video(label="Video result", elem_id="video-output", height=320, width=512) | |
inputs = [prompt, seed_inp, ddim_steps] | |
outputs = [video_out] | |
# control_task.change(change_task_options, inputs=[control_task], outputs=[canny_opt, hough_opt, normal_opt], queue=False) | |
# submit_btn.click(clean, inputs=[], outputs=[video_out], queue=False) | |
clean_btn.click(clean, inputs=[], outputs=[video_out], queue=False) | |
submit_btn.click(infer, inputs, outputs) | |
# share_button.click(None, [], [], _js=share_js) | |
print(2) | |
demo.queue(max_size=12).launch(server_name="0.0.0.0", server_port=7860) | |