Download app.py from DAIK01/TestAPI: direct link, hf CLI and curl.
- Browser
- Download file 826 Bytes
-
https://huggingface.co/spaces/DAIK01/TestAPI/resolve/main/app.py
- Command line
-
hf download hf://spaces/DAIK01/TestAPI/app.py
-
curl -L -o app.py https://huggingface.co/spaces/DAIK01/TestAPI/resolve/main/app.py
826 Bytes
| import gradio as gr | |
| from transformers import MarianMTModel, MarianTokenizer | |
| # Load the model and tokenizer | |
| model_name = "Helsinki-NLP/opus-mt-nl-en" | |
| tokenizer = MarianTokenizer.from_pretrained(model_name) | |
| model = MarianMTModel.from_pretrained(model_name) | |
| def translate(text): | |
| # Tokenize input text | |
| tokenized_text = tokenizer(text, return_tensors="pt", padding=True, truncation=True) | |
| # Perform translation | |
| translated = model.generate(**tokenized_text) | |
| # Decode translated text | |
| return tokenizer.decode(translated[0], skip_special_tokens=True) | |
| # Define Gradio interface | |
| interface = gr.Interface(fn=translate, inputs="text", outputs="text", title="Dutch to English Translator", description="Translate Dutch text to English using Helsinki-NLP/opus-mt-nl-en.") | |
| # Launch the interface | |
| interface.launch() | |