Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,11 +3,12 @@ import pandas as pd
|
|
| 3 |
import requests
|
| 4 |
from transformers import MarianMTModel, MarianTokenizer
|
| 5 |
|
| 6 |
-
# Function to fetch and parse language options
|
| 7 |
def fetch_languages(url):
|
| 8 |
response = requests.get(url)
|
| 9 |
if response.status_code == 200:
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
df.columns = ['ISO 639-1', 'ISO 639-2', 'Language Name', 'Native Name']
|
| 12 |
df['ISO 639-1'] = df['ISO 639-1'].str.strip()
|
| 13 |
language_options = [(row['ISO 639-1'], f"{row['ISO 639-1']} - {row['Language Name']}") for index, row in df.iterrows()]
|
|
@@ -15,7 +16,7 @@ def fetch_languages(url):
|
|
| 15 |
else:
|
| 16 |
return []
|
| 17 |
|
| 18 |
-
#
|
| 19 |
url = "https://huggingface.co/Lenylvt/LanguageISO/resolve/main/iso.md"
|
| 20 |
language_options = fetch_languages(url)
|
| 21 |
|
|
|
|
| 3 |
import requests
|
| 4 |
from transformers import MarianMTModel, MarianTokenizer
|
| 5 |
|
|
|
|
| 6 |
def fetch_languages(url):
|
| 7 |
response = requests.get(url)
|
| 8 |
if response.status_code == 200:
|
| 9 |
+
# Convert bytes to a string using decode, then create a file-like object with io.StringIO
|
| 10 |
+
csv_content = response.content.decode('utf-8')
|
| 11 |
+
df = pd.read_csv(io.StringIO(csv_content), delimiter="|", skiprows=2, header=None).dropna(axis=1, how='all')
|
| 12 |
df.columns = ['ISO 639-1', 'ISO 639-2', 'Language Name', 'Native Name']
|
| 13 |
df['ISO 639-1'] = df['ISO 639-1'].str.strip()
|
| 14 |
language_options = [(row['ISO 639-1'], f"{row['ISO 639-1']} - {row['Language Name']}") for index, row in df.iterrows()]
|
|
|
|
| 16 |
else:
|
| 17 |
return []
|
| 18 |
|
| 19 |
+
# Make sure to replace the URL with the correct one if it has changed
|
| 20 |
url = "https://huggingface.co/Lenylvt/LanguageISO/resolve/main/iso.md"
|
| 21 |
language_options = fetch_languages(url)
|
| 22 |
|