Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -22,7 +22,7 @@ generation_config = {
|
|
22 |
}
|
23 |
|
24 |
model = genai.GenerativeModel(
|
25 |
-
model_name="gemini-exp
|
26 |
generation_config=generation_config,
|
27 |
)
|
28 |
|
@@ -95,25 +95,14 @@ def format_timestamp(seconds):
|
|
95 |
milliseconds = int((seconds - int(seconds)) * 1000)
|
96 |
return f"{hours:02}:{minutes:02}:{int(seconds):02},{milliseconds:03}"
|
97 |
|
98 |
-
def translate_text(text, target_language):
|
99 |
-
"""Translate text using Gemini."""
|
100 |
-
prompt = f"Translate the following text into {target_language}:\n\n{text}"
|
101 |
-
response = model.generate_content(prompt)
|
102 |
-
return response.text
|
103 |
-
|
104 |
def translate_srt(srt_text, target_language):
|
105 |
"""Translate an SRT file while preserving timestamps."""
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
elif line.strip(): # Text line
|
113 |
-
translated_srt += translate_text(line, target_language) + "\n"
|
114 |
-
else: # Empty line
|
115 |
-
translated_srt += "\n"
|
116 |
-
return translated_srt
|
117 |
|
118 |
def process_video(video_file, language="Auto Detect", translate_to=None):
|
119 |
"""Process a video file to generate and translate subtitles."""
|
|
|
22 |
}
|
23 |
|
24 |
model = genai.GenerativeModel(
|
25 |
+
model_name="gemini-2.0-flash-exp",
|
26 |
generation_config=generation_config,
|
27 |
)
|
28 |
|
|
|
95 |
milliseconds = int((seconds - int(seconds)) * 1000)
|
96 |
return f"{hours:02}:{minutes:02}:{int(seconds):02},{milliseconds:03}"
|
97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
def translate_srt(srt_text, target_language):
|
99 |
"""Translate an SRT file while preserving timestamps."""
|
100 |
+
# Magic prompt for Gemini
|
101 |
+
prompt = f"Translate the following SRT subtitles into {target_language}. Preserve the SRT format (timestamps and structure). Translate only the text after the timestamp. Do not add explanations or extra text.\n\n{srt_text}"
|
102 |
+
|
103 |
+
# Send the prompt to Gemini
|
104 |
+
response = model.generate_content(prompt)
|
105 |
+
return response.text
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
def process_video(video_file, language="Auto Detect", translate_to=None):
|
108 |
"""Process a video file to generate and translate subtitles."""
|