Lenylvt commited on
Commit
3c71f27
1 Parent(s): f537405

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import gradio as gr
2
  from faster_whisper import WhisperModel
3
  import logging
@@ -40,14 +41,15 @@ def text_to_srt(text):
40
  with open(temp_file_path, 'w', encoding='utf-8') as file:
41
  file.write(srt_content)
42
  return temp_file_path
43
-
44
  # Fonction pour formater des secondes en timestamp
45
  def format_timestamp(seconds):
46
  hours = int(seconds // 3600)
47
  minutes = int((seconds % 3600) // 60)
48
  seconds_remainder = seconds % 60
49
  return f"{hours:02d}:{minutes:02d}:{seconds_remainder:06.3f}"
50
-
 
51
  # Fonction de traduction de texte
52
  def translate_text(text, source_language_code, target_language_code):
53
  model_name = f"Helsinki-NLP/opus-mt-{source_language_code}-{target_language_code}"
@@ -61,7 +63,8 @@ def translate_text(text, source_language_code, target_language_code):
61
  translated = model.generate(**tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=512))
62
  translated_text = tokenizer.decode(translated[0], skip_special_tokens=True)
63
  return translated_text
64
-
 
65
  # Fonction pour traduire un fichier SRT
66
  def translate_srt(input_file_path, source_language_code, target_language_code, progress=None):
67
  subs = pysrt.open(input_file_path)
@@ -75,7 +78,8 @@ def translate_srt(input_file_path, source_language_code, target_language_code, p
75
  translated_srt_path = input_file_path.replace(".srt", f"_{target_language_code}.srt")
76
  pysrt.SubRipFile(translated_subs).save(translated_srt_path)
77
  return translated_srt_path
78
-
 
79
  # Fonction pour transcrire l'audio d'une vidéo en texte
80
  def transcribe(audio_file_path, model_size="base"):
81
  device = "cuda" if torch.cuda.is_available() else "cpu"
@@ -87,7 +91,8 @@ def transcribe(audio_file_path, model_size="base"):
87
  for segment in segments
88
  ]
89
  return "\n".join(transcription_with_timestamps)
90
-
 
91
  # Fonction pour ajouter des sous-titres à une vidéo
92
  def add_subtitle_to_video(input_video, subtitle_file, subtitle_language, soft_subtitle=False):
93
  video_input_stream = ffmpeg.input(input_video)
 
1
+ import spaces
2
  import gradio as gr
3
  from faster_whisper import WhisperModel
4
  import logging
 
41
  with open(temp_file_path, 'w', encoding='utf-8') as file:
42
  file.write(srt_content)
43
  return temp_file_path
44
+
45
  # Fonction pour formater des secondes en timestamp
46
  def format_timestamp(seconds):
47
  hours = int(seconds // 3600)
48
  minutes = int((seconds % 3600) // 60)
49
  seconds_remainder = seconds % 60
50
  return f"{hours:02d}:{minutes:02d}:{seconds_remainder:06.3f}"
51
+
52
+ @spaces.GPU
53
  # Fonction de traduction de texte
54
  def translate_text(text, source_language_code, target_language_code):
55
  model_name = f"Helsinki-NLP/opus-mt-{source_language_code}-{target_language_code}"
 
63
  translated = model.generate(**tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=512))
64
  translated_text = tokenizer.decode(translated[0], skip_special_tokens=True)
65
  return translated_text
66
+
67
+ @spaces.GPU
68
  # Fonction pour traduire un fichier SRT
69
  def translate_srt(input_file_path, source_language_code, target_language_code, progress=None):
70
  subs = pysrt.open(input_file_path)
 
78
  translated_srt_path = input_file_path.replace(".srt", f"_{target_language_code}.srt")
79
  pysrt.SubRipFile(translated_subs).save(translated_srt_path)
80
  return translated_srt_path
81
+
82
+ @spaces.GPU
83
  # Fonction pour transcrire l'audio d'une vidéo en texte
84
  def transcribe(audio_file_path, model_size="base"):
85
  device = "cuda" if torch.cuda.is_available() else "cpu"
 
91
  for segment in segments
92
  ]
93
  return "\n".join(transcription_with_timestamps)
94
+
95
+ @spaces.GPU
96
  # Fonction pour ajouter des sous-titres à une vidéo
97
  def add_subtitle_to_video(input_video, subtitle_file, subtitle_language, soft_subtitle=False):
98
  video_input_stream = ffmpeg.input(input_video)