Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -525,7 +525,15 @@ class QuizApp:
|
|
525 |
self.quiz_generator = QuizGenerator(api_key)
|
526 |
self.certificate_generator = CertificateGenerator()
|
527 |
self.current_questions: List[Question] = []
|
528 |
-
self.logo_path = "atgc_logo.png"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
529 |
|
530 |
# Add fixed content here
|
531 |
self.fixed_content = """ATGC Transport and General Contracting LLC's Human Resources Policy and Procedures Manual serves as the definitive guide for personnel management within the organization. This comprehensive document defines policies and clarifies responsibilities to ensure consistent application of HR practices across all levels of the company. The manual applies to both permanent and temporary employees and has received approval from the Managing Director and Board of Directors. As a confidential document, unauthorized disclosure is strictly prohibited. The manual undergoes regular revisions to accommodate changes in company needs and UAE labor law, maintaining its relevance and flexibility.
|
@@ -568,6 +576,9 @@ Training and development initiatives require department head initiation, HR revi
|
|
568 |
Implementation and Compliance
|
569 |
The manual emphasizes the importance of proper implementation and compliance with all policies. Regular reviews and updates ensure continued relevance and effectiveness of policies. The HR Department maintains responsibility for policy interpretation and implementation, with ultimate authority resting with the Managing Director and Board of Directors."""
|
570 |
|
|
|
|
|
|
|
571 |
|
572 |
def generate_questions(self, text: str, num_questions: int) -> Tuple[bool, List[Question]]:
|
573 |
"""
|
@@ -765,14 +776,11 @@ def create_quiz_interface():
|
|
765 |
lines=10
|
766 |
)
|
767 |
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
step=1,
|
774 |
-
label="Number of Questions"
|
775 |
-
)
|
776 |
|
777 |
# Add clear button
|
778 |
clear_btn = gr.Button("Clear Learning Content", variant="secondary", size="sm")
|
@@ -833,14 +841,17 @@ def create_quiz_interface():
|
|
833 |
)
|
834 |
|
835 |
# Certification Tab (Hidden by default)
|
|
|
836 |
with gr.Tab(id=3, label="🎓 Step 3: Get Certified", visible=False) as cert_tab:
|
837 |
score_display = gr.Number(label="Your Score", visible=False)
|
838 |
course_name = gr.Textbox(
|
839 |
label="Certification Title",
|
840 |
-
value="Professional Assessment Certification",
|
841 |
-
interactive=False
|
842 |
)
|
843 |
-
certificate_display = gr.Image(label="Your Certificate")
|
|
|
|
|
844 |
def clear_content():
|
845 |
quiz_app.clear_learning_content()
|
846 |
return gr.update(value="")
|
@@ -853,12 +864,18 @@ def create_quiz_interface():
|
|
853 |
def show_certificate_tab():
|
854 |
return [
|
855 |
gr.update(visible=True), # Make cert_tab visible
|
|
|
|
|
|
|
856 |
gr.update(selected=3) # Switch to cert_tab
|
857 |
]
|
858 |
|
859 |
|
860 |
# Helper Functions
|
861 |
-
def on_generate_questions(text,
|
|
|
|
|
|
|
862 |
success, questions = quiz_app.generate_questions(quiz_app.fixed_content, num_questions)
|
863 |
if not success or not questions:
|
864 |
return [
|
@@ -868,7 +885,7 @@ def create_quiz_interface():
|
|
868 |
"",
|
869 |
[],
|
870 |
0,
|
871 |
-
[None] *
|
872 |
gr.update(selected=1),
|
873 |
gr.update(visible=False),
|
874 |
gr.update(visible=False)
|
@@ -895,7 +912,6 @@ def create_quiz_interface():
|
|
895 |
gr.update(visible=False)
|
896 |
]
|
897 |
|
898 |
-
|
899 |
def navigate(direction, current_idx, questions, answers, current_answer):
|
900 |
if not questions:
|
901 |
return [0, answers, "", gr.update(choices=[], visible=False), "", gr.update(visible=False)]
|
@@ -1013,7 +1029,7 @@ def create_quiz_interface():
|
|
1013 |
# Event Handlers
|
1014 |
generate_btn.click(
|
1015 |
fn=on_generate_questions,
|
1016 |
-
inputs=[text_input,
|
1017 |
outputs=[
|
1018 |
question_display,
|
1019 |
question_box,
|
@@ -1057,7 +1073,7 @@ def create_quiz_interface():
|
|
1057 |
|
1058 |
reset_btn.click(
|
1059 |
fn=on_generate_questions,
|
1060 |
-
inputs=[text_input,
|
1061 |
outputs=[
|
1062 |
question_display,
|
1063 |
question_box,
|
@@ -1071,10 +1087,10 @@ def create_quiz_interface():
|
|
1071 |
view_cert_btn
|
1072 |
]
|
1073 |
)
|
1074 |
-
|
1075 |
view_cert_btn.click(
|
1076 |
fn=show_certificate_tab,
|
1077 |
-
outputs=[cert_tab, tabs]
|
1078 |
)
|
1079 |
|
1080 |
current_options.change(
|
@@ -1084,8 +1100,12 @@ def create_quiz_interface():
|
|
1084 |
)
|
1085 |
|
1086 |
score_display.change(
|
1087 |
-
fn=lambda s, n, c, p: quiz_app.certificate_generator.generate(
|
1088 |
-
|
|
|
|
|
|
|
|
|
1089 |
outputs=certificate_display
|
1090 |
)
|
1091 |
|
|
|
525 |
self.quiz_generator = QuizGenerator(api_key)
|
526 |
self.certificate_generator = CertificateGenerator()
|
527 |
self.current_questions: List[Question] = []
|
528 |
+
self.logo_path = "atgc_logo.png"
|
529 |
+
self.selected_level = "Basic" # Default level
|
530 |
+
|
531 |
+
# Map difficulty levels to number of questions
|
532 |
+
self.difficulty_levels = {
|
533 |
+
"Basic": 5,
|
534 |
+
"Intermediate": 10,
|
535 |
+
"Advanced": 20
|
536 |
+
}
|
537 |
|
538 |
# Add fixed content here
|
539 |
self.fixed_content = """ATGC Transport and General Contracting LLC's Human Resources Policy and Procedures Manual serves as the definitive guide for personnel management within the organization. This comprehensive document defines policies and clarifies responsibilities to ensure consistent application of HR practices across all levels of the company. The manual applies to both permanent and temporary employees and has received approval from the Managing Director and Board of Directors. As a confidential document, unauthorized disclosure is strictly prohibited. The manual undergoes regular revisions to accommodate changes in company needs and UAE labor law, maintaining its relevance and flexibility.
|
|
|
576 |
Implementation and Compliance
|
577 |
The manual emphasizes the importance of proper implementation and compliance with all policies. Regular reviews and updates ensure continued relevance and effectiveness of policies. The HR Department maintains responsibility for policy interpretation and implementation, with ultimate authority resting with the Managing Director and Board of Directors."""
|
578 |
|
579 |
+
def get_certificate_title(self, base_title: str) -> str:
|
580 |
+
"""Get certificate title with difficulty level"""
|
581 |
+
return f"{base_title} - {self.selected_level} Level"
|
582 |
|
583 |
def generate_questions(self, text: str, num_questions: int) -> Tuple[bool, List[Question]]:
|
584 |
"""
|
|
|
776 |
lines=10
|
777 |
)
|
778 |
|
779 |
+
difficulty_level = gr.Radio(
|
780 |
+
choices=["Basic", "Intermediate", "Advanced"],
|
781 |
+
value="Basic",
|
782 |
+
label="Select Difficulty Level",
|
783 |
+
info="Basic: 5 questions | Intermediate: 10 questions | Advanced: 20 questions"
|
|
|
|
|
|
|
784 |
|
785 |
# Add clear button
|
786 |
clear_btn = gr.Button("Clear Learning Content", variant="secondary", size="sm")
|
|
|
841 |
)
|
842 |
|
843 |
# Certification Tab (Hidden by default)
|
844 |
+
|
845 |
with gr.Tab(id=3, label="🎓 Step 3: Get Certified", visible=False) as cert_tab:
|
846 |
score_display = gr.Number(label="Your Score", visible=False)
|
847 |
course_name = gr.Textbox(
|
848 |
label="Certification Title",
|
849 |
+
value=lambda: f"Professional Assessment Certification - {quiz_app.selected_level} Level", # Dynamic title with level
|
850 |
+
interactive=False
|
851 |
)
|
852 |
+
certificate_display = gr.Image(label="Your Certificate")
|
853 |
+
|
854 |
+
|
855 |
def clear_content():
|
856 |
quiz_app.clear_learning_content()
|
857 |
return gr.update(value="")
|
|
|
864 |
def show_certificate_tab():
|
865 |
return [
|
866 |
gr.update(visible=True), # Make cert_tab visible
|
867 |
+
gr.update(
|
868 |
+
value=f"Professional Assessment Certification - {quiz_app.selected_level} Level" # Update title with level
|
869 |
+
),
|
870 |
gr.update(selected=3) # Switch to cert_tab
|
871 |
]
|
872 |
|
873 |
|
874 |
# Helper Functions
|
875 |
+
def on_generate_questions(text, level):
|
876 |
+
quiz_app.selected_level = level # Store selected level
|
877 |
+
num_questions = quiz_app.difficulty_levels[level] # Get number of questions for level
|
878 |
+
|
879 |
success, questions = quiz_app.generate_questions(quiz_app.fixed_content, num_questions)
|
880 |
if not success or not questions:
|
881 |
return [
|
|
|
885 |
"",
|
886 |
[],
|
887 |
0,
|
888 |
+
[None] * num_questions, # Updated to use dynamic size
|
889 |
gr.update(selected=1),
|
890 |
gr.update(visible=False),
|
891 |
gr.update(visible=False)
|
|
|
912 |
gr.update(visible=False)
|
913 |
]
|
914 |
|
|
|
915 |
def navigate(direction, current_idx, questions, answers, current_answer):
|
916 |
if not questions:
|
917 |
return [0, answers, "", gr.update(choices=[], visible=False), "", gr.update(visible=False)]
|
|
|
1029 |
# Event Handlers
|
1030 |
generate_btn.click(
|
1031 |
fn=on_generate_questions,
|
1032 |
+
inputs=[text_input, difficulty_level], # Replace num_questions with difficulty_level
|
1033 |
outputs=[
|
1034 |
question_display,
|
1035 |
question_box,
|
|
|
1073 |
|
1074 |
reset_btn.click(
|
1075 |
fn=on_generate_questions,
|
1076 |
+
inputs=[text_input, difficulty_level], # Replace num_questions with difficulty_level
|
1077 |
outputs=[
|
1078 |
question_display,
|
1079 |
question_box,
|
|
|
1087 |
view_cert_btn
|
1088 |
]
|
1089 |
)
|
1090 |
+
|
1091 |
view_cert_btn.click(
|
1092 |
fn=show_certificate_tab,
|
1093 |
+
outputs=[cert_tab, course_name, tabs] # Add course_name to outputs
|
1094 |
)
|
1095 |
|
1096 |
current_options.change(
|
|
|
1100 |
)
|
1101 |
|
1102 |
score_display.change(
|
1103 |
+
fn=lambda s, n, c, p: quiz_app.certificate_generator.generate(
|
1104 |
+
s, n,
|
1105 |
+
quiz_app.get_certificate_title(c), # Add difficulty level to title
|
1106 |
+
quiz_app.logo_path, p
|
1107 |
+
) or gr.update(value=None),
|
1108 |
+
inputs=[score_display, name, course_name, participant_photo],
|
1109 |
outputs=certificate_display
|
1110 |
)
|
1111 |
|