Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -61,20 +61,24 @@ if language_options:
|
|
61 |
file_input = st.file_uploader("Upload SRT File", type=["srt"])
|
62 |
|
63 |
if file_input is not None and source_language_code and target_language_code:
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
-
#
|
67 |
buffer = BytesIO()
|
68 |
translated_srt.save(buffer, encoding='utf-8')
|
69 |
buffer.seek(0)
|
70 |
|
71 |
-
# Convert the BytesIO buffer to bytes for the download button
|
72 |
translated_srt_bytes = buffer.getvalue()
|
73 |
|
74 |
-
# Create a download button and serve the translated subtitles as a downloadable file
|
75 |
st.download_button(
|
76 |
label="Download Translated SRT",
|
77 |
data=translated_srt_bytes,
|
78 |
file_name="translated_subtitles.srt",
|
79 |
mime="text/plain",
|
80 |
-
)
|
|
|
61 |
file_input = st.file_uploader("Upload SRT File", type=["srt"])
|
62 |
|
63 |
if file_input is not None and source_language_code and target_language_code:
|
64 |
+
# Save the uploaded file to a temporary file
|
65 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".srt") as temp_file:
|
66 |
+
temp_file.write(file_input.getvalue())
|
67 |
+
temp_file_path = temp_file.name
|
68 |
+
|
69 |
+
# Now, temp_file_path contains the path to the temporary file which you can pass to translate_srt
|
70 |
+
translated_srt = translate_srt(temp_file_path, source_language_code, target_language_code)
|
71 |
|
72 |
+
# Proceed with the translation and file download preparation as before
|
73 |
buffer = BytesIO()
|
74 |
translated_srt.save(buffer, encoding='utf-8')
|
75 |
buffer.seek(0)
|
76 |
|
|
|
77 |
translated_srt_bytes = buffer.getvalue()
|
78 |
|
|
|
79 |
st.download_button(
|
80 |
label="Download Translated SRT",
|
81 |
data=translated_srt_bytes,
|
82 |
file_name="translated_subtitles.srt",
|
83 |
mime="text/plain",
|
84 |
+
)
|