Spaces:
Running
on
L40S
Running
on
L40S
import gradio as gr | |
import torch | |
from huggingface_hub import hf_hub_download | |
from gradio_tabs.animation import animation | |
from gradio_tabs.vid_edit import vid_edit | |
from gradio_tabs.img_edit import img_edit | |
from networks.generator import Generator | |
# Optimize torch.compile performance | |
torch.set_float32_matmul_precision('high') # Enable TensorFloat32 for better performance | |
torch._dynamo.config.cache_size_limit = 64 # Increase cache size to reduce recompilations | |
device = torch.device("cuda") | |
gen = Generator(size=512, motion_dim=40, scale=2).to(device) | |
ckpt_path = hf_hub_download(repo_id="YaohuiW/LIA-X", filename="lia-x.pt") | |
gen.load_state_dict(torch.load(ckpt_path, weights_only=True)) | |
gen.eval() | |
chunk_size=16 | |
def load_file(path): | |
with open(path, 'r', encoding='utf-8') as f: | |
content = f.read() | |
return content | |
custom_css = """ | |
<style> | |
body { | |
font-family: Georgia, serif; /* Change to your desired font */ | |
} | |
h1 { | |
color: black; /* Change title color */ | |
} | |
</style> | |
""" | |
with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo: | |
gr.HTML(load_file("assets/title.md")) | |
with gr.Row(): | |
with gr.Accordion(open=False, label="Instruction"): | |
gr.Markdown(load_file("assets/instruction.md")) | |
with gr.Row(): | |
with gr.Tabs(): | |
#animation(gen, chunk_size, device) | |
# for this demo, let's only showcase img_edit | |
img_edit(gen, device) | |
#vid_edit(gen, chunk_size, device) | |
demo.launch(allowed_paths=["./data/source","./data/driving"]) | |