Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,39 +1,48 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
import requests
|
|
|
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 8 |
|
| 9 |
def evaluate_ielts(essay):
|
| 10 |
-
#
|
| 11 |
vocab_result = vocab_model(essay)[0]
|
| 12 |
-
vocab_score = round(vocab_result['score'] * 9, 1)
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
grammar_response = requests.post(
|
|
|
|
|
|
|
|
|
|
| 16 |
grammar_errors = len(grammar_response.json()['matches'])
|
| 17 |
-
grammar_score = 9 -
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
#
|
| 23 |
-
|
| 24 |
|
| 25 |
return {
|
| 26 |
-
"Vocabulary Band": vocab_score,
|
| 27 |
"Grammar Band": grammar_score,
|
| 28 |
"Coherence Band": coherence_score,
|
| 29 |
-
"Overall Band": round(
|
| 30 |
}
|
| 31 |
|
| 32 |
-
# Create Interface
|
| 33 |
gr.Interface(
|
| 34 |
fn=evaluate_ielts,
|
| 35 |
-
inputs=gr.Textbox(label="
|
| 36 |
outputs=gr.JSON(),
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
| 39 |
).launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
import requests
|
| 4 |
+
import spacy
|
| 5 |
|
| 6 |
+
# Load models
|
| 7 |
+
nlp = spacy.load("en_core_web_sm") # For coherence analysis
|
| 8 |
+
vocab_model = pipeline("text-classification", model="textattack/bert-base-uncased-CoLA") # Better for essays
|
| 9 |
|
| 10 |
def evaluate_ielts(essay):
|
| 11 |
+
# Vocabulary Assessment
|
| 12 |
vocab_result = vocab_model(essay)[0]
|
| 13 |
+
vocab_score = round(vocab_result['score'] * 9 * 1.2, 1) # Adjusted multiplier
|
| 14 |
|
| 15 |
+
# Grammar Check (LanguageTool API)
|
| 16 |
+
grammar_response = requests.post(
|
| 17 |
+
"https://api.languagetool.org/v2/check",
|
| 18 |
+
data={"text": essay, "language": "en-GB"}
|
| 19 |
+
)
|
| 20 |
grammar_errors = len(grammar_response.json()['matches'])
|
| 21 |
+
grammar_score = max(1, 9 - (grammar_errors // 1.5)) # 1.5 errors = 1 point deduction
|
| 22 |
|
| 23 |
+
# Coherence Analysis
|
| 24 |
+
doc = nlp(essay)
|
| 25 |
+
transition_words = ["however", "moreover", "therefore", "consequently"]
|
| 26 |
+
transitions = sum(1 for token in doc if token.text.lower() in transition_words)
|
| 27 |
+
coherence_score = min(9, transitions + 4) # 4-9 scale
|
| 28 |
|
| 29 |
+
# Overall Band (IELTS-style weighting)
|
| 30 |
+
overall = (vocab_score * 0.4) + (grammar_score * 0.3) + (coherence_score * 0.3)
|
| 31 |
|
| 32 |
return {
|
| 33 |
+
"Vocabulary Band": min(9, vocab_score),
|
| 34 |
"Grammar Band": grammar_score,
|
| 35 |
"Coherence Band": coherence_score,
|
| 36 |
+
"Overall Band": round(overall, 1)
|
| 37 |
}
|
| 38 |
|
|
|
|
| 39 |
gr.Interface(
|
| 40 |
fn=evaluate_ielts,
|
| 41 |
+
inputs=gr.Textbox(label="Essay", lines=7),
|
| 42 |
outputs=gr.JSON(),
|
| 43 |
+
examples=[[
|
| 44 |
+
"Education plays a vital role in societal development. "
|
| 45 |
+
"Firstly, it equips individuals with critical thinking skills. "
|
| 46 |
+
"Furthermore, educated citizens contribute to economic growth."
|
| 47 |
+
]]
|
| 48 |
).launch()
|