File size: 1,662 Bytes
549d120 3e007a5 549d120 3e007a5 549d120 3e007a5 549d120 87cc2b7 3e007a5 87cc2b7 14d677a 3e007a5 87cc2b7 3e007a5 549d120 3e007a5 87cc2b7 3e007a5 87cc2b7 | 1 2 3 4 5 6 7 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 35 36 37 38 39 40 41 42 43 44 | 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
# إعدادات مخفضة لتناسب سرعة الـ CPU المجاني
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
# واجهة Gradio
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()
|