Spaces:
Sleeping
Sleeping
File size: 1,684 Bytes
4bdcdda d60a3d5 a03a333 d60a3d5 4bdcdda 0f9dc19 4bdcdda 2189552 4bdcdda 2189552 4bdcdda 2189552 0f9dc19 4bdcdda 2189552 a03a333 d60a3d5 550812d 4bdcdda d60a3d5 2189552 a03a333 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import requests
import pandas as pd
import gradio as gr
from transformers import MarianMTModel, MarianTokenizer
# Fetch and parse language options from the provided URL
url = "https://huggingface.co/Lenylvt/LanguageISO/resolve/main/iso.md"
response = requests.get(url)
# Assuming the response content is a Markdown table, convert it to a DataFrame
df = pd.read_csv(url, delimiter="|", skiprows=2, header=None).dropna(axis=1, how='all')
df.columns = ['ISO 639-1', 'ISO 639-2', 'Language Name', 'Native Name']
df['ISO 639-1'] = df['ISO 639-1'].str.strip()
# Prepare language options for the dropdown
language_options = [(row['ISO 639-1'], f"{row['Language Name']} ({row['ISO 639-1']})") for index, row in df.iterrows()]
# Your translate_text function and Gradio interface setup goes here
# Replace the previous static language_options list with the dynamic one created above
# Example translate_text function placeholder
def translate_text(text, source_language, target_language):
return "Translation function implementation"
# Create dropdowns for source and target languages, using only the codes for value
source_language_dropdown = gr.Dropdown(choices=language_options, label="Source Language")
target_language_dropdown = gr.Dropdown(choices=language_options, label="Target Language")
# Define the interface
iface = gr.Interface(
fn=translate_text,
inputs=[gr.Textbox(lines=2, placeholder="Enter text to translate..."), source_language_dropdown, target_language_dropdown],
outputs=gr.Textbox(),
title="Text Translator with Dynamic Language Options",
description="Select source and target languages to translate text."
)
# Launch the app
iface.launch() |