Lenylvt commited on
Commit
b3a9f55
1 Parent(s): 47e5660

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -52,7 +52,7 @@ def translate_srt(input_file, source_language_code, target_language_code):
52
  return translated_file
53
 
54
  st.title("SRT Translator")
55
- st.write("Translate subtitles from one language to another.")
56
 
57
  # Fetch language options
58
  url = "https://huggingface.co/Lenylvt/LanguageISO/resolve/main/iso.md"
@@ -61,10 +61,10 @@ language_options = fetch_languages(url)
61
  source_language_code, target_language_code = None, None
62
 
63
  if language_options:
64
- source_language_code = st.selectbox("Select Source Language", options=language_options, format_func=lambda x: x[1])[0]
65
- target_language_code = st.selectbox("Select Target Language", options=language_options, format_func=lambda x: x[1])[0]
66
 
67
- file_input = st.file_uploader("Upload SRT File", type=["srt"])
68
 
69
  if file_input is not None and source_language_code and target_language_code:
70
  with tempfile.NamedTemporaryFile(delete=False, suffix=".srt") as temp_file:
@@ -73,15 +73,15 @@ if file_input is not None and source_language_code and target_language_code:
73
 
74
  translated_srt = translate_srt(temp_file_path, source_language_code, target_language_code)
75
 
76
- buffer = BytesIO()
77
- translated_srt.save(buffer, encoding='utf-8')
78
- buffer.seek(0)
79
-
80
- translated_srt_bytes = buffer.getvalue()
81
 
82
  st.download_button(
83
- label="Download Translated SRT",
84
  data=translated_srt_bytes,
85
  file_name="translated_subtitles.srt",
86
  mime="text/plain",
87
- )
 
52
  return translated_file
53
 
54
  st.title("SRT Translator")
55
+ st.write("We use model from [Language Technology Research Group at the University of Helsinki](https://huggingface.co/Helsinki-NLP). For API use please visit [this space](https://huggingface.co/spaces/Lenylvt/SRT_Translation-API)")
56
 
57
  # Fetch language options
58
  url = "https://huggingface.co/Lenylvt/LanguageISO/resolve/main/iso.md"
 
61
  source_language_code, target_language_code = None, None
62
 
63
  if language_options:
64
+ source_language_code = st.selectbox("1️⃣ Select Source Language", options=language_options, format_func=lambda x: x[1])[0]
65
+ target_language_code = st.selectbox("2️⃣ Select Target Language", options=language_options, format_func=lambda x: x[1])[0]
66
 
67
+ file_input = st.file_uploader("📁 Upload SRT File", type=["srt"], accept_multiple_files=False)
68
 
69
  if file_input is not None and source_language_code and target_language_code:
70
  with tempfile.NamedTemporaryFile(delete=False, suffix=".srt") as temp_file:
 
73
 
74
  translated_srt = translate_srt(temp_file_path, source_language_code, target_language_code)
75
 
76
+ #buffer = BytesIO()
77
+ #translated_srt.save(buffer, encoding='utf-8')
78
+ #buffer.seek(0)
79
+ #
80
+ #translated_srt_bytes = buffer.getvalue()
81
 
82
  st.download_button(
83
+ label="⬇️ Download Translated SRT",
84
  data=translated_srt_bytes,
85
  file_name="translated_subtitles.srt",
86
  mime="text/plain",
87
+ )