ans42 commited on
Commit
0b5dad4
·
verified ·
1 Parent(s): 6a71934

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -0
app.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from diffusers import DiffusionPipeline
4
+ from diffusers.utils import export_to_video
5
+ import os
6
+
7
+ # تنزيل النموذج المخصص لتحويل النص إلى فيديو (بجودة ممتازة متوافقة مع كولاب)
8
+ print("جاري تحميل النموذج... قد يستغرق هذا بضع دقائق في المرة الأولى.")
9
+ pipe = DiffusionPipeline.from_pretrained("cerspense/zeroscope_v2_576w", torch_dtype=torch.float16)
10
+ # تفريغ الذاكرة تلقائياً لتجنب توقف كولاب بسبب نفاد الرامات
11
+ pipe.enable_model_cpu_offload()
12
+
13
+ def generate_video(prompt, negative_prompt, steps):
14
+ try:
15
+ # إعدادات توليد الفيديو
16
+ video_frames = pipe(
17
+ prompt,
18
+ negative_prompt=negative_prompt,
19
+ num_inference_steps=int(steps),
20
+ height=320,
21
+ width=576,
22
+ num_frames=24 # عدد الإطارات (يحدد طول الفيديو)
23
+ ).frames[0]
24
+
25
+ # حفظ الفيديو
26
+ output_path = "output_video.mp4"
27
+ export_to_video(video_frames, output_path)
28
+ return output_path
29
+ except Exception as e:
30
+ return f"حدث خطأ: {str(e)}"
31
+
32
+ # تصميم واجهة المستخدم (مظهر احترافي وجميل)
33
+ custom_theme = gr.themes.Soft(
34
+ primary_hue="blue",
35
+ secondary_hue="indigo",
36
+ ).set(
37
+ button_primary_background_fill="*primary_500",
38
+ button_primary_background_fill_hover="*primary_600",
39
+ )
40
+
41
+ with gr.Blocks(theme=custom_theme, title="أداة محمد الصرماني") as demo:
42
+ gr.HTML(
43
+ """
44
+ <div style="text-align: center; padding: 20px; background-color: #1e1e2f; color: white; border-radius: 10px; margin-bottom: 20px;">
45
+ <h1 style="color: #4da6ff; margin: 0;">🎥 أداة محمد الصرماني من ليبيا 🇱🇾</h1>
46
+ <p style="font-size: 16px; margin-top: 5px;">لتحويل النصوص إلى فيديوهات عالية الدقة باستخدام الذكاء الاصطناعي</p>
47
+ </div>
48
+ """
49
+ )
50
+
51
+ with gr.Row():
52
+ with gr.Column(scale=1):
53
+ prompt = gr.Textbox(label="وصف الفيديو (يفضل باللغة الإنجليزية لأفضل نتيجة)", placeholder="مثال: A cinematic shot of a futuristic city at night, neon lights...", lines=3)
54
+ negative_prompt = gr.Textbox(label="الأشياء التي لا تريدها في الفيديو (اختياري)", placeholder="مثال: blurry, low quality, distorted", value="blurry, distorted, low quality, bad anatomy")
55
+ steps = gr.Slider(minimum=20, maximum=50, value=30, step=1, label="جودة المعالجة (رقم أكبر = جودة أفضل ووقت أطول)")
56
+
57
+ generate_btn = gr.Button("🚀 بدء توليد الفيديو", variant="primary", size="lg")
58
+
59
+ with gr.Column(scale=1):
60
+ video_output = gr.Video(label="الفيديو النهائي (بصيغة MP4)")
61
+
62
+ # ربط الزر بدالة التوليد
63
+ generate_btn.click(
64
+ fn=generate_video,
65
+ inputs=[prompt, negative_prompt, steps],
66
+ outputs=video_output
67
+ )
68
+
69
+ # تشغيل الواجهة وتوليد رابط Gradio.live
70
+ demo.launch(share=True, debug=True)