kader1997 commited on
Commit
3a28f40
·
verified ·
1 Parent(s): 41bfaac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -31
app.py CHANGED
@@ -32,60 +32,52 @@ def step_2_render_video(video_path, df_edited):
32
  if video_path is None or df_edited is None or df_edited.empty:
33
  return None, "بيانات ناقصة."
34
 
35
- output_path = "output_pro.mp4"
36
  video = VideoFileClip(video_path)
37
  w, h = int(video.w), int(video.h)
38
  clips = [video]
39
  words_list = df_edited.values.tolist()
40
 
41
- chunk_size = 3 # عدد الكلمات في المجموعة
42
 
43
- for i in range(len(words_list)):
44
- # تحديد المجموعة (الجملة)
45
- start_chunk = (i // chunk_size) * chunk_size
46
- end_chunk = min(start_chunk + chunk_size, len(words_list))
47
- current_chunk = words_list[start_chunk:end_chunk]
48
-
49
- # بناء الجملة
50
  sentence = " ".join([str(r[0]) for r in current_chunk])
51
- clean_sentence = process_arabic_text(sentence)
52
 
53
- # توقيت المجموعة الكاملة
54
  c_start = float(current_chunk[0][1])
55
  c_end = float(current_chunk[-1][2])
 
56
 
57
- # 1. طبقة الجملة اللون الأصفر) - تظهر طوال مدة المجموعة
58
- bg_clip = TextClip(
59
  text=clean_sentence,
60
- font_size=80,
61
- color='yellow',
62
  stroke_color='black',
63
  stroke_width=2,
64
  method='caption',
65
  font=FONT_PATH,
66
  size=(int(w * 0.9), None),
67
  text_align='center'
68
- ).with_start(c_start).with_duration(c_end - c_start).with_position(('center', int(h * 0.75)))
69
 
70
- # 2. طبقة "الكلمة النشطة" (باللون الأبيض) - تضيء فوق الجملة في وقتها المحدد
71
- active_clip = TextClip(
72
- text=clean_sentence,
73
- font_size=80,
74
- color='white',
75
- stroke_color='black',
76
- stroke_width=2,
77
- method='caption',
78
- font=FONT_PATH,
79
- size=(int(w * 0.9), None),
80
- text_align='center'
81
- ).with_start(float(words_list[i][1])).with_duration(max(0.1, float(words_list[i][2]) - float(words_list[i][1]))).with_position(('center', int(h * 0.75)))
82
 
83
- clips.append(bg_clip)
84
- clips.append(active_clip)
 
 
85
 
86
  final_video = CompositeVideoClip(clips, size=(w, h))
87
  final_video.write_videofile(output_path, codec="libx264", audio_codec="aac", fps=video.fps)
88
- return output_path, "تم إنتاج الفيديو بنمط احترافي!"
89
 
90
  # --- بناء الواجهة (تصحيح ربط المخرجات) ---
91
  with gr.Blocks() as app:
 
32
  if video_path is None or df_edited is None or df_edited.empty:
33
  return None, "بيانات ناقصة."
34
 
35
+ output_path = "animated_pro_video.mp4"
36
  video = VideoFileClip(video_path)
37
  w, h = int(video.w), int(video.h)
38
  clips = [video]
39
  words_list = df_edited.values.tolist()
40
 
41
+ chunk_size = 3
42
 
43
+ for i in range(0, len(words_list), chunk_size):
44
+ # تحديد المجموعة (3 كلمات)
45
+ current_chunk = words_list[i : i + chunk_size]
 
 
 
 
46
  sentence = " ".join([str(r[0]) for r in current_chunk])
47
+ clean_sentence = reshape(sentence) + "\n "
48
 
 
49
  c_start = float(current_chunk[0][1])
50
  c_end = float(current_chunk[-1][2])
51
+ duration = c_end - c_start
52
 
53
+ # إنشاء النص الأساسي
54
+ txt_clip = TextClip(
55
  text=clean_sentence,
56
+ font_size=90, # كبرنا الخط قليلاً للأنيميشن
57
+ color='yellow', # لون ثابت كما طلبت
58
  stroke_color='black',
59
  stroke_width=2,
60
  method='caption',
61
  font=FONT_PATH,
62
  size=(int(w * 0.9), None),
63
  text_align='center'
64
+ ).with_start(c_start).with_duration(duration).with_position(('center', int(h * 0.75)))
65
 
66
+ # --- إضافة الأنيميشن (Pop-up Effect) ---
67
+ # هذه الدالة تجعل النص يبدأ من حجم 0.8 ويصل لـ 1.0 في أول 0.1 ثانية
68
+ def zoom(t):
69
+ if t < 0.1:
70
+ return 0.8 + 2 * t # تكبير سريع في البداية
71
+ return 1.0
 
 
 
 
 
 
72
 
73
+ # تطبيق الأنيميشن على الكليب
74
+ animated_txt = txt_clip.image_transform(lambda img, t: img.resize(zoom(t)))
75
+
76
+ clips.append(animated_txt)
77
 
78
  final_video = CompositeVideoClip(clips, size=(w, h))
79
  final_video.write_videofile(output_path, codec="libx264", audio_codec="aac", fps=video.fps)
80
+ return output_path, "تم إنتاج الفيديو بأنيميشن محترف!"
81
 
82
  # --- بناء الواجهة (تصحيح ربط المخرجات) ---
83
  with gr.Blocks() as app: