alphaprep commited on
Commit
7592c61
·
verified ·
1 Parent(s): 18d5021

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
+ import torch
4
+ import numpy as np
5
+
6
+ # Load model and tokenizer
7
+ model_name = "KevSun/IELTS_essay_scoring"
8
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
9
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
10
+
11
+ # Prediction function
12
+ def score_essay(essay):
13
+ inputs = tokenizer(essay, return_tensors="pt", truncation=True, max_length=512)
14
+ with torch.no_grad():
15
+ outputs = model(**inputs)
16
+ preds = outputs.logits.squeeze().numpy()
17
+ normalized = (preds / preds.max()) * 9
18
+ rounded = np.round(normalized * 2) / 2
19
+ labels = ["Task Achievement", "Coherence & Cohesion", "Vocabulary", "Grammar", "Overall"]
20
+ return {label: float(score) for label, score in zip(labels, rounded)}
21
+
22
+ # Gradio UI
23
+ iface = gr.Interface(
24
+ fn=score_essay,
25
+ inputs=gr.Textbox(lines=10, placeholder="Paste your IELTS essay here..."),
26
+ outputs=[gr.Label(num_top_classes=5)],
27
+ title="Automated IELTS Essay Scorer",
28
+ description="Predicts scores for multiple dimensions of your essay"
29
+ )
30
+
31
+ iface.launch()