rahul7star commited on
Commit
8e49b64
Β·
verified Β·
1 Parent(s): aab7d3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -29
app.py CHANGED
@@ -1,35 +1,28 @@
1
  import torch
2
- import gradio as gr
3
- from diffusers import StableDiffusionPipeline
 
4
 
5
- # Load model manually from Hugging Face model hub or your uploaded files
6
- model_path = "sarthak247/Wan2.1-T2V-1.3B-nf4" # Replace with your model path
7
- pipe = StableDiffusionPipeline.from_pretrained(model_path, torch_dtype=torch.float16)
8
- pipe.to("cuda") # If running on GPU
 
 
9
 
10
- def generate_video(prompt):
11
- """
12
- Generates a video from the provided prompt using the pre-loaded model.
13
- """
14
- try:
15
- # Generate video using the model pipeline
16
- video = pipe(prompt).videos[0] # Assuming output is a video tensor
17
-
18
- # Return the generated video
19
- return video
20
 
21
- except Exception as e:
22
- print(f"Error during video generation: {e}")
23
- return "Error generating video"
24
 
25
- # Gradio UI for video generation
26
- iface = gr.Interface(
27
- fn=generate_video,
28
- inputs=gr.Textbox(label="Enter Text Prompt"),
29
- outputs=gr.Video(label="Generated Video"),
30
- title="Text-to-Video Generation with Wan2.1-T2V",
31
- description="This app generates a video based on the text prompt using the Wan2.1-T2V model."
32
- )
33
 
34
- # Launch the Gradio app
35
- iface.launch()
 
 
 
 
 
 
 
 
1
  import torch
2
+ from diffusers.utils import export_to_video
3
+ from diffusers import AutoencoderKLWan, WanPipeline
4
+ from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepScheduler
5
 
6
+ model_id = "Wan-AI/Wan2.1-T2V-14B-Diffusers"
7
+ vae = AutoencoderKLWan.from_pretrained(model_id, subfolder="vae", torch_dtype=torch.float32)
8
+ pipe = WanPipeline.from_pretrained(model_id, vae=vae, torch_dtype=torch.bfloat16)
9
+ flow_shift = 3.0 # 5.0 for 720P, 3.0 for 480P
10
+ pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config, flow_shift=flow_shift)
11
+ pipe.to("cuda")
12
 
13
+ pipe.load_lora_weights("NIVEDAN/wan2.1-lora")
 
 
 
 
 
 
 
 
 
14
 
15
+ pipe.enable_model_cpu_offload() #for low-vram environments
 
 
16
 
17
+ prompt = "nivedan"
18
+ negative_prompt = "Bright tones, overexposed, static, blurred details, subtitles, style, works, paintings, images, static, overall gray, worst quality, low quality, JPEG compression residue, ugly, incomplete, extra fingers, poorly drawn hands, poorly drawn faces, deformed, disfigured, misshapen limbs, fused fingers, still picture, messy background, three legs, many people in the background, walking backwards"
 
 
 
 
 
 
19
 
20
+ output = pipe(
21
+ prompt=prompt,
22
+ negative_prompt=negative_prompt,
23
+ height=480,
24
+ width=832,
25
+ num_frames=81,
26
+ guidance_scale=5.0,
27
+ ).frames[0]
28
+ export_to_video(output, "output.mp4", fps=16)