Check if answer as enough words
This commit is contained in:
76
app.py
76
app.py
@@ -220,7 +220,29 @@ def grade_writing_task_1():
|
|||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
question = data.get('question')
|
question = data.get('question')
|
||||||
answer = data.get('answer')
|
answer = data.get('answer')
|
||||||
if has_words(answer):
|
if not has_words(answer):
|
||||||
|
return {
|
||||||
|
'comment': "The answer does not contain any english words.",
|
||||||
|
'overall': 0,
|
||||||
|
'task_response': {
|
||||||
|
'Coherence and Cohesion': 0,
|
||||||
|
'Grammatical Range and Accuracy': 0,
|
||||||
|
'Lexical Resource': 0,
|
||||||
|
'Task Achievement': 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elif not has_x_words(answer, 100):
|
||||||
|
return {
|
||||||
|
'comment': "The answer is insufficient and too small to be graded.",
|
||||||
|
'overall': 0,
|
||||||
|
'task_response': {
|
||||||
|
'Coherence and Cohesion': 0,
|
||||||
|
'Grammatical Range and Accuracy': 0,
|
||||||
|
'Lexical Resource': 0,
|
||||||
|
'Task Achievement': 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else:
|
||||||
message = ("Evaluate the given Writing Task 1 response based on the IELTS grading system, ensuring a "
|
message = ("Evaluate the given Writing Task 1 response based on the IELTS grading system, ensuring a "
|
||||||
"strict assessment that penalizes errors. Deduct points for deviations from the task, and "
|
"strict assessment that penalizes errors. Deduct points for deviations from the task, and "
|
||||||
"assign a score of 0 if the response fails to address the question. Additionally, provide an "
|
"assign a score of 0 if the response fails to address the question. Additionally, provide an "
|
||||||
@@ -236,17 +258,6 @@ def grade_writing_task_1():
|
|||||||
GRADING_TEMPERATURE)
|
GRADING_TEMPERATURE)
|
||||||
response['fixed_text'] = get_fixed_text(answer)
|
response['fixed_text'] = get_fixed_text(answer)
|
||||||
return response
|
return response
|
||||||
else:
|
|
||||||
return {
|
|
||||||
'comment': "The answer does not contain any english words.",
|
|
||||||
'overall': 0,
|
|
||||||
'task_response': {
|
|
||||||
'Coherence and Cohesion': 0,
|
|
||||||
'Grammatical Range and Accuracy': 0,
|
|
||||||
'Lexical Resource': 0,
|
|
||||||
'Task Achievement': 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return str(e)
|
return str(e)
|
||||||
|
|
||||||
@@ -281,7 +292,29 @@ def grade_writing_task_2():
|
|||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
question = data.get('question')
|
question = data.get('question')
|
||||||
answer = data.get('answer')
|
answer = data.get('answer')
|
||||||
if has_words(answer):
|
if not has_words(answer):
|
||||||
|
return {
|
||||||
|
'comment': "The answer does not contain any english words.",
|
||||||
|
'overall': 0,
|
||||||
|
'task_response': {
|
||||||
|
'Coherence and Cohesion': 0,
|
||||||
|
'Grammatical Range and Accuracy': 0,
|
||||||
|
'Lexical Resource': 0,
|
||||||
|
'Task Achievement': 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elif not has_x_words(answer, 180):
|
||||||
|
return {
|
||||||
|
'comment': "The answer is insufficient and too small to be graded.",
|
||||||
|
'overall': 0,
|
||||||
|
'task_response': {
|
||||||
|
'Coherence and Cohesion': 0,
|
||||||
|
'Grammatical Range and Accuracy': 0,
|
||||||
|
'Lexical Resource': 0,
|
||||||
|
'Task Achievement': 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else:
|
||||||
message = ("Evaluate the given Writing Task 2 response based on the IELTS grading system, ensuring a "
|
message = ("Evaluate the given Writing Task 2 response based on the IELTS grading system, ensuring a "
|
||||||
"strict assessment that penalizes errors. Deduct points for deviations from the task, and "
|
"strict assessment that penalizes errors. Deduct points for deviations from the task, and "
|
||||||
"assign a score of 0 if the response fails to address the question. Additionally, provide an "
|
"assign a score of 0 if the response fails to address the question. Additionally, provide an "
|
||||||
@@ -297,17 +330,6 @@ def grade_writing_task_2():
|
|||||||
GEN_QUESTION_TEMPERATURE)
|
GEN_QUESTION_TEMPERATURE)
|
||||||
response['fixed_text'] = get_fixed_text(answer)
|
response['fixed_text'] = get_fixed_text(answer)
|
||||||
return response
|
return response
|
||||||
else:
|
|
||||||
return {
|
|
||||||
'comment': "The answer does not contain any english words.",
|
|
||||||
'overall': 0,
|
|
||||||
'task_response': {
|
|
||||||
'Coherence and Cohesion': 0,
|
|
||||||
'Grammatical Range and Accuracy': 0,
|
|
||||||
'Lexical Resource': 0,
|
|
||||||
'Task Achievement': 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return str(e)
|
return str(e)
|
||||||
|
|
||||||
@@ -368,7 +390,7 @@ def grade_speaking_task_1():
|
|||||||
|
|
||||||
download_firebase_file(FIREBASE_BUCKET, answer_firebase_path, sound_file_name)
|
download_firebase_file(FIREBASE_BUCKET, answer_firebase_path, sound_file_name)
|
||||||
answer = speech_to_text(sound_file_name)
|
answer = speech_to_text(sound_file_name)
|
||||||
if has_50_words(answer):
|
if has_x_words(answer, 20):
|
||||||
message = ("Evaluate the given Speaking Part 1 response based on the IELTS grading system, ensuring a "
|
message = ("Evaluate the given Speaking Part 1 response based on the IELTS grading system, ensuring a "
|
||||||
"strict assessment that penalizes errors. Deduct points for deviations from the task, and "
|
"strict assessment that penalizes errors. Deduct points for deviations from the task, and "
|
||||||
"assign a score of 0 if the response fails to address the question. Additionally, provide "
|
"assign a score of 0 if the response fails to address the question. Additionally, provide "
|
||||||
@@ -447,7 +469,7 @@ def grade_speaking_task_2():
|
|||||||
|
|
||||||
download_firebase_file(FIREBASE_BUCKET, answer_firebase_path, sound_file_name)
|
download_firebase_file(FIREBASE_BUCKET, answer_firebase_path, sound_file_name)
|
||||||
answer = speech_to_text(sound_file_name)
|
answer = speech_to_text(sound_file_name)
|
||||||
if has_50_words(answer):
|
if has_x_words(answer, 20):
|
||||||
message = ("Evaluate the given Speaking Part 2 response based on the IELTS grading system, ensuring a "
|
message = ("Evaluate the given Speaking Part 2 response based on the IELTS grading system, ensuring a "
|
||||||
"strict assessment that penalizes errors. Deduct points for deviations from the task, and "
|
"strict assessment that penalizes errors. Deduct points for deviations from the task, and "
|
||||||
"assign a score of 0 if the response fails to address the question. Additionally, provide "
|
"assign a score of 0 if the response fails to address the question. Additionally, provide "
|
||||||
@@ -559,7 +581,7 @@ def grade_speaking_task_3():
|
|||||||
text_answers.append(answer_text)
|
text_answers.append(answer_text)
|
||||||
item["answer"] = answer_text
|
item["answer"] = answer_text
|
||||||
os.remove(sound_file_name)
|
os.remove(sound_file_name)
|
||||||
if not has_50_words(answer_text):
|
if not has_x_words(answer_text, 20):
|
||||||
return {
|
return {
|
||||||
"comment": "The audio recorded does not contain enough english words to be graded.",
|
"comment": "The audio recorded does not contain enough english words to be graded.",
|
||||||
"overall": 0,
|
"overall": 0,
|
||||||
|
|||||||
@@ -94,11 +94,11 @@ def has_words(text: str):
|
|||||||
words_in_input = text.split()
|
words_in_input = text.split()
|
||||||
return any(word.lower() in english_words for word in words_in_input)
|
return any(word.lower() in english_words for word in words_in_input)
|
||||||
|
|
||||||
def has_50_words(text: str):
|
def has_x_words(text: str, quantity):
|
||||||
english_words = set(words.words())
|
english_words = set(words.words())
|
||||||
words_in_input = text.split()
|
words_in_input = text.split()
|
||||||
english_word_count = sum(1 for word in words_in_input if word.lower() in english_words)
|
english_word_count = sum(1 for word in words_in_input if word.lower() in english_words)
|
||||||
return english_word_count >= 50
|
return english_word_count >= quantity
|
||||||
|
|
||||||
def divide_text(text, max_length=3000):
|
def divide_text(text, max_length=3000):
|
||||||
if len(text) <= max_length:
|
if len(text) <= max_length:
|
||||||
|
|||||||
Reference in New Issue
Block a user