ArxAlfa commited on
Commit
6f83a0d
1 Parent(s): 8da01f8

Refactor translation endpoint

Browse files
Files changed (1) hide show
  1. app.py +4 -7
app.py CHANGED
@@ -5,20 +5,17 @@ from transformers import T5Tokenizer, T5ForConditionalGeneration
5
  # Create a new FastAPI app instance
6
  app = FastAPI(docs_url="/", redoc_url="/new_redoc")
7
 
8
- # Initialize the text generation pipeline
9
- # This function will be able to generate text
10
- # given an input.
11
- # pipe = pipeline("translation", model="t5-small")
12
-
13
  tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-small")
14
  model = T5ForConditionalGeneration.from_pretrained("google/flan-t5-small")
15
 
16
 
 
17
  @app.get("/generate")
18
  def generate(text: str):
19
- """Translate a text input to another language"""
20
 
21
- input_text = "translate English to German: " + text
22
  input_ids = tokenizer(input_text, return_tensors="pt").input_ids
23
 
24
  outputs = model.generate(input_ids)
 
5
  # Create a new FastAPI app instance
6
  app = FastAPI(docs_url="/", redoc_url="/new_redoc")
7
 
8
+ # Create a translation pipeline
 
 
 
 
9
  tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-small")
10
  model = T5ForConditionalGeneration.from_pretrained("google/flan-t5-small")
11
 
12
 
13
+ # Create a POST endpoint
14
  @app.get("/generate")
15
  def generate(text: str):
16
+ """Traduce del castellano al inglés"""
17
 
18
+ input_text = "translate Spanish to English: " + text
19
  input_ids = tokenizer(input_text, return_tensors="pt").input_ids
20
 
21
  outputs = model.generate(input_ids)