tinyInstruct / app.py
AItool's picture
changing model
b9591bd verified
raw
history blame
1.33 kB
# app.py
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
model_id = "deep-learning-analytics/GrammarCorrector"
# Load tokenizer and model
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
# Create pipeline
polisher = pipeline("text2text-generation",
model=model,
tokenizer=tokenizer)
def oxford_polish_strict(sentence: str) -> str:
prompt = (
"Correct this sentence into formal written English, following the Oxford University Style Guide. "
"Ensure tense matches time expressions (e.g. 'tomorrow' → future, 'yesterday' → past), "
"use British spelling, apply the Oxford comma, and correct uncountable nouns naturally. "
"Sentence: " + sentence
)
out = polisher(prompt, max_new_tokens=80, do_sample=False)
return out[0]["generated_text"].strip()
# Gradio interface
demo = gr.Interface(
fn=oxford_polish_strict,
inputs=gr.Textbox(lines=2, placeholder="Enter a sentence to correct..."),
outputs=gr.Textbox(label="Oxford-style Correction"),
title="Oxford Grammar Polisher",
description="Rewrite sentences in formal written English using Oxford grammar rules. Powered by GrammarCorrector (T5-base)."
)
demo.launch()