Spaces:
Sleeping
Sleeping
Rename app.py to Scoring System.py
Browse files- Scoring System.py +25 -0
- app.py +0 -93
Scoring System.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# scoring.py
|
| 2 |
+
BAND_CRITERIA = {
|
| 3 |
+
'vocab': {
|
| 4 |
+
9: {"threshold": 0.9, "description": "Sophisticated lexical items"},
|
| 5 |
+
8: {"threshold": 0.8, "description": "Wide resource, occasional errors"},
|
| 6 |
+
7: {"threshold": 0.7, "description": "Adequate range"},
|
| 7 |
+
6: {"threshold": 0.6, "description": "Limited range"}
|
| 8 |
+
},
|
| 9 |
+
'grammar': {
|
| 10 |
+
9: {"errors": 0, "description": "Virtually error-free"},
|
| 11 |
+
8: {"errors": 2, "description": "Rare minor errors"},
|
| 12 |
+
7: {"errors": 4, "description": "Some errors"},
|
| 13 |
+
6: {"errors": 6, "description": "Frequent errors"}
|
| 14 |
+
}
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
def convert_to_band(raw_score, category):
|
| 18 |
+
"""Convert raw model output to IELTS band"""
|
| 19 |
+
bands = sorted(BAND_CRITERIA[category].items(), reverse=True)
|
| 20 |
+
for band, criteria in bands:
|
| 21 |
+
if category == 'vocab' and raw_score >= criteria['threshold']:
|
| 22 |
+
return band
|
| 23 |
+
elif category == 'grammar' and raw_score <= criteria['errors']:
|
| 24 |
+
return band
|
| 25 |
+
return 4 # Minimum band
|
app.py
DELETED
|
@@ -1,93 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import spacy
|
| 3 |
-
import requests
|
| 4 |
-
from transformers import pipeline
|
| 5 |
-
from supabase import create_client
|
| 6 |
-
from statistics import mean
|
| 7 |
-
|
| 8 |
-
# Configuration
|
| 9 |
-
SUPABASE_URL = "your-supabase-url"
|
| 10 |
-
SUPABASE_KEY = "your-supabase-key"
|
| 11 |
-
HF_TOKEN = "your-hf-token"
|
| 12 |
-
nlp = spacy.load("en_core_web_lg")
|
| 13 |
-
|
| 14 |
-
# Models
|
| 15 |
-
MODELS = {
|
| 16 |
-
"vocab": pipeline("text-classification",
|
| 17 |
-
model="domenicrosati/IELTS-writing-task-2-rater"),
|
| 18 |
-
"grammar": pipeline("text2text-generation",
|
| 19 |
-
model="vennify/t5-base-grammar-correction"),
|
| 20 |
-
"coherence": pipeline("feature-extraction",
|
| 21 |
-
model="sentence-transformers/all-mpnet-base-v2")
|
| 22 |
-
}
|
| 23 |
-
|
| 24 |
-
# Supabase Client
|
| 25 |
-
supabase = create_client(SUPABASE_URL, SUPABASE_KEY)
|
| 26 |
-
|
| 27 |
-
def analyze_text(essay):
|
| 28 |
-
"""Comprehensive text analysis using multiple NLP techniques"""
|
| 29 |
-
doc = nlp(essay)
|
| 30 |
-
|
| 31 |
-
# Vocabulary Analysis
|
| 32 |
-
vocab_score = MODELS["vocab"](essay)[0]["score"] * 9
|
| 33 |
-
|
| 34 |
-
# Grammar Analysis
|
| 35 |
-
grammar_errors = len(MODELS["grammar"](f"grammar: {essay}")[0]["generated_text"].split("<error>")) - 1
|
| 36 |
-
grammar_score = max(1, 9 - (grammar_errors // 1.2))
|
| 37 |
-
|
| 38 |
-
# Coherence Analysis
|
| 39 |
-
embeddings = MODELS["coherence"](essay)
|
| 40 |
-
transition_words = ["however", "moreover", "furthermore", "consequently"]
|
| 41 |
-
transitions = sum(1 for token in doc if token.text.lower() in transition_words)
|
| 42 |
-
coherence_score = min(9, 4 + (transitions * 0.5) + (len(doc.ents) * 0.2))
|
| 43 |
-
|
| 44 |
-
# Task Achievement (Using Mistral-7B)
|
| 45 |
-
task_response = requests.post(
|
| 46 |
-
"https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.3",
|
| 47 |
-
headers={"Authorization": f"Bearer {HF_TOKEN}"},
|
| 48 |
-
json={"inputs": f"Rate IELTS task achievement (1-9): {essay}"}
|
| 49 |
-
)
|
| 50 |
-
task_score = int(task_response.json()[0]["generated_text"][:1]) if task_response.ok else 6
|
| 51 |
-
|
| 52 |
-
return {
|
| 53 |
-
"vocab": round(vocab_score, 1),
|
| 54 |
-
"grammar": grammar_score,
|
| 55 |
-
"coherence": round(coherence_score, 1),
|
| 56 |
-
"task": task_score,
|
| 57 |
-
"overall": round(mean([vocab_score, grammar_score, coherence_score, task_score]), 1)
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
def evaluate_ielts(essay):
|
| 61 |
-
analysis = analyze_text(essay)
|
| 62 |
-
|
| 63 |
-
# Store results
|
| 64 |
-
supabase.table("ielts_results").insert({
|
| 65 |
-
"essay": essay,
|
| 66 |
-
"scores": analysis,
|
| 67 |
-
"timestamp": "now()"
|
| 68 |
-
}).execute()
|
| 69 |
-
|
| 70 |
-
return analysis
|
| 71 |
-
|
| 72 |
-
# Professional Gradio Interface
|
| 73 |
-
with gr.Blocks(theme=gr.themes.Soft(), css=".gradio-container {max-width: 800px!important}") as demo:
|
| 74 |
-
gr.Markdown("## Professional IELTS Evaluation System")
|
| 75 |
-
|
| 76 |
-
with gr.Row():
|
| 77 |
-
essay_input = gr.Textbox(label="Enter Essay", lines=10,
|
| 78 |
-
placeholder="Discuss both views and give your opinion...")
|
| 79 |
-
output_json = gr.JSON(label="Evaluation Results")
|
| 80 |
-
|
| 81 |
-
with gr.Row():
|
| 82 |
-
gr.Examples(
|
| 83 |
-
examples=[
|
| 84 |
-
["While some argue technology improves learning, others believe it distracts students. This essay examines both perspectives before concluding that balanced use offers optimal benefits."],
|
| 85 |
-
["Environmental protection requires global cooperation. Governments must implement stricter regulations while promoting sustainable energy alternatives to combat climate change effectively."]
|
| 86 |
-
],
|
| 87 |
-
inputs=essay_input
|
| 88 |
-
)
|
| 89 |
-
|
| 90 |
-
submit_btn = gr.Button("Evaluate", variant="primary")
|
| 91 |
-
submit_btn.click(fn=evaluate_ielts, inputs=essay_input, outputs=output_json)
|
| 92 |
-
|
| 93 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|