Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -115,41 +115,41 @@ async def stream_generator(file_path: str, display_name: str, api_key: str, mode
|
|
| 115 |
|
| 116 |
yield log_msg(f"Ready. Starting generation for full duration...")
|
| 117 |
|
| 118 |
-
# 4. Prompt Construction (
|
| 119 |
end_time_instruction = total_duration_str if total_duration_str != "Unknown" else "the absolute end of the file"
|
| 120 |
|
| 121 |
instruction_set = f"""
|
| 122 |
-
1. Transcribe audio from 00:00:00 to {end_time_instruction}.
|
| 123 |
2. Translate to natural Burmese (Myanmar).
|
| 124 |
-
3.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
"""
|
| 126 |
|
| 127 |
if include_songs:
|
| 128 |
-
instruction_set += "\n 4.
|
| 129 |
else:
|
| 130 |
instruction_set += "\n 4. Ignore background music/lyrics."
|
| 131 |
|
| 132 |
if include_on_screen_text:
|
| 133 |
-
instruction_set += "\n 5.
|
| 134 |
else:
|
| 135 |
instruction_set += "\n 5. Ignore visual text."
|
| 136 |
|
| 137 |
-
# Stability Instructions
|
| 138 |
instruction_set += f"""
|
| 139 |
-
6. **SYNC
|
| 140 |
-
-
|
| 141 |
-
-
|
| 142 |
-
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
- Start time must be 00:00:00.
|
| 146 |
-
- **DO NOT** write "01:00:00" (1 hour) unless the video is actually longer than 60 minutes.
|
| 147 |
-
- e.g., Use "00:01:10", NOT "01:01:10".
|
| 148 |
"""
|
| 149 |
|
| 150 |
prompt = f"""
|
| 151 |
-
Task: Create Burmese SRT subtitles
|
| 152 |
-
|
| 153 |
INSTRUCTIONS:{instruction_set}
|
| 154 |
"""
|
| 155 |
|
|
@@ -161,7 +161,7 @@ async def stream_generator(file_path: str, display_name: str, api_key: str, mode
|
|
| 161 |
response_stream = model.generate_content(
|
| 162 |
[video_file, prompt],
|
| 163 |
stream=True,
|
| 164 |
-
generation_config={"temperature": 0.
|
| 165 |
)
|
| 166 |
|
| 167 |
chunk_count = 0
|
|
|
|
| 115 |
|
| 116 |
yield log_msg(f"Ready. Starting generation for full duration...")
|
| 117 |
|
| 118 |
+
# 4. Prompt Construction (Optimized for Sync)
|
| 119 |
end_time_instruction = total_duration_str if total_duration_str != "Unknown" else "the absolute end of the file"
|
| 120 |
|
| 121 |
instruction_set = f"""
|
| 122 |
+
1. Transcribe the audio from 00:00:00 to {end_time_instruction}.
|
| 123 |
2. Translate to natural Burmese (Myanmar).
|
| 124 |
+
3. **TIMING RULE**:
|
| 125 |
+
- **Do NOT fill gaps.** If there is music without lyrics, leave it blank.
|
| 126 |
+
- Timestamps must match the **exact start and end** of the singing/speech.
|
| 127 |
+
- Do NOT make timestamps continuous (e.g., if line 1 ends at 00:05 and line 2 starts at 00:10, do NOT extend line 1 to 00:10).
|
| 128 |
+
- Break subtitles when the singer takes a breath.
|
| 129 |
"""
|
| 130 |
|
| 131 |
if include_songs:
|
| 132 |
+
instruction_set += "\n 4. SONGS: Capture lyrics. Use 🎶 at start/end."
|
| 133 |
else:
|
| 134 |
instruction_set += "\n 4. Ignore background music/lyrics."
|
| 135 |
|
| 136 |
if include_on_screen_text:
|
| 137 |
+
instruction_set += "\n 5. ON-SCREEN TEXT: Use 📝."
|
| 138 |
else:
|
| 139 |
instruction_set += "\n 5. Ignore visual text."
|
| 140 |
|
|
|
|
| 141 |
instruction_set += f"""
|
| 142 |
+
6. **SYNC CHECK**:
|
| 143 |
+
- Start time MUST be 00:00:00.
|
| 144 |
+
- Ensure timestamps do NOT overlap.
|
| 145 |
+
- Continue until {end_time_instruction}.
|
| 146 |
+
- **Timestamp Format**: HH:MM:SS,mmm (e.g. 00:01:23,450)
|
| 147 |
+
- **NO HALLUCINATED HOURS**: Do not write "01:00:00" if video is short.
|
|
|
|
|
|
|
|
|
|
| 148 |
"""
|
| 149 |
|
| 150 |
prompt = f"""
|
| 151 |
+
Task: Create accurate, synced Burmese SRT subtitles.
|
| 152 |
+
Total Duration: {total_duration_str}
|
| 153 |
INSTRUCTIONS:{instruction_set}
|
| 154 |
"""
|
| 155 |
|
|
|
|
| 161 |
response_stream = model.generate_content(
|
| 162 |
[video_file, prompt],
|
| 163 |
stream=True,
|
| 164 |
+
generation_config={"temperature": 0.0} # Temperature 0.0 for strictest adherence to timing
|
| 165 |
)
|
| 166 |
|
| 167 |
chunk_count = 0
|