capradeepgujaran commited on
Commit
3f0cb92
1 Parent(s): f6f42ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -16
app.py CHANGED
@@ -741,8 +741,8 @@ def create_quiz_interface():
741
  0,
742
  "",
743
  gr.update(visible=True),
744
- gr.Tabs(selected=2), # Stay on assessment tab
745
- gr.update(visible=False) # view_cert_btn visibility
746
  ]
747
 
748
  score, passed, feedback = quiz_app.calculate_score(final_answers[:len(questions)])
@@ -751,33 +751,36 @@ def create_quiz_interface():
751
  for i, (q, f) in enumerate(zip(questions, feedback)):
752
  color = "green" if f.is_correct else "red"
753
  symbol = "✅" if f.is_correct else "❌"
 
754
  feedback_html += f"""### Question {i+1}
755
  {q.question}
756
-
757
- <div style="color: {color}; padding: 10px; margin: 5px 0; border-left: 3px solid {color};">
758
  {symbol} Your answer: {f.selected or "No answer"}
759
  {'' if f.is_correct else f'<br>Correct answer: {f.correct_answer}'}
760
- </div>
761
- """
762
 
763
  result_msg = "🎉 Passed!" if passed else "Please try again"
764
  if not passed:
765
- feedback_html += f"""
766
- <div style="background-color: #ffe6e6; padding: 20px; margin-top: 20px; border-radius: 10px;">
767
- <h3 style="color: #cc0000;">Please Try Again</h3>
768
- <p>Your score: {score:.1f}%</p>
769
- <p>You need 80% or higher to pass and receive a certificate.</p>
770
- </div>
771
- """
 
 
 
 
772
 
773
  return [
774
  feedback_html,
775
  gr.update(visible=True),
776
  score,
777
  result_msg,
778
- gr.update(visible=False), # Hide question box
779
- gr.Tabs(selected=2), # Stay on assessment tab
780
- gr.update(visible=passed) # Show view certificate button only if passed
781
  ]
782
  # Event handlers
783
 
 
741
  0,
742
  "",
743
  gr.update(visible=True),
744
+ gr.Tabs(selected=2),
745
+ gr.update(visible=False)
746
  ]
747
 
748
  score, passed, feedback = quiz_app.calculate_score(final_answers[:len(questions)])
 
751
  for i, (q, f) in enumerate(zip(questions, feedback)):
752
  color = "green" if f.is_correct else "red"
753
  symbol = "✅" if f.is_correct else "❌"
754
+
755
  feedback_html += f"""### Question {i+1}
756
  {q.question}
757
+ <div style="color: {color}; padding: 10px; margin: 10px 0; border-left: 3px solid {color}; background-color: {'#f8fff8' if f.is_correct else '#fff8f8'};">
 
758
  {symbol} Your answer: {f.selected or "No answer"}
759
  {'' if f.is_correct else f'<br>Correct answer: {f.correct_answer}'}
760
+ </div>\n"""
 
761
 
762
  result_msg = "🎉 Passed!" if passed else "Please try again"
763
  if not passed:
764
+ feedback_html += f"""<div style="background-color: #ffe6e6; padding: 20px; margin: 20px 0; border-radius: 10px; border: 1px solid #ffcccc;">
765
+ <h3 style="color: #cc0000; margin-top: 0;">Please Try Again</h3>
766
+ <p style="margin: 10px 0;">Your score: {score:.1f}%</p>
767
+ <p style="margin: 10px 0;">You need 80% or higher to pass and receive a certificate.</p>
768
+ </div>"""
769
+ else:
770
+ feedback_html += f"""<div style="background-color: #e6ffe6; padding: 20px; margin: 20px 0; border-radius: 10px; border: 1px solid #ccffcc;">
771
+ <h3 style="color: #008000; margin-top: 0;">🎉 Congratulations!</h3>
772
+ <p style="margin: 10px 0;">You passed with a score of {score:.1f}%</p>
773
+ <p style="margin: 10px 0;">Click "View Certificate" to see your certificate.</p>
774
+ </div>"""
775
 
776
  return [
777
  feedback_html,
778
  gr.update(visible=True),
779
  score,
780
  result_msg,
781
+ gr.update(visible=False),
782
+ gr.Tabs(selected=2),
783
+ gr.update(visible=passed)
784
  ]
785
  # Event handlers
786