Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -103,7 +103,7 @@ def prompt_fix_grammar(language="English"):
|
|
| 103 |
"""
|
| 104 |
prompt = f"""
|
| 105 |
-------------- You are a professional subtitle editor for **video dubbing**.
|
| 106 |
-
Fix the grammar, spelling, and awkward phrasing in the following `.srt` subtitle file while preserving timing, meaning, and emotional tone.
|
| 107 |
Do NOT translate — keep everything in {language}.
|
| 108 |
|
| 109 |
Output in JSON format exactly like this:
|
|
@@ -127,6 +127,40 @@ Output in JSON format exactly like this:
|
|
| 127 |
return prompt
|
| 128 |
|
| 129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
import pysrt
|
| 131 |
|
| 132 |
def prompt_maker(srt_path, target_language, task="Translation"):
|
|
@@ -140,6 +174,8 @@ def prompt_maker(srt_path, target_language, task="Translation"):
|
|
| 140 |
f.write(f"{sub.text}\n\n")
|
| 141 |
if task == "Translation":
|
| 142 |
f.write(prompt_translation(target_language))
|
|
|
|
|
|
|
| 143 |
else:
|
| 144 |
f.write(prompt_fix_grammar(target_language))
|
| 145 |
|
|
@@ -196,10 +232,10 @@ def ui2():
|
|
| 196 |
gr.Markdown("### Step 1: Generate Prompt")
|
| 197 |
srt_file = gr.File(label="Upload .srt file generated by Whisper", file_types=[".srt"])
|
| 198 |
task = gr.Dropdown(
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
language = gr.Dropdown(target_lang_list, label="Select the language you want to translate into", value="English")
|
| 204 |
generate_btn = gr.Button("Generate Prompt")
|
| 205 |
output_prompt = gr.Textbox(
|
|
|
|
| 103 |
"""
|
| 104 |
prompt = f"""
|
| 105 |
-------------- You are a professional subtitle editor for **video dubbing**.
|
| 106 |
+
Fix the grammar, spelling, and awkward phrasing in the following `.srt` subtitle file while preserving timing, meaning, and emotional tone.
|
| 107 |
Do NOT translate — keep everything in {language}.
|
| 108 |
|
| 109 |
Output in JSON format exactly like this:
|
|
|
|
| 127 |
return prompt
|
| 128 |
|
| 129 |
|
| 130 |
+
def prompt_srt_to_romanized(language="Hindi"):
|
| 131 |
+
"""
|
| 132 |
+
Generates a prompt for converting a .srt subtitle file
|
| 133 |
+
from any language to a Romanized (Latin letters) version,
|
| 134 |
+
preserving timing, meaning, punctuation, and formatting.
|
| 135 |
+
"""
|
| 136 |
+
prompt = f"""
|
| 137 |
+
-------------- You are a professional subtitle editor tasked with converting subtitles to Romanized text.
|
| 138 |
+
Your task is to convert a `.srt` subtitle file from {language} to **Romanized {language}**,
|
| 139 |
+
keeping everything exactly the same except using Latin letters for all words.
|
| 140 |
+
|
| 141 |
+
**Instructions:**
|
| 142 |
+
1. Preserve the original timestamp of each subtitle.
|
| 143 |
+
2. Keep the original meaning, punctuation, and formatting intact.
|
| 144 |
+
3. Convert **only the original subtitle text** to Roman letters, word by word.
|
| 145 |
+
4. Do not add, remove, or change any words.
|
| 146 |
+
5. Output in strict JSON format exactly like this:
|
| 147 |
+
|
| 148 |
+
```json
|
| 149 |
+
{{
|
| 150 |
+
"subtitle sequence number": {{
|
| 151 |
+
"timestamp": "original timestamp",
|
| 152 |
+
"original subtitle text": "original {language} subtitle line",
|
| 153 |
+
"dubbing": "Romanized, {language} line of original subtitle text"
|
| 154 |
+
}}
|
| 155 |
+
}}
|
| 156 |
+
````
|
| 157 |
+
|
| 158 |
+
Focus entirely on **accurate Romanization**; do not modify anything else.
|
| 159 |
+
"""
|
| 160 |
+
return prompt
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
|
| 164 |
import pysrt
|
| 165 |
|
| 166 |
def prompt_maker(srt_path, target_language, task="Translation"):
|
|
|
|
| 174 |
f.write(f"{sub.text}\n\n")
|
| 175 |
if task == "Translation":
|
| 176 |
f.write(prompt_translation(target_language))
|
| 177 |
+
if task=="Romanization":
|
| 178 |
+
f.write(prompt_srt_to_romanized(target_language))
|
| 179 |
else:
|
| 180 |
f.write(prompt_fix_grammar(target_language))
|
| 181 |
|
|
|
|
| 232 |
gr.Markdown("### Step 1: Generate Prompt")
|
| 233 |
srt_file = gr.File(label="Upload .srt file generated by Whisper", file_types=[".srt"])
|
| 234 |
task = gr.Dropdown(
|
| 235 |
+
["Translation","Romanization","Fix Grammar [English to English for dubbing]"],
|
| 236 |
+
label="Select Task",
|
| 237 |
+
value="Translation",
|
| 238 |
+
)
|
| 239 |
language = gr.Dropdown(target_lang_list, label="Select the language you want to translate into", value="English")
|
| 240 |
generate_btn = gr.Button("Generate Prompt")
|
| 241 |
output_prompt = gr.Textbox(
|