Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ import streamlit as st
|
|
4 |
import pandas as pd
|
5 |
import pysrt
|
6 |
from transformers import MarianMTModel, MarianTokenizer
|
|
|
7 |
|
8 |
def fetch_languages(url):
|
9 |
response = requests.get(url)
|
@@ -13,7 +14,7 @@ def fetch_languages(url):
|
|
13 |
df = pd.read_csv(io.StringIO(csv_content), delimiter="|", skiprows=2, header=None).dropna(axis=1, how='all')
|
14 |
df.columns = ['ISO 639-1', 'ISO 639-2', 'Language Name', 'Native Name']
|
15 |
df['ISO 639-1'] = df['ISO 639-1'].str.strip()
|
16 |
-
language_options = [(row['ISO 639-1'], f"{row['ISO 639-1']} - {row['Language Name']}") for index, row in df.iterrows()]
|
17 |
return language_options
|
18 |
else:
|
19 |
st.error("Failed to fetch language options. Please try again later.")
|
@@ -46,8 +47,10 @@ def translate_srt(input_file, source_language_code, target_language_code):
|
|
46 |
translated_subs.append(translated_sub)
|
47 |
progress_bar.progress((idx + 1) / len(subs))
|
48 |
translated_file = pysrt.SubRipFile(translated_subs)
|
49 |
-
|
50 |
-
|
|
|
|
|
51 |
progress_bar.empty()
|
52 |
return translated_srt_path
|
53 |
|
|
|
4 |
import pandas as pd
|
5 |
import pysrt
|
6 |
from transformers import MarianMTModel, MarianTokenizer
|
7 |
+
import tempfile
|
8 |
|
9 |
def fetch_languages(url):
|
10 |
response = requests.get(url)
|
|
|
14 |
df = pd.read_csv(io.StringIO(csv_content), delimiter="|", skiprows=2, header=None).dropna(axis=1, how='all')
|
15 |
df.columns = ['ISO 639-1', 'ISO 639-2', 'Language Name', 'Native Name']
|
16 |
df['ISO 639-1'] = df['ISO 639-1'].str.strip()
|
17 |
+
language_options = [(row['ISO 639-1'], f"{row['ISO 639-1']} - {row['Language Name'].strip()}") for index, row in df.iterrows()]
|
18 |
return language_options
|
19 |
else:
|
20 |
st.error("Failed to fetch language options. Please try again later.")
|
|
|
47 |
translated_subs.append(translated_sub)
|
48 |
progress_bar.progress((idx + 1) / len(subs))
|
49 |
translated_file = pysrt.SubRipFile(translated_subs)
|
50 |
+
# Use tempfile to create a temporary file path
|
51 |
+
with tempfile.NamedTemporaryFile(suffix=".srt", delete=False) as tmp_file:
|
52 |
+
translated_file.save(tmp_file.name)
|
53 |
+
translated_srt_path = tmp_file.name
|
54 |
progress_bar.empty()
|
55 |
return translated_srt_path
|
56 |
|