Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,8 @@ import time
|
|
| 2 |
import requests
|
| 3 |
import re
|
| 4 |
import gradio as gr
|
|
|
|
|
|
|
| 5 |
api_key = "268976:66f4f58a2a905"
|
| 6 |
|
| 7 |
|
|
@@ -152,7 +154,18 @@ def translate(file, max_chars):
|
|
| 152 |
subtitle_file = generate_translated_subtitle('fa', srt_string, 'video_subtitled')
|
| 153 |
time.sleep(10)
|
| 154 |
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
|
| 157 |
with gr.Blocks() as demo:
|
| 158 |
gr.Markdown("Start typing below and then click **Run** to see the progress and final output.")
|
|
|
|
| 2 |
import requests
|
| 3 |
import re
|
| 4 |
import gradio as gr
|
| 5 |
+
import os
|
| 6 |
+
import shutil
|
| 7 |
api_key = "268976:66f4f58a2a905"
|
| 8 |
|
| 9 |
|
|
|
|
| 154 |
subtitle_file = generate_translated_subtitle('fa', srt_string, 'video_subtitled')
|
| 155 |
time.sleep(10)
|
| 156 |
|
| 157 |
+
if os.path.exists(subtitle_file):
|
| 158 |
+
copied_subtitle = os.path.join(os.path.dirname(subtitle_file),
|
| 159 |
+
f"copy_{os.path.basename(subtitle_file)}")
|
| 160 |
+
shutil.copy2(subtitle_file, copied_subtitle)
|
| 161 |
+
|
| 162 |
+
# Delete the original subtitle file
|
| 163 |
+
os.remove(subtitle_file)
|
| 164 |
+
|
| 165 |
+
return copied_subtitle
|
| 166 |
+
else:
|
| 167 |
+
print("Error: subtitle file not found.")
|
| 168 |
+
return None
|
| 169 |
|
| 170 |
with gr.Blocks() as demo:
|
| 171 |
gr.Markdown("Start typing below and then click **Run** to see the progress and final output.")
|