|
|
import gradio as gr |
|
|
import torch |
|
|
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler |
|
|
from diffusers.utils import export_to_video |
|
|
import tempfile |
|
|
|
|
|
|
|
|
model_id = "damo-vilab/text-to-video-ms-1.7b" |
|
|
|
|
|
print("جاري تحميل النموذج على CPU...") |
|
|
pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32) |
|
|
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config) |
|
|
pipe.to("cpu") |
|
|
|
|
|
def generate_video(prompt): |
|
|
if not prompt: |
|
|
return None |
|
|
|
|
|
|
|
|
video_frames = pipe( |
|
|
prompt, |
|
|
num_inference_steps=5, |
|
|
num_frames=8, |
|
|
height=256, |
|
|
width=256 |
|
|
).frames[0] |
|
|
|
|
|
|
|
|
temp_file = tempfile.NamedTemporaryFile(suffix='.mp4', delete=False) |
|
|
export_to_video(video_frames, temp_file.name, fps=8) |
|
|
return temp_file.name |
|
|
|
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
gr.Markdown("### 🎥 Light Video Generator (CPU Friendly)") |
|
|
with gr.Row(): |
|
|
input_text = gr.Textbox(label="اكتب الوصف هنا", placeholder="A panda eating bamboo...") |
|
|
btn = gr.Button("إنشاء الفيديو") |
|
|
output_video = gr.Video(label="الفيديو الناتج") |
|
|
|
|
|
btn.click(fn=generate_video, inputs=input_text, outputs=output_video) |
|
|
|
|
|
demo.launch() |
|
|
|