Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -32,41 +32,37 @@ def create_video_from_text(text_prompt, duration=10, fps=30, resolution="480p"):
|
|
| 32 |
else: # 1080p
|
| 33 |
size = (1920, 1080)
|
| 34 |
|
| 35 |
-
# توليد
|
| 36 |
-
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
for
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
for resp in answers:
|
| 55 |
-
for artifact in resp.artifacts:
|
| 56 |
-
if artifact.finish_reason == generation.FILTER:
|
| 57 |
-
raise ValueError("المحتوى غير مناسب، يرجى تعديل الوصف")
|
| 58 |
-
if artifact.type == generation.ARTIFACT_IMAGE:
|
| 59 |
-
img = Image.open(io.BytesIO(artifact.binary))
|
| 60 |
-
# تحويل حجم الصورة
|
| 61 |
-
img = img.resize(size, Image.LANCZOS)
|
| 62 |
-
# تحويل الصورة إلى مصفوفة numpy
|
| 63 |
-
frame = np.array(img)
|
| 64 |
-
# تكرار الإطار عدة مرات للحصول على فيديو أنعم
|
| 65 |
-
for _ in range(int(fps * 2)): # كل صورة تتكرر لمدة 2 ثواني
|
| 66 |
-
frames.append(frame)
|
| 67 |
|
| 68 |
if not frames:
|
| 69 |
-
raise ValueError("لم يتم توليد
|
| 70 |
|
| 71 |
print("جاري إنشاء الفيديو...")
|
| 72 |
|
|
@@ -109,13 +105,13 @@ def video_generator(text_prompt, duration=10, resolution="480p"):
|
|
| 109 |
iface = gr.Interface(
|
| 110 |
fn=video_generator,
|
| 111 |
inputs=[
|
| 112 |
-
gr.Textbox(label="وصف ال
|
| 113 |
gr.Slider(minimum=5, maximum=30, value=10, step=5, label="مدة الفيديو (بالثواني)"),
|
| 114 |
gr.Radio(["480p", "720p", "1080p"], label="دقة الفيديو", value="480p")
|
| 115 |
],
|
| 116 |
outputs=gr.Video(label="الفيديو المُنشأ"),
|
| 117 |
-
title="مولد الفيديو بالذكاء الاصطناعي",
|
| 118 |
-
description="قم بإدخال وصف لل
|
| 119 |
theme="huggingface",
|
| 120 |
cache_examples=False
|
| 121 |
)
|
|
|
|
| 32 |
else: # 1080p
|
| 33 |
size = (1920, 1080)
|
| 34 |
|
| 35 |
+
# توليد صورة واحدة فقط
|
| 36 |
+
print("جاري توليد الصورة...")
|
| 37 |
|
| 38 |
+
# توليد صورة باستخدام Stability AI
|
| 39 |
+
answers = stability_api.generate(
|
| 40 |
+
prompt=text_prompt,
|
| 41 |
+
seed=int(time.time()), # رقم عشوائي
|
| 42 |
+
steps=30,
|
| 43 |
+
cfg_scale=8.0,
|
| 44 |
+
width=512,
|
| 45 |
+
height=512,
|
| 46 |
+
samples=1,
|
| 47 |
+
sampler=generation.SAMPLER_K_DPMPP_2M
|
| 48 |
+
)
|
| 49 |
|
| 50 |
+
for resp in answers:
|
| 51 |
+
for artifact in resp.artifacts:
|
| 52 |
+
if artifact.finish_reason == generation.FILTER:
|
| 53 |
+
raise ValueError("المحتوى غير مناسب، يرجى تعديل الوصف")
|
| 54 |
+
if artifact.type == generation.ARTIFACT_IMAGE:
|
| 55 |
+
img = Image.open(io.BytesIO(artifact.binary))
|
| 56 |
+
# تحويل حجم الصورة
|
| 57 |
+
img = img.resize(size, Image.LANCZOS)
|
| 58 |
+
# تحويل الصورة إلى مصفوفة numpy
|
| 59 |
+
frame = np.array(img)
|
| 60 |
+
# تكرار نفس الإطار لمدة الفيديو
|
| 61 |
+
total_frames = int(duration * fps)
|
| 62 |
+
frames = [frame] * total_frames
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
if not frames:
|
| 65 |
+
raise ValueError("لم يتم توليد الصورة")
|
| 66 |
|
| 67 |
print("جاري إنشاء الفيديو...")
|
| 68 |
|
|
|
|
| 105 |
iface = gr.Interface(
|
| 106 |
fn=video_generator,
|
| 107 |
inputs=[
|
| 108 |
+
gr.Textbox(label="وصف المشهد", placeholder="اكتب وصفاً للمشهد الذي تريد إنشاءه..."),
|
| 109 |
gr.Slider(minimum=5, maximum=30, value=10, step=5, label="مدة الفيديو (بالثواني)"),
|
| 110 |
gr.Radio(["480p", "720p", "1080p"], label="دقة الفيديو", value="480p")
|
| 111 |
],
|
| 112 |
outputs=gr.Video(label="الفيديو المُنشأ"),
|
| 113 |
+
title="مولد الفيديو الثابت بالذكاء الاصطناعي",
|
| 114 |
+
description="قم بإدخال وصف للمشهد وسيقوم النظام بإنشاء فيديو ثابت باستخدام الذكاء الاصطناعي",
|
| 115 |
theme="huggingface",
|
| 116 |
cache_examples=False
|
| 117 |
)
|