binaryMao commited on
Commit
bfcc59d
·
verified ·
1 Parent(s): 64e18a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -11
app.py CHANGED
@@ -1,7 +1,7 @@
1
  # -*- coding: utf-8 -*-
2
  """
3
  ROBOTSMALI V38 FINAL — SOUS-TITRAGE BAMBARA (STYLE NETFLIX)
4
- Correction V38 : Durée exacte, QuartzNet fonctionnel, pipeline simplifiée
5
  """
6
 
7
  import os, tempfile, traceback, random, textwrap
@@ -159,16 +159,29 @@ def align_vad(text,audio,sr,total_dur,top_db=28):
159
  def burn(video, subs):
160
  tmp_srt = tempfile.mktemp(suffix=".srt")
161
  out_file = "RobotsMali_Subtitled.mp4"
162
- # Écriture SRT
163
  def sec_to_srt(t):
164
- h=int(t//3600); m=int((t%3600)//60); s=int(t%60); ms=int((t-int(t))*1000)
 
 
 
165
  return f"{h:02}:{m:02}:{s:02},{ms:03}"
166
- with open(tmp_srt,"w",encoding="utf-8") as f:
167
- for i,(start,end,text) in enumerate(subs,1):
 
 
168
  f.write(f"{i}\n{sec_to_srt(start)} --> {sec_to_srt(end)}\n{text}\n\n")
169
- # Fusion vidéo + sous-titres sans changer durée
170
- os.system(f'ffmpeg -y -i "{video}" -vf "subtitles={tmp_srt}" -c:v copy -c:a aac -b:a 192k "{out_file}"')
171
- if os.path.exists(tmp_srt): os.remove(tmp_srt)
 
 
 
 
 
 
 
 
172
  return out_file
173
 
174
  # ----------------------------
@@ -177,7 +190,6 @@ def burn(video, subs):
177
  def pipeline(video, model_name):
178
  try:
179
  wav=tempfile.mktemp(suffix=".wav")
180
- # Extraction audio
181
  extract_audio(video,wav)
182
  clean,audio,sr=clean_audio(wav)
183
  model=load_model(model_name)
@@ -210,8 +222,8 @@ def pipeline(video, model_name):
210
  # ----------------------------
211
  # INTERFACE GRADIO
212
  # ----------------------------
213
- with gr.Blocks(title="RobotsMali V38 Final") as demo:
214
- gr.Markdown("## ⚡ RobotsMali V38 — Sous-titrage Style Netflix (QuartzNet & RNNT stable)")
215
  v = gr.Video(label="Vidéo à sous-titrer")
216
  m = gr.Dropdown(list(MODELS.keys()), value="Soloba V1 (CTC)", label="Modèle ASR")
217
  b = gr.Button("▶️ Générer")
 
1
  # -*- coding: utf-8 -*-
2
  """
3
  ROBOTSMALI V38 FINAL — SOUS-TITRAGE BAMBARA (STYLE NETFLIX)
4
+ Correction V38.1 : FFmpeg fixe (pas de -c copy), durée exacte, QuartzNet fonctionnel
5
  """
6
 
7
  import os, tempfile, traceback, random, textwrap
 
159
  def burn(video, subs):
160
  tmp_srt = tempfile.mktemp(suffix=".srt")
161
  out_file = "RobotsMali_Subtitled.mp4"
162
+
163
  def sec_to_srt(t):
164
+ h = int(t // 3600)
165
+ m = int((t % 3600) // 60)
166
+ s = int(t % 60)
167
+ ms = int((t - int(t)) * 1000)
168
  return f"{h:02}:{m:02}:{s:02},{ms:03}"
169
+
170
+ # Écriture du SRT
171
+ with open(tmp_srt, "w", encoding="utf-8") as f:
172
+ for i, (start, end, text) in enumerate(subs, 1):
173
  f.write(f"{i}\n{sec_to_srt(start)} --> {sec_to_srt(end)}\n{text}\n\n")
174
+
175
+ # Fusion avec réencodage (corrigé)
176
+ cmd = (
177
+ f'ffmpeg -y -i "{video}" '
178
+ f'-vf "subtitles={tmp_srt}:force_style=\'Fontsize=24,PrimaryColour=&HFFFFFF&,OutlineColour=&H000000&\'" '
179
+ f'-c:v libx264 -preset ultrafast -crf 23 -c:a copy "{out_file}"'
180
+ )
181
+ os.system(cmd)
182
+
183
+ if os.path.exists(tmp_srt):
184
+ os.remove(tmp_srt)
185
  return out_file
186
 
187
  # ----------------------------
 
190
  def pipeline(video, model_name):
191
  try:
192
  wav=tempfile.mktemp(suffix=".wav")
 
193
  extract_audio(video,wav)
194
  clean,audio,sr=clean_audio(wav)
195
  model=load_model(model_name)
 
222
  # ----------------------------
223
  # INTERFACE GRADIO
224
  # ----------------------------
225
+ with gr.Blocks(title="RobotsMali V38.1 Final") as demo:
226
+ gr.Markdown("## ⚡ RobotsMali V38.1 — Sous-titrage Style Netflix (QuartzNet & RNNT stable)")
227
  v = gr.Video(label="Vidéo à sous-titrer")
228
  m = gr.Dropdown(list(MODELS.keys()), value="Soloba V1 (CTC)", label="Modèle ASR")
229
  b = gr.Button("▶️ Générer")