Spaces:
Sleeping
Sleeping
Create Core Analysis Logic.py
Browse files- Core Analysis Logic.py +16 -0
Core Analysis Logic.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py (middle section)
|
| 2 |
+
def analyze_essay(essay):
|
| 3 |
+
# Vocabulary analysis
|
| 4 |
+
vocab_raw = MODELS["vocab"](essay)[0]["score"]
|
| 5 |
+
vocab_band = convert_to_band(vocab_raw, 'vocab')
|
| 6 |
+
|
| 7 |
+
# Grammar analysis
|
| 8 |
+
corrections = MODELS["grammar"](f"Fix: {essay}")[0]["generated_text"]
|
| 9 |
+
error_count = corrections.count('<error>')
|
| 10 |
+
grammar_band = convert_to_band(error_count, 'grammar')
|
| 11 |
+
|
| 12 |
+
return {
|
| 13 |
+
"vocabulary": vocab_band,
|
| 14 |
+
"grammar": grammar_band,
|
| 15 |
+
"overall": (vocab_band + grammar_band) / 2
|
| 16 |
+
}
|