thomson99 commited on
Commit
ef7c6f6
·
verified ·
1 Parent(s): a0f0c39

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -34
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
- num_frames = max(int(duration / 2), 1) # نقلل عدد الإطارات للأداء
37
 
38
- print(f"جاري توليد {num_frames} إطار...")
 
 
 
 
 
 
 
 
 
 
39
 
40
- for i in range(num_frames):
41
- print(f"توليد الإطار {i+1}/{num_frames}")
42
- # توليد صورة باستخدام Stability AI
43
- answers = stability_api.generate(
44
- prompt=text_prompt,
45
- seed=int(time.time()), # رقم عشوائي لكل صورة
46
- steps=30,
47
- cfg_scale=8.0,
48
- width=512,
49
- height=512,
50
- samples=1,
51
- sampler=generation.SAMPLER_K_DPMPP_2M
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="وصف الفيديو", placeholder="اكتب وصفاً للفيديو الذي تريد إنشاءه..."),
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
  )