Spaces:
Running
on
Zero
Running
on
Zero
Leonard Püttmann
commited on
Upload 2 files
Browse files- app.py +6 -2
- requirements.txt +1 -2
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
import spacy
|
@@ -17,20 +18,22 @@ class ModelSingleton:
|
|
17 |
|
18 |
# Load translation models and tokenizers
|
19 |
self.tokenizer_en_it = AutoTokenizer.from_pretrained("LeonardPuettmann/Quadrifoglio-mt-en-it")
|
20 |
-
self.model_en_it = AutoModelForSeq2SeqLM.from_pretrained("LeonardPuettmann/Quadrifoglio-mt-en-it"
|
21 |
|
22 |
self.tokenizer_it_en = AutoTokenizer.from_pretrained("LeonardPuettmann/Quadrifoglio-mt-it-en")
|
23 |
-
self.model_it_en = AutoModelForSeq2SeqLM.from_pretrained("LeonardPuettmann/Quadrifoglio-mt-it-en"
|
24 |
|
25 |
self.initialized = True
|
26 |
|
27 |
model_singleton = ModelSingleton()
|
28 |
|
|
|
29 |
def generate_response_en_it(input_text):
|
30 |
input_ids = model_singleton.tokenizer_en_it("translate English to Italian: " + input_text, return_tensors="pt").input_ids
|
31 |
output = model_singleton.model_en_it.generate(input_ids, max_new_tokens=256)
|
32 |
return model_singleton.tokenizer_en_it.decode(output[0], skip_special_tokens=True)
|
33 |
|
|
|
34 |
def generate_response_it_en(input_text):
|
35 |
input_ids = model_singleton.tokenizer_it_en("translate Italian to English: " + input_text, return_tensors="pt").input_ids
|
36 |
output = model_singleton.model_it_en.generate(input_ids, max_new_tokens=256)
|
@@ -67,3 +70,4 @@ iface = gr.Interface(
|
|
67 |
|
68 |
# Launch the interface
|
69 |
iface.launch()
|
|
|
|
1 |
+
import spaces
|
2 |
import gradio as gr
|
3 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
4 |
import spacy
|
|
|
18 |
|
19 |
# Load translation models and tokenizers
|
20 |
self.tokenizer_en_it = AutoTokenizer.from_pretrained("LeonardPuettmann/Quadrifoglio-mt-en-it")
|
21 |
+
self.model_en_it = AutoModelForSeq2SeqLM.from_pretrained("LeonardPuettmann/Quadrifoglio-mt-en-it")
|
22 |
|
23 |
self.tokenizer_it_en = AutoTokenizer.from_pretrained("LeonardPuettmann/Quadrifoglio-mt-it-en")
|
24 |
+
self.model_it_en = AutoModelForSeq2SeqLM.from_pretrained("LeonardPuettmann/Quadrifoglio-mt-it-en")
|
25 |
|
26 |
self.initialized = True
|
27 |
|
28 |
model_singleton = ModelSingleton()
|
29 |
|
30 |
+
@spaces.GPU(duration=30)
|
31 |
def generate_response_en_it(input_text):
|
32 |
input_ids = model_singleton.tokenizer_en_it("translate English to Italian: " + input_text, return_tensors="pt").input_ids
|
33 |
output = model_singleton.model_en_it.generate(input_ids, max_new_tokens=256)
|
34 |
return model_singleton.tokenizer_en_it.decode(output[0], skip_special_tokens=True)
|
35 |
|
36 |
+
@spaces.GPU(duration=30)
|
37 |
def generate_response_it_en(input_text):
|
38 |
input_ids = model_singleton.tokenizer_it_en("translate Italian to English: " + input_text, return_tensors="pt").input_ids
|
39 |
output = model_singleton.model_it_en.generate(input_ids, max_new_tokens=256)
|
|
|
70 |
|
71 |
# Launch the interface
|
72 |
iface.launch()
|
73 |
+
|
requirements.txt
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
-
accelerate
|
2 |
-
bitsandbytes
|
3 |
gradio
|
4 |
transformers
|
5 |
spacy
|
|
|
6 |
torch
|
7 |
en-core-web-sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.7.1/en_core_web_sm-3.7.1-py3-none-any.whl
|
8 |
it-core-news-sm @ https://github.com/explosion/spacy-models/releases/download/it_core_news_sm-3.8.0/it_core_news_sm-3.8.0-py3-none-any.whl
|
|
|
|
|
|
|
1 |
gradio
|
2 |
transformers
|
3 |
spacy
|
4 |
+
spaces
|
5 |
torch
|
6 |
en-core-web-sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.7.1/en_core_web_sm-3.7.1-py3-none-any.whl
|
7 |
it-core-news-sm @ https://github.com/explosion/spacy-models/releases/download/it_core_news_sm-3.8.0/it_core_news_sm-3.8.0-py3-none-any.whl
|