Spaces:
Sleeping
Sleeping
younes21000
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
import gradio as gr
|
2 |
import whisper
|
3 |
import os
|
4 |
from transformers import M2M100ForConditionalGeneration, M2M100Tokenizer
|
@@ -36,8 +35,7 @@ def load_translation_model(target_language):
|
|
36 |
"hi": "hi", # Hindi
|
37 |
"ja": "ja", # Japanese
|
38 |
"ko": "ko", # Korean
|
39 |
-
"ru": "ru"
|
40 |
-
|
41 |
}
|
42 |
target_lang_code = lang_codes.get(target_language)
|
43 |
if not target_lang_code:
|
@@ -68,7 +66,7 @@ def format_timestamp(seconds):
|
|
68 |
seconds = seconds % 60
|
69 |
return f"{hours:02}:{minutes:02}:{seconds:02},{milliseconds:03}"
|
70 |
|
71 |
-
#
|
72 |
def write_srt(transcription, output_file, tokenizer=None, translation_model=None):
|
73 |
with open(output_file, "w") as f:
|
74 |
for i, segment in enumerate(transcription['segments']):
|
@@ -113,9 +111,11 @@ def write_word(transcription, output_file, tokenizer=None, translation_model=Non
|
|
113 |
|
114 |
# Helper function to write PDF documents
|
115 |
def write_pdf(transcription, output_file, tokenizer=None, translation_model=None):
|
|
|
116 |
c = canvas.Canvas(output_file, pagesize=A4)
|
117 |
app_dir = os.path.dirname(os.path.abspath(__file__))
|
118 |
|
|
|
119 |
nazanin_font_path = os.path.join(app_dir, 'B-NAZANIN.TTF')
|
120 |
arial_font_path = os.path.join(app_dir, 'Arial.ttf')
|
121 |
|
@@ -184,10 +184,10 @@ def write_ppt(transcription, output_file, tokenizer=None, translation_model=None
|
|
184 |
|
185 |
# Transcribing video and generating output
|
186 |
def transcribe_video(video_file, language, target_language, model_name, output_format):
|
187 |
-
actual_model_name = whisper_models[model_name]
|
188 |
-
model = whisper.load_model(actual_model_name)
|
189 |
|
190 |
-
if video_file is not None:
|
191 |
video_file_path = video_file.name
|
192 |
else:
|
193 |
raise ValueError("No video file provided. Please upload a video file.")
|
@@ -250,4 +250,4 @@ iface = gr.Interface(
|
|
250 |
)
|
251 |
|
252 |
# Run the interface
|
253 |
-
iface.launch(share=True)
|
|
|
|
|
1 |
import whisper
|
2 |
import os
|
3 |
from transformers import M2M100ForConditionalGeneration, M2M100Tokenizer
|
|
|
35 |
"hi": "hi", # Hindi
|
36 |
"ja": "ja", # Japanese
|
37 |
"ko": "ko", # Korean
|
38 |
+
"ru": "ru", # Russian
|
|
|
39 |
}
|
40 |
target_lang_code = lang_codes.get(target_language)
|
41 |
if not target_lang_code:
|
|
|
66 |
seconds = seconds % 60
|
67 |
return f"{hours:02}:{minutes:02}:{seconds:02},{milliseconds:03}"
|
68 |
|
69 |
+
# Corrected write_srt function
|
70 |
def write_srt(transcription, output_file, tokenizer=None, translation_model=None):
|
71 |
with open(output_file, "w") as f:
|
72 |
for i, segment in enumerate(transcription['segments']):
|
|
|
111 |
|
112 |
# Helper function to write PDF documents
|
113 |
def write_pdf(transcription, output_file, tokenizer=None, translation_model=None):
|
114 |
+
# Create PDF with A4 page size
|
115 |
c = canvas.Canvas(output_file, pagesize=A4)
|
116 |
app_dir = os.path.dirname(os.path.abspath(__file__))
|
117 |
|
118 |
+
# Register fonts
|
119 |
nazanin_font_path = os.path.join(app_dir, 'B-NAZANIN.TTF')
|
120 |
arial_font_path = os.path.join(app_dir, 'Arial.ttf')
|
121 |
|
|
|
184 |
|
185 |
# Transcribing video and generating output
|
186 |
def transcribe_video(video_file, language, target_language, model_name, output_format):
|
187 |
+
actual_model_name = whisper_models[model_name] # Map user selection to model name
|
188 |
+
model = whisper.load_model(actual_model_name) # Load the selected model
|
189 |
|
190 |
+
if video_file is not None: # Ensure the video_file is not None
|
191 |
video_file_path = video_file.name
|
192 |
else:
|
193 |
raise ValueError("No video file provided. Please upload a video file.")
|
|
|
250 |
)
|
251 |
|
252 |
# Run the interface
|
253 |
+
iface.launch(share=True)
|