Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,24 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
| 3 |
import torch
|
|
|
|
| 4 |
|
| 5 |
# Load the models and tokenizers for each translation direction
|
| 6 |
# Faroese to English
|
| 7 |
model_faero_eng = AutoModelForSeq2SeqLM.from_pretrained("barbaroo/nllb_200_600M_fo_en")
|
| 8 |
-
tokenizer_faero_eng = AutoTokenizer.from_pretrained("barbaroo/nllb_200_600M_fo_en", src_lang
|
| 9 |
|
| 10 |
# English to Faroese
|
| 11 |
model_eng_faero = AutoModelForSeq2SeqLM.from_pretrained("barbaroo/nllb_200_1.3B_en_fo")
|
| 12 |
-
tokenizer_eng_faero = AutoTokenizer.from_pretrained("barbaroo/nllb_200_1.3B_en_fo", src_lang
|
| 13 |
|
| 14 |
# Check if GPU is available
|
| 15 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 16 |
model_faero_eng.to(device)
|
| 17 |
model_eng_faero.to(device)
|
| 18 |
|
|
|
|
|
|
|
| 19 |
def translate(text, direction):
|
| 20 |
if direction == "Faroese to English":
|
| 21 |
# Encode the text for Faroese to English
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
| 3 |
import torch
|
| 4 |
+
import spaces # Import spaces for ZeroGPU compatibility
|
| 5 |
|
| 6 |
# Load the models and tokenizers for each translation direction
|
| 7 |
# Faroese to English
|
| 8 |
model_faero_eng = AutoModelForSeq2SeqLM.from_pretrained("barbaroo/nllb_200_600M_fo_en")
|
| 9 |
+
tokenizer_faero_eng = AutoTokenizer.from_pretrained("barbaroo/nllb_200_600M_fo_en", src_lang="fao_Latn")
|
| 10 |
|
| 11 |
# English to Faroese
|
| 12 |
model_eng_faero = AutoModelForSeq2SeqLM.from_pretrained("barbaroo/nllb_200_1.3B_en_fo")
|
| 13 |
+
tokenizer_eng_faero = AutoTokenizer.from_pretrained("barbaroo/nllb_200_1.3B_en_fo", src_lang="eng_Latn")
|
| 14 |
|
| 15 |
# Check if GPU is available
|
| 16 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 17 |
model_faero_eng.to(device)
|
| 18 |
model_eng_faero.to(device)
|
| 19 |
|
| 20 |
+
# Use @spaces.GPU to specify GPU usage for the translation function
|
| 21 |
+
@spaces.GPU # Apply ZeroGPU decorator
|
| 22 |
def translate(text, direction):
|
| 23 |
if direction == "Faroese to English":
|
| 24 |
# Encode the text for Faroese to English
|