Spaces:
Sleeping
Sleeping
| # app.py (middle section) | |
| def analyze_essay(essay): | |
| # Vocabulary analysis | |
| vocab_raw = MODELS["vocab"](essay)[0]["score"] | |
| vocab_band = convert_to_band(vocab_raw, 'vocab') | |
| # Grammar analysis | |
| corrections = MODELS["grammar"](f"Fix: {essay}")[0]["generated_text"] | |
| error_count = corrections.count('<error>') | |
| grammar_band = convert_to_band(error_count, 'grammar') | |
| return { | |
| "vocabulary": vocab_band, | |
| "grammar": grammar_band, | |
| "overall": (vocab_band + grammar_band) / 2 | |
| } | |
| # app.py (bottom section) | |
| with gr.Blocks(theme=gr.themes.Soft()) as demo: | |
| gr.Markdown("## IELTS Writing Evaluator") | |
| with gr.Row(): | |
| input_essay = gr.Textbox(label="Your Essay", lines=10) | |
| output_scores = gr.JSON(label="Results") | |
| gr.Examples( | |
| examples=[ | |
| ["Education plays a vital role in societal development..."] | |
| ], | |
| inputs=input_essay | |
| ) | |
| submit = gr.Button("Evaluate") | |
| submit.click(analyze_essay, inputs=input_essay, outputs=output_scores) | |
| demo.launch() | |
| # app.py (after imports) | |
| from transformers import pipeline | |
| MODELS = { | |
| "vocab": pipeline("text-classification", | |
| model="domenicrosati/IELTS-writing-task-2-rater"), | |
| "grammar": pipeline("text2text-generation", | |
| model="vennify/t5-base-grammar-correction") | |
| } |