Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from pydantic import BaseModel
|
3 |
+
from happytransformer import HappyTextToText, TTSettings
|
4 |
+
|
5 |
+
app = FastAPI()
|
6 |
+
|
7 |
+
happy_tt = HappyTextToText("T5", "vennify/t5-base-grammar-correction")
|
8 |
+
|
9 |
+
class InputText(BaseModel):
|
10 |
+
txt: str
|
11 |
+
|
12 |
+
@app.post("/correct_grammar/")
|
13 |
+
def correct_grammar(input_text: InputText):
|
14 |
+
args = TTSettings(num_beams=5, min_length=1, max_length=100000)
|
15 |
+
corrected_text = happy_tt.generate_text(f"grammar: {input_text.txt}", args=args)
|
16 |
+
return {"corrected_text": corrected_text.text}
|
17 |
+
|
18 |
+
if __name__ == "__main__":
|
19 |
+
import uvicorn
|
20 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|