nltk update
Browse files
app.py
CHANGED
@@ -2,7 +2,9 @@ from fastapi import FastAPI
|
|
2 |
from pydantic import BaseModel
|
3 |
from fastapi.responses import JSONResponse
|
4 |
from transformers import AutoTokenizer,AutoModelForSeq2SeqLM
|
|
|
5 |
from nltk.tokenize import sent_tokenize
|
|
|
6 |
import torch
|
7 |
|
8 |
app = FastAPI()
|
@@ -10,6 +12,7 @@ app = FastAPI()
|
|
10 |
class Sentence(BaseModel):
|
11 |
sentence: str
|
12 |
|
|
|
13 |
# model_name = 'Vamsi/T5_Paraphrase_Paws'
|
14 |
model_name = 'google/flan-t5-large'
|
15 |
tokenizer = AutoTokenizer.from_pretrained(model_name,clean_up_tokenization_spaces=True)
|
@@ -46,5 +49,6 @@ def rephrase(sentence: Sentence):
|
|
46 |
try:
|
47 |
rephrase_text = " ".join([my_rephrase(sent) for sent in sent_tokenize(sentence.sentence) ])
|
48 |
return JSONResponse(status_code=200, content={"rephrased_sentence": rephrase_text})
|
49 |
-
except:
|
|
|
50 |
return JSONResponse(status_code=422,content="Unable to rephrase")
|
|
|
2 |
from pydantic import BaseModel
|
3 |
from fastapi.responses import JSONResponse
|
4 |
from transformers import AutoTokenizer,AutoModelForSeq2SeqLM
|
5 |
+
import nltk
|
6 |
from nltk.tokenize import sent_tokenize
|
7 |
+
nltk.download('punkt_tab')
|
8 |
import torch
|
9 |
|
10 |
app = FastAPI()
|
|
|
12 |
class Sentence(BaseModel):
|
13 |
sentence: str
|
14 |
|
15 |
+
|
16 |
# model_name = 'Vamsi/T5_Paraphrase_Paws'
|
17 |
model_name = 'google/flan-t5-large'
|
18 |
tokenizer = AutoTokenizer.from_pretrained(model_name,clean_up_tokenization_spaces=True)
|
|
|
49 |
try:
|
50 |
rephrase_text = " ".join([my_rephrase(sent) for sent in sent_tokenize(sentence.sentence) ])
|
51 |
return JSONResponse(status_code=200, content={"rephrased_sentence": rephrase_text})
|
52 |
+
except Exception as e:
|
53 |
+
print(e)
|
54 |
return JSONResponse(status_code=422,content="Unable to rephrase")
|