rahul7star commited on
Commit
12a63af
Β·
verified Β·
1 Parent(s): b5529e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -31
app.py CHANGED
@@ -1,34 +1,55 @@
1
- import gradio as gr
2
  import torch
3
- from diffusers import DiffusionPipeline
4
-
5
- # Load the WAN 2.1 T2V Model
6
-
7
- from diffusers import DiffusionPipeline
8
-
9
- from diffusers import DiffusionPipeline
10
-
11
- from diffusers import DiffusionPipeline
12
-
13
- from diffusers import DiffusionPipeline
14
-
15
- pipe = DiffusionPipeline.from_pretrained("sarthak247/Wan2.1-T2V-1.3B-nf4")
16
-
17
- prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
18
- image = pipe(prompt).images[0]
19
- def generate_image(prompt):
20
- """Generates an image from text prompt using WAN 2.1"""
21
- image = pipe(prompt).images[0]
22
- return image
23
-
24
- # Create Gradio UI
25
- interface = gr.Interface(
26
- fn=generate_image,
27
- inputs=gr.Textbox(label="Enter Prompt"),
28
- outputs=gr.Image(label="Generated Image"),
29
- title="WAN 2.1 - Text-to-Image Generation",
30
- description="Generate images from text using WAN 2.1 T2V model."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  )
32
 
33
- # Launch the app
34
- interface.launch()
 
 
1
  import torch
2
+ import gradio as gr
3
+ import imageio
4
+ import os
5
+ from safetensors.torch import load_file
6
+ from torchvision import transforms
7
+ from PIL import Image
8
+ import numpy as np
9
+
10
+ # Define model path (assuming it's in the HF Space)
11
+ MODEL_PATH = "sarthak247/Wan2.1-T2V-1.3B-nf4"
12
+ MODEL_FILE = f"{MODEL_PATH}/diffusion_pytorch_model.safetensors"
13
+
14
+ # Load model weights manually
15
+ device = "cuda" if torch.cuda.is_available() else "cpu"
16
+ print(f"Loading model on {device}...")
17
+
18
+ try:
19
+ model_weights = load_file(MODEL_FILE, device=device)
20
+ print("Model loaded successfully!")
21
+ except Exception as e:
22
+ print(f"Error loading model: {e}")
23
+ model_weights = None
24
+
25
+ # Placeholder function - Replace with actual inference logic
26
+ def generate_video(prompt):
27
+ """
28
+ Generates a placeholder video using the model.
29
+ Replace this function with the actual inference logic once available.
30
+ """
31
+ if model_weights is None:
32
+ return "Model failed to load. Please check the logs."
33
+
34
+ # Simulate an image output (Replace this with actual video frame generation)
35
+ img = Image.new("RGB", (512, 512), color="black")
36
+ transform = transforms.ToTensor()
37
+ frame = (transform(img).permute(1, 2, 0).numpy() * 255).astype(np.uint8)
38
+
39
+ # Create a fake video with repeated frames
40
+ frames = [frame] * 16 # 16 repeated frames (Replace with actual video frames)
41
+ output_path = "output.mp4"
42
+ imageio.mimsave(output_path, frames, fps=8)
43
+
44
+ return output_path
45
+
46
+ # Gradio UI
47
+ iface = gr.Interface(
48
+ fn=generate_video,
49
+ inputs=gr.Textbox(label="Enter Text Prompt"),
50
+ outputs=gr.Video(label="Generated Video"),
51
+ title="Wan2.1-T2V-1.3B Video Generation",
52
+ description="This app loads the model manually and generates text-to-video output."
53
  )
54
 
55
+ iface.launch()