Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,7 +11,6 @@ FONT_PATH = "arialbd.ttf" # تأكد من رفع هذا الملف في مجلد
|
|
| 11 |
model = WhisperModel("large-v3", device="cpu", compute_type="int8")
|
| 12 |
|
| 13 |
def process_arabic_text(text):
|
| 14 |
-
# نستخدم reshape فقط لأن السيرفر يدعم الاتجاه التلقائي
|
| 15 |
return reshape(text) + "\n "
|
| 16 |
|
| 17 |
def step_1_extract_words(video_path):
|
|
@@ -32,26 +31,18 @@ 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 = "
|
| 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 |
-
# دالة الزووم (Pop-up)
|
| 44 |
-
def zoom_effect(t):
|
| 45 |
-
if t < 0.15:
|
| 46 |
-
# تأثير الانبثاق: من 80% إلى 100% من الحجم
|
| 47 |
-
return 0.8 + (1.33 * t)
|
| 48 |
-
return 1.0
|
| 49 |
|
| 50 |
-
print(f"جاري معالجة
|
| 51 |
|
| 52 |
for i in range(0, len(words_list), chunk_size):
|
| 53 |
current_chunk = words_list[i : i + chunk_size]
|
| 54 |
-
# تجميع الكلمات الثلاث في نص واحد
|
| 55 |
sentence = " ".join([str(r[0]) for r in current_chunk])
|
| 56 |
clean_sentence = process_arabic_text(sentence)
|
| 57 |
|
|
@@ -59,10 +50,10 @@ def step_2_render_video(video_path, df_edited):
|
|
| 59 |
c_end = float(current_chunk[-1][2])
|
| 60 |
duration = max(0.1, c_end - c_start)
|
| 61 |
|
| 62 |
-
#
|
| 63 |
txt_clip = TextClip(
|
| 64 |
text=clean_sentence,
|
| 65 |
-
font_size=
|
| 66 |
color='yellow',
|
| 67 |
stroke_color='black',
|
| 68 |
stroke_width=2,
|
|
@@ -71,21 +62,17 @@ def step_2_render_video(video_path, df_edited):
|
|
| 71 |
size=(int(w * 0.9), None),
|
| 72 |
text_align='center'
|
| 73 |
).with_start(c_start).with_duration(duration).with_position(('center', int(h * 0.75)))
|
| 74 |
-
|
| 75 |
-
# 2. تطبيق الأنيميشن مباشرة (Resize)
|
| 76 |
-
animated_txt = txt_clip.resize(zoom_effect)
|
| 77 |
|
| 78 |
-
clips.append(
|
| 79 |
|
| 80 |
-
print("جاري دمج الفيديو النهائي...")
|
| 81 |
final_video = CompositeVideoClip(clips, size=(w, h))
|
| 82 |
final_video.write_videofile(output_path, codec="libx264", audio_codec="aac", fps=video.fps, logger=None)
|
| 83 |
|
| 84 |
-
return output_path, "تم إنتاج الفيديو ب
|
| 85 |
|
| 86 |
# --- بناء الواجهة ---
|
| 87 |
-
with gr.Blocks(title="Caption Pro
|
| 88 |
-
gr.Markdown("# 🎬 Caption Pro -
|
| 89 |
|
| 90 |
with gr.Row():
|
| 91 |
video_in = gr.Video(label="فيديو المدخلات")
|
|
@@ -94,8 +81,8 @@ with gr.Blocks(title="Caption Pro V3") as app:
|
|
| 94 |
status = gr.Textbox(label="الحالة", interactive=False)
|
| 95 |
table = gr.Dataframe(headers=["الكلمة", "البداية", "النهاية"], datatype=["str", "number", "number"], interactive=True)
|
| 96 |
|
| 97 |
-
btn_ex = gr.Button("1. استخراج الكلمات
|
| 98 |
-
btn_re = gr.Button("2. إنتاج الفيديو
|
| 99 |
|
| 100 |
btn_ex.click(step_1_extract_words, inputs=[video_in], outputs=[table, status])
|
| 101 |
btn_re.click(step_2_render_video, inputs=[video_in, table], outputs=[video_out, status])
|
|
|
|
| 11 |
model = WhisperModel("large-v3", device="cpu", compute_type="int8")
|
| 12 |
|
| 13 |
def process_arabic_text(text):
|
|
|
|
| 14 |
return reshape(text) + "\n "
|
| 15 |
|
| 16 |
def step_1_extract_words(video_path):
|
|
|
|
| 31 |
if video_path is None or df_edited is None or df_edited.empty:
|
| 32 |
return None, "بيانات ناقصة."
|
| 33 |
|
| 34 |
+
output_path = "final_clean_video.mp4"
|
| 35 |
video = VideoFileClip(video_path)
|
| 36 |
w, h = int(video.w), int(video.h)
|
| 37 |
clips = [video]
|
| 38 |
words_list = df_edited.values.tolist()
|
| 39 |
|
| 40 |
chunk_size = 3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
+
print(f"جاري معالجة الفيديو...")
|
| 43 |
|
| 44 |
for i in range(0, len(words_list), chunk_size):
|
| 45 |
current_chunk = words_list[i : i + chunk_size]
|
|
|
|
| 46 |
sentence = " ".join([str(r[0]) for r in current_chunk])
|
| 47 |
clean_sentence = process_arabic_text(sentence)
|
| 48 |
|
|
|
|
| 50 |
c_end = float(current_chunk[-1][2])
|
| 51 |
duration = max(0.1, c_end - c_start)
|
| 52 |
|
| 53 |
+
# إنشاء نص الكابشن ثابت بدون أي أنيميشن
|
| 54 |
txt_clip = TextClip(
|
| 55 |
text=clean_sentence,
|
| 56 |
+
font_size=80,
|
| 57 |
color='yellow',
|
| 58 |
stroke_color='black',
|
| 59 |
stroke_width=2,
|
|
|
|
| 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 |
+
clips.append(txt_clip)
|
| 67 |
|
|
|
|
| 68 |
final_video = CompositeVideoClip(clips, size=(w, h))
|
| 69 |
final_video.write_videofile(output_path, codec="libx264", audio_codec="aac", fps=video.fps, logger=None)
|
| 70 |
|
| 71 |
+
return output_path, "تم إنتاج الفيديو بنجاح!"
|
| 72 |
|
| 73 |
# --- بناء الواجهة ---
|
| 74 |
+
with gr.Blocks(title="Caption Pro Clean") as app:
|
| 75 |
+
gr.Markdown("# 🎬 Caption Pro - Simple Style")
|
| 76 |
|
| 77 |
with gr.Row():
|
| 78 |
video_in = gr.Video(label="فيديو المدخلات")
|
|
|
|
| 81 |
status = gr.Textbox(label="الحالة", interactive=False)
|
| 82 |
table = gr.Dataframe(headers=["الكلمة", "البداية", "النهاية"], datatype=["str", "number", "number"], interactive=True)
|
| 83 |
|
| 84 |
+
btn_ex = gr.Button("1. استخراج الكلمات", variant="primary")
|
| 85 |
+
btn_re = gr.Button("2. إنتاج الفيديو", variant="secondary")
|
| 86 |
|
| 87 |
btn_ex.click(step_1_extract_words, inputs=[video_in], outputs=[table, status])
|
| 88 |
btn_re.click(step_2_render_video, inputs=[video_in, table], outputs=[video_out, status])
|