Update app.py
Browse files
app.py
CHANGED
@@ -110,9 +110,19 @@ def detect_grammar_errors(text):
|
|
110 |
outputs = grammar_model.generate(inputs, max_length=512, num_beams=4, early_stopping=True)
|
111 |
grammar_analysis = grammar_tokenizer.decode(outputs[0], skip_special_tokens=True)
|
112 |
|
113 |
-
#
|
114 |
-
|
115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
|
117 |
def penalize_for_grammar(student_answer):
|
118 |
grammar_errors = detect_grammar_errors(student_answer)
|
|
|
110 |
outputs = grammar_model.generate(inputs, max_length=512, num_beams=4, early_stopping=True)
|
111 |
grammar_analysis = grammar_tokenizer.decode(outputs[0], skip_special_tokens=True)
|
112 |
|
113 |
+
# Compare the corrected sentence with the original one
|
114 |
+
corrected_sentence = grammar_analysis
|
115 |
+
|
116 |
+
# Simple heuristic to count changes as errors (e.g., difference in word count)
|
117 |
+
# You can also use edit distance or other sophisticated techniques to count errors
|
118 |
+
original_words = text.split()
|
119 |
+
corrected_words = corrected_sentence.split()
|
120 |
+
|
121 |
+
# Calculate a rough estimate of grammar errors based on differences in word count
|
122 |
+
error_count = abs(len(original_words) - len(corrected_words))
|
123 |
+
|
124 |
+
return error_count, corrected_sentence
|
125 |
+
|
126 |
|
127 |
def penalize_for_grammar(student_answer):
|
128 |
grammar_errors = detect_grammar_errors(student_answer)
|