Update app.py
Browse files
app.py
CHANGED
|
@@ -143,7 +143,7 @@ questions = {parsed_questions}
|
|
| 143 |
|
| 144 |
def eval_quiz(name, *answers):
|
| 145 |
"""
|
| 146 |
-
Evaluates the student's answers
|
| 147 |
"""
|
| 148 |
if not name.strip():
|
| 149 |
name = "Anonymous"
|
|
@@ -152,9 +152,20 @@ def eval_quiz(name, *answers):
|
|
| 152 |
if ans and hashlib.sha256(str(ans).lower().strip().encode()).hexdigest() == questions[i]["answer_hash"]:
|
| 153 |
score += 1
|
| 154 |
|
| 155 |
-
|
|
|
|
| 156 |
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
|
| 159 |
# Gradio interface for the student
|
| 160 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
|
|
| 143 |
|
| 144 |
def eval_quiz(name, *answers):
|
| 145 |
"""
|
| 146 |
+
Evaluates the student's answers and generates a certificate only if the score is 80% or higher.
|
| 147 |
"""
|
| 148 |
if not name.strip():
|
| 149 |
name = "Anonymous"
|
|
|
|
| 152 |
if ans and hashlib.sha256(str(ans).lower().strip().encode()).hexdigest() == questions[i]["answer_hash"]:
|
| 153 |
score += 1
|
| 154 |
|
| 155 |
+
total_questions = len(questions)
|
| 156 |
+
passing_threshold = 0.8
|
| 157 |
|
| 158 |
+
result_message = f"Hi {{name}}, your score is: {{score}} / {{total_questions}}."
|
| 159 |
+
cert_path = None # Default to no certificate
|
| 160 |
+
|
| 161 |
+
# Check if the score meets the passing threshold
|
| 162 |
+
if total_questions > 0 and (score / total_questions) >= passing_threshold:
|
| 163 |
+
cert_path = generate_certificate(name, score, total_questions, instructor="{instructor}")
|
| 164 |
+
result_message += " Congratulations, you passed and earned a certificate!"
|
| 165 |
+
else:
|
| 166 |
+
result_message += " A score of 80% is required to receive a certificate."
|
| 167 |
+
|
| 168 |
+
return result_message, cert_path
|
| 169 |
|
| 170 |
# Gradio interface for the student
|
| 171 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|