Update app.py
Browse files
app.py
CHANGED
|
@@ -269,13 +269,8 @@ def translate_transcriptions(df, selected_translation_lang_2):
|
|
| 269 |
|
| 270 |
print("translations done")
|
| 271 |
|
| 272 |
-
|
| 273 |
|
| 274 |
-
def create_srt_and_burn(df, video_in):
|
| 275 |
-
|
| 276 |
-
print("Starting creation of video wit srt")
|
| 277 |
-
|
| 278 |
-
|
| 279 |
with open('subtitles.srt','w', encoding="utf-8") as file:
|
| 280 |
for i in range(len(df)):
|
| 281 |
file.write(str(i+1))
|
|
@@ -284,32 +279,32 @@ def create_srt_and_burn(df, video_in):
|
|
| 284 |
|
| 285 |
|
| 286 |
milliseconds = round(start * 1000.0)
|
| 287 |
-
|
| 288 |
hours = milliseconds // 3_600_000
|
| 289 |
milliseconds -= hours * 3_600_000
|
| 290 |
-
|
| 291 |
minutes = milliseconds // 60_000
|
| 292 |
milliseconds -= minutes * 60_000
|
| 293 |
-
|
| 294 |
seconds = milliseconds // 1_000
|
| 295 |
milliseconds -= seconds * 1_000
|
| 296 |
-
|
| 297 |
file.write(f"{hours}:{minutes:02d}:{seconds:02d}.{milliseconds:03d}")
|
| 298 |
|
| 299 |
stop = df.iloc[i]['end']
|
| 300 |
|
| 301 |
|
| 302 |
milliseconds = round(stop * 1000.0)
|
| 303 |
-
|
| 304 |
hours = milliseconds // 3_600_000
|
| 305 |
milliseconds -= hours * 3_600_000
|
| 306 |
-
|
| 307 |
minutes = milliseconds // 60_000
|
| 308 |
milliseconds -= minutes * 60_000
|
| 309 |
-
|
| 310 |
seconds = milliseconds // 1_000
|
| 311 |
milliseconds -= seconds * 1_000
|
| 312 |
-
|
| 313 |
|
| 314 |
file.write(' --> ')
|
| 315 |
file.write(f"{hours}:{minutes:02d}:{seconds:02d}.{milliseconds:03d}")
|
|
@@ -318,7 +313,14 @@ def create_srt_and_burn(df, video_in):
|
|
| 318 |
if int(i) != len(df)-1:
|
| 319 |
file.write('\n\n')
|
| 320 |
|
| 321 |
-
print("SRT DONE")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
try:
|
| 323 |
file1 = open('./subtitles.srt', 'r', encoding="utf-8")
|
| 324 |
Lines = file1.readlines()
|
|
@@ -357,7 +359,7 @@ selected_whisper_model = gr.Dropdown(choices=whisper_models, type="value", value
|
|
| 357 |
transcription_df = gr.DataFrame(value=df_init,label="Transcription dataframe", row_count=(0, "dynamic"), max_rows = 10, wrap=True, overflow_row_behaviour='paginate')
|
| 358 |
transcription_and_translation_df = gr.DataFrame(value=df_init,label="Transcription and translation dataframe", max_rows = 10, wrap=True, overflow_row_behaviour='paginate')
|
| 359 |
|
| 360 |
-
|
| 361 |
label="Download srt-file",
|
| 362 |
file_count="single",
|
| 363 |
type="file",
|
|
@@ -432,8 +434,13 @@ with demo:
|
|
| 432 |
##### ''')
|
| 433 |
selected_translation_lang_2.render()
|
| 434 |
translate_transcriptions_button = gr.Button("Step 3. Translate transcription")
|
| 435 |
-
translate_transcriptions_button.click(translate_transcriptions, [transcription_df, selected_translation_lang_2], transcription_and_translation_df)
|
| 436 |
transcription_and_translation_df.render()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 437 |
|
| 438 |
with gr.Row():
|
| 439 |
with gr.Column():
|
|
@@ -442,14 +449,10 @@ with demo:
|
|
| 442 |
##### ''')
|
| 443 |
translate_and_make_srt_btn = gr.Button("Step 4. Create and burn srt to video")
|
| 444 |
print(video_in)
|
| 445 |
-
translate_and_make_srt_btn.click(create_srt_and_burn, [
|
| 446 |
-
video_out
|
| 447 |
video_out.render()
|
| 448 |
|
| 449 |
-
with gr.Row():
|
| 450 |
-
with gr.Column():
|
| 451 |
-
gr.Markdown('''##### From here you can download the srt-file ''')
|
| 452 |
-
text_file.render()
|
| 453 |
|
| 454 |
|
| 455 |
demo.launch()
|
|
|
|
| 269 |
|
| 270 |
print("translations done")
|
| 271 |
|
| 272 |
+
print("Starting SRT-file creation")
|
| 273 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
with open('subtitles.srt','w', encoding="utf-8") as file:
|
| 275 |
for i in range(len(df)):
|
| 276 |
file.write(str(i+1))
|
|
|
|
| 279 |
|
| 280 |
|
| 281 |
milliseconds = round(start * 1000.0)
|
| 282 |
+
|
| 283 |
hours = milliseconds // 3_600_000
|
| 284 |
milliseconds -= hours * 3_600_000
|
| 285 |
+
|
| 286 |
minutes = milliseconds // 60_000
|
| 287 |
milliseconds -= minutes * 60_000
|
| 288 |
+
|
| 289 |
seconds = milliseconds // 1_000
|
| 290 |
milliseconds -= seconds * 1_000
|
| 291 |
+
|
| 292 |
file.write(f"{hours}:{minutes:02d}:{seconds:02d}.{milliseconds:03d}")
|
| 293 |
|
| 294 |
stop = df.iloc[i]['end']
|
| 295 |
|
| 296 |
|
| 297 |
milliseconds = round(stop * 1000.0)
|
| 298 |
+
|
| 299 |
hours = milliseconds // 3_600_000
|
| 300 |
milliseconds -= hours * 3_600_000
|
| 301 |
+
|
| 302 |
minutes = milliseconds // 60_000
|
| 303 |
milliseconds -= minutes * 60_000
|
| 304 |
+
|
| 305 |
seconds = milliseconds // 1_000
|
| 306 |
milliseconds -= seconds * 1_000
|
| 307 |
+
|
| 308 |
|
| 309 |
file.write(' --> ')
|
| 310 |
file.write(f"{hours}:{minutes:02d}:{seconds:02d}.{milliseconds:03d}")
|
|
|
|
| 313 |
if int(i) != len(df)-1:
|
| 314 |
file.write('\n\n')
|
| 315 |
|
| 316 |
+
print("SRT DONE")
|
| 317 |
+
|
| 318 |
+
return df, 'subtitles.srt'
|
| 319 |
+
|
| 320 |
+
def create_srt_and_burn(srt_file, video_in):
|
| 321 |
+
|
| 322 |
+
print("Starting creation of video wit srt")
|
| 323 |
+
|
| 324 |
try:
|
| 325 |
file1 = open('./subtitles.srt', 'r', encoding="utf-8")
|
| 326 |
Lines = file1.readlines()
|
|
|
|
| 359 |
transcription_df = gr.DataFrame(value=df_init,label="Transcription dataframe", row_count=(0, "dynamic"), max_rows = 10, wrap=True, overflow_row_behaviour='paginate')
|
| 360 |
transcription_and_translation_df = gr.DataFrame(value=df_init,label="Transcription and translation dataframe", max_rows = 10, wrap=True, overflow_row_behaviour='paginate')
|
| 361 |
|
| 362 |
+
srt_file = gr.File(
|
| 363 |
label="Download srt-file",
|
| 364 |
file_count="single",
|
| 365 |
type="file",
|
|
|
|
| 434 |
##### ''')
|
| 435 |
selected_translation_lang_2.render()
|
| 436 |
translate_transcriptions_button = gr.Button("Step 3. Translate transcription")
|
| 437 |
+
translate_transcriptions_button.click(translate_transcriptions, [transcription_df, selected_translation_lang_2], transcription_and_translation_df, srt_file)
|
| 438 |
transcription_and_translation_df.render()
|
| 439 |
+
|
| 440 |
+
with gr.Row():
|
| 441 |
+
with gr.Column():
|
| 442 |
+
gr.Markdown('''##### From here you can download the srt-file ''')
|
| 443 |
+
srt_file.render()
|
| 444 |
|
| 445 |
with gr.Row():
|
| 446 |
with gr.Column():
|
|
|
|
| 449 |
##### ''')
|
| 450 |
translate_and_make_srt_btn = gr.Button("Step 4. Create and burn srt to video")
|
| 451 |
print(video_in)
|
| 452 |
+
translate_and_make_srt_btn.click(create_srt_and_burn, [srt_file,video_in], [
|
| 453 |
+
video_out])
|
| 454 |
video_out.render()
|
| 455 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 456 |
|
| 457 |
|
| 458 |
demo.launch()
|