kader1997 commited on
Commit
62041f5
·
verified ·
1 Parent(s): 1811bc0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -5,7 +5,7 @@ import librosa
5
  import gradio as gr
6
  from scipy.signal import butter, lfilter
7
 
8
- # ضبط مسار ImageMagick (تأكد أن المسار صحيح في جهازك)
9
  os.environ["IMAGEMAGICK_BINARY"] = r"C:\Program Files\ImageMagick-7.1.2-Q16-HDRI\magick.exe"
10
 
11
  try:
@@ -34,9 +34,9 @@ def remove_silence(video_path, threshold, progress=gr.Progress()):
34
 
35
  output_filename = f"final_result_{int(time.time())}.mp4"
36
  video = None
37
-
38
  try:
39
- progress(0.1, desc="تحميل الفيديو وتحليل الصوت...")
40
  video = VideoFileClip(video_path)
41
 
42
  fps_audio = 22050
@@ -49,7 +49,7 @@ def remove_silence(video_path, threshold, progress=gr.Progress()):
49
  audio_array = librosa.util.normalize(audio_array)
50
  audio_array = highpass_filter(audio_array, fps_audio)
51
 
52
- progress(0.3, desc="تحديد مناطق الكلام...")
53
  intervals = librosa.effects.split(audio_array, top_db=abs(threshold))
54
 
55
  if len(intervals) == 0:
@@ -68,10 +68,10 @@ def remove_silence(video_path, threshold, progress=gr.Progress()):
68
  if not keep_clips:
69
  return None, "لم يتم العثور على مقاطع صالحة للقص."
70
 
71
- progress(0.6, desc="دمج المقاطع...")
72
  final_video = concatenate_videoclips(keep_clips, method="compose")
73
 
74
- progress(0.8, desc="تصدير الفيديو...")
75
  final_video.write_videofile(
76
  output_filename,
77
  fps=video.fps,
@@ -84,7 +84,7 @@ def remove_silence(video_path, threshold, progress=gr.Progress()):
84
  logger=None
85
  )
86
 
87
- # إغلاق المقاطع لتحرير الملفات من الذاكرة
88
  video.close()
89
  for c in keep_clips:
90
  c.close()
@@ -93,12 +93,13 @@ def remove_silence(video_path, threshold, progress=gr.Progress()):
93
  return output_filename, "تمت المعالجة بنجاح!"
94
 
95
  except Exception as e:
96
- if video: video.close()
 
97
  return None, f"خطأ تقني: {str(e)}"
98
 
99
  # ------------------ واجهة Gradio ------------------
100
 
101
- # تم حذف theme من هنا لتجنب التحذير
102
  with gr.Blocks(title="SilentCut Pro") as demo:
103
  gr.Markdown("# 🎬 SilentCut Pro")
104
  with gr.Row():
@@ -113,5 +114,5 @@ with gr.Blocks(title="SilentCut Pro") as demo:
113
  btn.click(fn=remove_silence, inputs=[v_in, slider], outputs=[v_out, status])
114
 
115
  if __name__ == "__main__":
116
- # تم نقل الـ theme إلى هنا ليتوافق مع Gradio 6.0
117
- demo.launch(theme=gr.themes.Soft())
 
5
  import gradio as gr
6
  from scipy.signal import butter, lfilter
7
 
8
+ # ضبط مسار ImageMagick
9
  os.environ["IMAGEMAGICK_BINARY"] = r"C:\Program Files\ImageMagick-7.1.2-Q16-HDRI\magick.exe"
10
 
11
  try:
 
34
 
35
  output_filename = f"final_result_{int(time.time())}.mp4"
36
  video = None
37
+
38
  try:
39
+ progress(0.1, desc="جاري تحليل الصوت...")
40
  video = VideoFileClip(video_path)
41
 
42
  fps_audio = 22050
 
49
  audio_array = librosa.util.normalize(audio_array)
50
  audio_array = highpass_filter(audio_array, fps_audio)
51
 
52
+ progress(0.3, desc="تحديد فترات الكلام...")
53
  intervals = librosa.effects.split(audio_array, top_db=abs(threshold))
54
 
55
  if len(intervals) == 0:
 
68
  if not keep_clips:
69
  return None, "لم يتم العثور على مقاطع صالحة للقص."
70
 
71
+ progress(0.6, desc="دمج الفيديو...")
72
  final_video = concatenate_videoclips(keep_clips, method="compose")
73
 
74
+ progress(0.8, desc="تصدير الملف النهائي...")
75
  final_video.write_videofile(
76
  output_filename,
77
  fps=video.fps,
 
84
  logger=None
85
  )
86
 
87
+ # تحرير الذاكرة وإغلاق الكليبات
88
  video.close()
89
  for c in keep_clips:
90
  c.close()
 
93
  return output_filename, "تمت المعالجة بنجاح!"
94
 
95
  except Exception as e:
96
+ if video:
97
+ video.close()
98
  return None, f"خطأ تقني: {str(e)}"
99
 
100
  # ------------------ واجهة Gradio ------------------
101
 
102
+ # إزالة theme من هنا لتجنب التحذير
103
  with gr.Blocks(title="SilentCut Pro") as demo:
104
  gr.Markdown("# 🎬 SilentCut Pro")
105
  with gr.Row():
 
114
  btn.click(fn=remove_silence, inputs=[v_in, slider], outputs=[v_out, status])
115
 
116
  if __name__ == "__main__":
117
+ # نقل الـ theme والـ ssr_mode إلى هنا
118
+ demo.launch(theme=gr.themes.Soft(), ssr_mode=False)