Leonard Püttmann commited on
Commit
60af901
·
verified ·
1 Parent(s): 122c55f

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -1,9 +1,10 @@
1
- #import spaces
2
  import torch
3
  import gradio as gr
4
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
5
  import spacy
6
 
 
7
  class ModelSingleton:
8
  _instance = None
9
 
@@ -28,18 +29,19 @@ class ModelSingleton:
28
 
29
  model_singleton = ModelSingleton()
30
 
31
- #@spaces.GPU(duration=30)
32
  def generate_response_en_it(input_text):
33
  input_ids = model_singleton.tokenizer_en_it("translate English to Italian: " + input_text, return_tensors="pt").input_ids
34
  output = model_singleton.model_en_it.generate(input_ids, max_new_tokens=256)
35
  return model_singleton.tokenizer_en_it.decode(output[0], skip_special_tokens=True)
36
 
37
- #@spaces.GPU(duration=30)
38
  def generate_response_it_en(input_text):
39
  input_ids = model_singleton.tokenizer_it_en("translate Italian to English: " + input_text, return_tensors="pt").input_ids
40
  output = model_singleton.model_it_en.generate(input_ids, max_new_tokens=256)
41
  return model_singleton.tokenizer_it_en.decode(output[0], skip_special_tokens=True)
42
 
 
43
  def translate_text(input_text, direction):
44
  if direction == "en-it":
45
  nlp = model_singleton.nlp_en
 
1
+ import spaces
2
  import torch
3
  import gradio as gr
4
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
5
  import spacy
6
 
7
+ @spaces.GPU(duration=30)
8
  class ModelSingleton:
9
  _instance = None
10
 
 
29
 
30
  model_singleton = ModelSingleton()
31
 
32
+ @spaces.GPU(duration=30)
33
  def generate_response_en_it(input_text):
34
  input_ids = model_singleton.tokenizer_en_it("translate English to Italian: " + input_text, return_tensors="pt").input_ids
35
  output = model_singleton.model_en_it.generate(input_ids, max_new_tokens=256)
36
  return model_singleton.tokenizer_en_it.decode(output[0], skip_special_tokens=True)
37
 
38
+ @spaces.GPU(duration=30)
39
  def generate_response_it_en(input_text):
40
  input_ids = model_singleton.tokenizer_it_en("translate Italian to English: " + input_text, return_tensors="pt").input_ids
41
  output = model_singleton.model_it_en.generate(input_ids, max_new_tokens=256)
42
  return model_singleton.tokenizer_it_en.decode(output[0], skip_special_tokens=True)
43
 
44
+ @spaces.GPU(duration=30)
45
  def translate_text(input_text, direction):
46
  if direction == "en-it":
47
  nlp = model_singleton.nlp_en