Spaces:
Runtime error
Runtime error
File size: 1,985 Bytes
ecbb694 44f548c a220e3e db19c0d 69ec052 b61920c 4a96c16 ecd242d 4e78963 4a96c16 eecdd62 4a96c16 1acb0b1 4a96c16 b61920c 80a12dd 6fb6258 204e990 80a12dd 204e990 6fb6258 204e990 6fb6258 80a12dd b61920c |
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
#!pip install transformers # put transformers in the requirements.txt file
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
en_nl_tokenizer = AutoTokenizer.from_pretrained("Helsinki-NLP/opus-mt-en-nl")
en_nl_model = AutoModelForSeq2SeqLM.from_pretrained("Helsinki-NLP/opus-mt-en-nl")
#translation_pipeline = pipeline("text-classification", model=finbert_sentiment_prosus, tokenizer=finbert_sentiment_prosus_tokenizer)
en_nl_translator = pipeline("translation_en_to_nl", model = en_nl_model, tokenizer=en_nl_tokenizer) #might ignore "translation_en_to_nl"
#
#gr.Interface.load("models/Helsinki-NLP/opus-mt-en-nl").launch()
def translate(df):
#translate the input_text
for i in range(len(df['English'])):
input_string = str(df.loc[i, 'English'])
if input_string == '':
pass
else:
df.loc[i, 'Dutch'] = en_nl_translator(input_string)[0]['translation_text'] #extract from list, then take the value associated to key 'translation_text'
return df
input_df = gr.Dataframe(
headers=["English", "Dutch"],
datatype=["str", "str"],
row_count=5,
col_count=(2, "fixed"),
)
batch_translate = gr.Interface(
fn = translate,
inputs = input_df, #[input1, input2]
outputs = "dataframe",
description = "Fill in with text you want to translate"
)
if __name__ == "__main__":
batch_translate.launch()
"""
def translate(a):
return a
demo = gr.Interface(
fn = some_func,
[
gr.Dataframe(
headers=["English", "Dutch"],
datatype=["str", "str"],
row_count=10,
col_count=(2, "fixed"),
),
gr.Dropdown(["M", "F", "O"]),
],
"dataframe",
description="Add the English text you want to translate",
)
if __name__ == "__main__":
gr.Interface.load("models/Helsinki-NLP/opus-mt-en-nl").launch()
#demo.launch()
"""
|