Spaces:
Runtime error
Runtime error
Delete GenVideo_app.py
Browse files- GenVideo_app.py +0 -158
GenVideo_app.py
DELETED
|
@@ -1,158 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
|
| 3 |
-
import gradio as gr
|
| 4 |
-
from gradio_imageslider import ImageSlider
|
| 5 |
-
import argparse
|
| 6 |
-
from SUPIR.util import HWC3, upscale_image, fix_resize, convert_dtype
|
| 7 |
-
import numpy as np
|
| 8 |
-
import torch
|
| 9 |
-
from SUPIR.util import create_SUPIR_model, load_QF_ckpt
|
| 10 |
-
from PIL import Image
|
| 11 |
-
from llava.llava_agent import LLavaAgent
|
| 12 |
-
from CKPT_PTH import LLAVA_MODEL_PATH
|
| 13 |
-
import einops
|
| 14 |
-
import copy
|
| 15 |
-
import time
|
| 16 |
-
import spaces
|
| 17 |
-
from huggingface_hub import hf_hub_download
|
| 18 |
-
|
| 19 |
-
from diffusers import AnimateDiffPipeline, DDIMScheduler, MotionAdapter
|
| 20 |
-
from diffusers.utils import export_to_gif
|
| 21 |
-
from diffusers.utils import export_to_video
|
| 22 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 23 |
-
import uuid
|
| 24 |
-
|
| 25 |
-
hf_hub_download(repo_id="laion/CLIP-ViT-bigG-14-laion2B-39B-b160k", filename="open_clip_pytorch_model.bin", local_dir="laion_CLIP-ViT-bigG-14-laion2B-39B-b160k")
|
| 26 |
-
hf_hub_download(repo_id="camenduru/SUPIR", filename="sd_xl_base_1.0_0.9vae.safetensors", local_dir="yushan777_SUPIR")
|
| 27 |
-
hf_hub_download(repo_id="camenduru/SUPIR", filename="SUPIR-v0F.ckpt", local_dir="yushan777_SUPIR")
|
| 28 |
-
hf_hub_download(repo_id="camenduru/SUPIR", filename="SUPIR-v0Q.ckpt", local_dir="yushan777_SUPIR")
|
| 29 |
-
hf_hub_download(repo_id="RunDiffusion/Juggernaut-XL-Lightning", filename="Juggernaut_RunDiffusionPhoto2_Lightning_4Steps.safetensors", local_dir="RunDiffusion_Juggernaut-XL-Lightning")
|
| 30 |
-
|
| 31 |
-
parser = argparse.ArgumentParser()
|
| 32 |
-
parser.add_argument("--opt", type=str, default='options/SUPIR_v0.yaml')
|
| 33 |
-
parser.add_argument("--ip", type=str, default='127.0.0.1')
|
| 34 |
-
parser.add_argument("--port", type=int, default='6688')
|
| 35 |
-
parser.add_argument("--no_llava", action='store_true', default=False)
|
| 36 |
-
parser.add_argument("--use_image_slider", action='store_true', default=False)
|
| 37 |
-
parser.add_argument("--log_history", action='store_true', default=False)
|
| 38 |
-
parser.add_argument("--loading_half_params", action='store_true', default=False)
|
| 39 |
-
parser.add_argument("--use_tile_vae", action='store_true', default=False)
|
| 40 |
-
parser.add_argument("--encoder_tile_size", type=int, default=512)
|
| 41 |
-
parser.add_argument("--decoder_tile_size", type=int, default=64)
|
| 42 |
-
parser.add_argument("--load_8bit_llava", action='store_true', default=False)
|
| 43 |
-
args = parser.parse_args()
|
| 44 |
-
server_ip = args.ip
|
| 45 |
-
server_port = args.port
|
| 46 |
-
use_llava = not args.no_llava
|
| 47 |
-
|
| 48 |
-
if torch.cuda.device_count() > 0:
|
| 49 |
-
if torch.cuda.device_count() >= 2:
|
| 50 |
-
SUPIR_device = 'cuda:0'
|
| 51 |
-
LLaVA_device = 'cuda:1'
|
| 52 |
-
elif torch.cuda.device_count() == 1:
|
| 53 |
-
SUPIR_device = 'cuda:0'
|
| 54 |
-
LLaVA_device = 'cuda:0'
|
| 55 |
-
else:
|
| 56 |
-
SUPIR_device = 'cpu'
|
| 57 |
-
LLaVA_device = 'cpu'
|
| 58 |
-
|
| 59 |
-
# load SUPIR
|
| 60 |
-
model, default_setting = create_SUPIR_model(args.opt, SUPIR_sign='Q', load_default_setting=True)
|
| 61 |
-
if args.loading_half_params:
|
| 62 |
-
model = model.half()
|
| 63 |
-
if args.use_tile_vae:
|
| 64 |
-
model.init_tile_vae(encoder_tile_size=args.encoder_tile_size, decoder_tile_size=args.decoder_tile_size)
|
| 65 |
-
model = model.to(SUPIR_device)
|
| 66 |
-
model.first_stage_model.denoise_encoder_s1 = copy.deepcopy(model.first_stage_model.denoise_encoder)
|
| 67 |
-
model.current_model = 'v0-Q'
|
| 68 |
-
ckpt_Q, ckpt_F = load_QF_ckpt(args.opt)
|
| 69 |
-
|
| 70 |
-
# load LLaVA
|
| 71 |
-
#if use_llava:
|
| 72 |
-
#llava_agent = LLavaAgent(LLAVA_MODEL_PATH, device=LLaVA_device, load_8bit=args.load_8bit_llava, load_4bit=False)
|
| 73 |
-
#else:
|
| 74 |
-
#llava_agent = None
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
# Available adapters (replace with your actual adapter names)
|
| 78 |
-
adapter_options = {
|
| 79 |
-
"zoom-out":"guoyww/animatediff-motion-lora-zoom-out",
|
| 80 |
-
"zoom-in":"guoyww/animatediff-motion-lora-zoom-in",
|
| 81 |
-
"pan-left":"guoyww/animatediff-motion-lora-pan-left",
|
| 82 |
-
"pan-right":"guoyww/animatediff-motion-lora-pan-right",
|
| 83 |
-
"roll-clockwise":"guoyww/animatediff-motion-lora-rolling-clockwise",
|
| 84 |
-
"roll-anticlockwise":"guoyww/animatediff-motion-lora-rolling-anticlockwise",
|
| 85 |
-
"tilt-up":"guoyww/animatediff-motion-lora-tilt-up",
|
| 86 |
-
"tilt-down":"guoyww/animatediff-motion-lora-tilt-down"
|
| 87 |
-
}
|
| 88 |
-
|
| 89 |
-
def load_cached_examples():
|
| 90 |
-
examples = [
|
| 91 |
-
["a cat playing with a ball of yarn", "blurry", 7.5, 12, ["zoom-in"]],
|
| 92 |
-
["a dog running in a field", "dark, indoors", 8.0, 8, ["pan-left", "tilt-up"]],
|
| 93 |
-
]
|
| 94 |
-
return examples
|
| 95 |
-
|
| 96 |
-
device = "cuda"
|
| 97 |
-
adapter = MotionAdapter.from_pretrained("guoyww/animatediff-motion-adapter-v1-5-2", torch_dtype=torch.float16)
|
| 98 |
-
model_id = "SG161222/Realistic_Vision_V5.1_noVAE"
|
| 99 |
-
|
| 100 |
-
pipe = AnimateDiffPipeline.from_pretrained(model_id, motion_adapter=adapter, torch_dtype=torch.float16).to(device)
|
| 101 |
-
scheduler = DDIMScheduler.from_pretrained(
|
| 102 |
-
model_id,
|
| 103 |
-
subfolder="scheduler",
|
| 104 |
-
clip_sample=False,
|
| 105 |
-
timestep_spacing="linspace",
|
| 106 |
-
beta_schedule="linear",
|
| 107 |
-
steps_offset=1,
|
| 108 |
-
)
|
| 109 |
-
pipe.scheduler = scheduler
|
| 110 |
-
|
| 111 |
-
@spaces.GPU
|
| 112 |
-
def generate_video(prompt,negative_prompt, guidance_scale, num_inference_steps, adapter_choices):
|
| 113 |
-
|
| 114 |
-
pipe.to(device)
|
| 115 |
-
|
| 116 |
-
# Set adapters based on user selection
|
| 117 |
-
if adapter_choices:
|
| 118 |
-
for i in range(len(adapter_choices)):
|
| 119 |
-
adapter_name = adapter_choices[i]
|
| 120 |
-
pipe.load_lora_weights(
|
| 121 |
-
adapter_options[adapter_name], adapter_name=adapter_name,
|
| 122 |
-
)
|
| 123 |
-
pipe.set_adapters(adapter_choices, adapter_weights=[1.0] * len(adapter_choices))
|
| 124 |
-
print(adapter_choices)
|
| 125 |
-
|
| 126 |
-
output = pipe(
|
| 127 |
-
prompt=prompt,
|
| 128 |
-
negative_prompt=negative_prompt,
|
| 129 |
-
num_frames=16,
|
| 130 |
-
guidance_scale=guidance_scale,
|
| 131 |
-
num_inference_steps=num_inference_steps,
|
| 132 |
-
)
|
| 133 |
-
name = str(uuid.uuid4()).replace("-", "")
|
| 134 |
-
path = f"/tmp/{name}.mp4"
|
| 135 |
-
export_to_video(output.frames[0], path, fps=10)
|
| 136 |
-
return path
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
iface = gr.Interface(
|
| 141 |
-
theme=gr.themes.Soft(primary_hue="cyan", secondary_hue="teal"),
|
| 142 |
-
fn=generate_video,
|
| 143 |
-
inputs=[
|
| 144 |
-
gr.Textbox(label="Prompt"),
|
| 145 |
-
gr.Textbox(label="Negative Prompt"),
|
| 146 |
-
gr.Slider(minimum=0.5, maximum=10, value=7.5, label="Guidance Scale"),
|
| 147 |
-
gr.Slider(minimum=4, maximum=24, step=4, value=4, label="Inference Steps"),
|
| 148 |
-
gr.CheckboxGroup(adapter_options.keys(), label="Adapter Choice",type='value'),
|
| 149 |
-
],
|
| 150 |
-
outputs=gr.Video(label="Generated Video"),
|
| 151 |
-
examples = [
|
| 152 |
-
["Urban ambiance, man walking, neon lights, rain, wet floor, high quality", "bad quality", 7.5, 24, []],
|
| 153 |
-
["Nature, farms, mountains in background, drone shot, high quality","bad quality" ,8.0, 24, []],
|
| 154 |
-
],
|
| 155 |
-
cache_examples=True
|
| 156 |
-
)
|
| 157 |
-
|
| 158 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|