Spaces:
Sleeping
Sleeping
| # app.py | |
| import gradio as gr | |
| from transformers import pipeline | |
| # Load Falcon-7B-Instruct or fallback model | |
| model_id = "tiiuae/falcon-7b-instruct" | |
| polisher = pipeline("text-generation", | |
| model=model_id, | |
| torch_dtype="auto", | |
| trust_remote_code=True) | |
| def oxford_polish(sentence): | |
| prompt = ( | |
| "You are an Oxford grammar professor. " | |
| "Rewrite the following sentence in 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.\n\n" | |
| f"Sentence: {sentence}\n\nCorrected:" | |
| ) | |
| out = polisher(prompt, max_new_tokens=80, do_sample=False) | |
| return out[0]["generated_text"].split("Corrected:")[-1].strip() | |
| # Gradio interface | |
| demo = gr.Interface( | |
| fn=oxford_polish, | |
| 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 Falcon-7B-Instruct." | |
| ) | |
| demo.launch() | |