File size: 1,383 Bytes
2c1579a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5bd03d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7e78c03
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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")
}