Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,55 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
import torch
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
from
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
)
|
| 32 |
|
| 33 |
-
|
| 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()
|
|
|