init
Browse files- README.md +3 -0
- app.py +22 -0
- requirements.txt +5 -0
README.md
CHANGED
|
@@ -11,3 +11,6 @@ short_description: This is my space, i want to make more ..
|
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 14 |
+
|
| 15 |
+
# Grammar Corrector using grammarly/coedit-xl
|
| 16 |
+
This is a FastAPI app deployed on Hugging Face Spaces using the `grammarly/coedit-xl` model to fix English grammar issues.
|
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Request
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
app = FastAPI()
|
| 7 |
+
|
| 8 |
+
# Load model + tokenizer
|
| 9 |
+
model_name = "grammarly/coedit-xl"
|
| 10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 11 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 12 |
+
|
| 13 |
+
class InputText(BaseModel):
|
| 14 |
+
text: str
|
| 15 |
+
|
| 16 |
+
@app.post("/correct")
|
| 17 |
+
async def correct_text(data: InputText):
|
| 18 |
+
input_text = data.text
|
| 19 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
| 20 |
+
outputs = model.generate(**inputs, max_new_tokens=256)
|
| 21 |
+
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 22 |
+
return {"corrected": result}
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers
|
| 2 |
+
torch
|
| 3 |
+
fastapi
|
| 4 |
+
uvicorn
|
| 5 |
+
pydantic
|