capradeepgujaran commited on
Commit
f31fada
1 Parent(s): dc58ff0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -134
app.py CHANGED
@@ -45,7 +45,7 @@ class QuizGenerator:
45
  }
46
  ],
47
  model="gemma2-9b-it",
48
- temperature=0,
49
  max_tokens=6000
50
  )
51
 
@@ -525,73 +525,6 @@ 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
- 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.
540
- The Human Resources Department supports ATGC by providing strategic services through this manual, which aims to manage all aspects of staff relations in compliance with UAE regulations. It defines HR policies and procedures, outlines employee financial and administrative rights, facilitates teamwork and innovation, ensures proper planning and execution of HR processes, provides guidelines for recruitment and manpower planning, develops employee competencies, and creates a healthy work environment to enhance loyalty and team spirit.
541
- Manpower Planning and Budgeting
542
-
543
- ATGC implements strategic manpower planning to align workforce capacity with organizational goals and operational needs. This process begins with an annual workforce planning initiative led by the HR Director, who communicates the planning agenda and requirements to all department heads. Department heads then assess their current and future staffing needs based on project demands, operational goals, and strategic initiatives, completing detailed workforce planning forms that outline current staffing levels, vacancies, anticipated attrition, and skill gaps.
544
- The HR Director consolidates data from all departments to create a comprehensive organizational workforce plan, analyzing historical data and industry trends to forecast future requirements. This consolidated plan undergoes executive review and requires final approval from the Managing Director. The process includes detailed financial planning for workforce expenses, including salaries, benefits, training, and development costs.
545
- Recruitment and Onboarding
546
-
547
- The recruitment process at ATGC emphasizes finding qualified candidates who align with company values and objectives. The company utilizes both internal and external recruitment sources, with preference given to internal candidates when possible. Age criteria are clearly defined: 20-59 years for office staff and 20-55 years for site staff. The recruitment of relatives is generally restricted, though exceptions may be made in special cases with appropriate approval.
548
- The selection process includes comprehensive interviews, written and practical tests where applicable, and mandatory reference checks. All candidates must undergo medical examination prior to employment. Employment contracts are prepared in both Arabic and English, clearly outlining terms and conditions of employment. The onboarding process includes pre-arrival communication, comprehensive HR and departmental induction, system access setup, and initial training. New employees undergo a probation period of up to six months, during which their performance is closely monitored and evaluated.
549
- Employee Transfers, Secondments, and Acting Appointments
550
-
551
- ATGC maintains clear procedures for internal mobility through transfers, secondments, and acting appointments. Transfers require approval from both current and receiving managers, ensuring that operational needs are met while supporting employee development. Secondments are available for positions at equal or higher grades and include a 20% salary bonus when additional responsibilities are involved. Acting appointments allow employees to temporarily perform higher-level duties, providing development opportunities and ensuring operational continuity.
552
- Payroll, Working Hours, and Holidays
553
-
554
- The company operates on a six-day workweek, Monday through Saturday, with standard hours from 8:00 AM to 5:00 PM. A 15-minute grace period is allowed for morning arrival. Working hours are reduced during Ramadan in accordance with UAE customs and regulations. The salary structure differs based on employment date: newer employees receive 40% basic salary and 60% allowances, while those employed before February 2023 receive 60% basic salary and 40% allowances.
555
- Salaries are paid monthly through bank transfer, with overtime compensation provided according to UAE Labor Law requirements. Regular salary increments are based on performance evaluations and company guidelines. The payroll system carefully tracks attendance, overtime, and leave to ensure accurate compensation calculations.
556
- Allowances and Benefits
557
-
558
- ATGC provides a comprehensive benefits package including medical insurance for employees and their families, workmen's compensation insurance, and death and disability coverage. Housing benefits are provided either through company accommodation or housing allowances, depending on employee grade and position. Eligible employees may receive company cars for business use, and all employees are entitled to business travel allowances when required to work away from their primary location.
559
- Additional benefits include annual airline ticket allowances and uniform provision for specific positions. These benefits are designed to enhance employee welfare and maintain competitive compensation packages within the industry.
560
- Employee Code of Conduct and Office Etiquette
561
-
562
- The company maintains high standards for professional behavior through its Code of Conduct, which requires compliance with local and international laws, maintenance of confidentiality, prevention of conflicts of interest, and protection of company property. Employees must demonstrate professional behavior and ethics in all work-related activities.
563
- Office etiquette guidelines cover professional dress code requirements, workplace cleanliness standards, communication protocols, and appropriate technology usage. These standards help maintain a professional work environment and promote positive workplace relationships.
564
- Performance Management and Review
565
-
566
- ATGC implements a comprehensive performance management system centered on annual evaluations for permanent employees. Performance assessment is based on both Key Performance Indicators (KPIs) and behavioral factors, using a rating scale from A (Excellent) to D (Poor). The system includes provisions for performance improvement programs when necessary and helps identify training needs for employee development.
567
- Regular feedback and monitoring ensure that performance issues are addressed promptly and employees receive the support needed to meet expectations. The performance review process also influences decisions about promotions, salary increments, and other career development opportunities.
568
- Leave Entitlements and Management
569
-
570
- The company provides various types of leave to support work-life balance and employee wellbeing. Annual leave entitlement is 30 calendar days after one year of service, while sick leave allows up to 90 days per year with varying pay levels. Maternity leave provides 60 days for female employees, and paternity leave offers 5 days for new fathers.
571
- Additional leave types include bereavement leave (5 days), pilgrimage leave (5 days paid plus 25 days unpaid), educational leave (up to 10 days paid), and unpaid leave (maximum 30 days). All leave requests require proper documentation and approval through appropriate channels.
572
- Employee Relations and Documentation
573
-
574
- ATGC maintains robust systems for employee documentation, including employment verification, salary certificates, experience letters, and various other official documents. The company also implements a structured grievance procedure that begins with informal resolution attempts, followed by formal written complaints to HR if necessary. All grievances receive investigation and response within two days, with possible escalation to the CEO for unresolved issues.
575
- The company ensures protection against retaliation for employees who raise legitimate concerns and maintains confidentiality throughout the grievance process.
576
- Recognition and Awards
577
-
578
- Employee recognition is an important aspect of ATGC's HR policy, with various awards programs recognizing different types of achievement. These include performance awards for exceptional work, service loyalty awards for long-term commitment, team awards for group achievements, and special achievement awards for notable contributions to the company.
579
- Recognition takes multiple forms, including certificates, trophies, monetary bonuses, and additional paid time off. The awards system helps motivate employees and recognize outstanding contributions to the organization's success.
580
- Employment Separation
581
-
582
- The company maintains clear procedures for employment separation, whether through resignation, termination, or retirement. Resignations require 30 days' notice and include proper handover of duties, exit interviews, and return of company property. Termination procedures comply with UAE labor law and may occur with notice as per contract or immediately in cases of gross misconduct.
583
- End of service benefits are calculated based on length of service, with 21 days of basic salary per year for the first five years and 30 days per year thereafter. Payments are processed within 14 days of termination, subject to deduction of any outstanding dues.
584
- Authority Delegation
585
-
586
- ATGC maintains a clear delegation of authority structure for various HR functions. Recruitment authority flows from department heads through HR to final CEO approval. Salary administration requires multiple levels of review, with final approval from the Managing Director for significant changes. Leave administration follows a hierarchical approval process based on employee level and leave type.
587
- Training and development initiatives require department head initiation, HR review, and CEO approval, ensuring alignment with company objectives and budget constraints.
588
- Implementation and Compliance
589
-
590
- 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."""
591
-
592
- def get_certificate_title(self, base_title: str) -> str:
593
- """Get certificate title with difficulty level"""
594
- return f"{base_title} - {self.selected_level} Level"
595
 
596
  def generate_questions(self, text: str, num_questions: int) -> Tuple[bool, List[Question]]:
597
  """
@@ -771,23 +704,9 @@ def create_quiz_interface():
771
 
772
  # Header
773
  gr.Markdown("""
774
- <div style="text-align: center;">
775
- <h1>🎓 ATGC HR Procedure Certification </h1>
776
- <h3>Transform Your Knowledge into Recognized Achievements</h3></p>
777
- </div>
778
-
779
- <div style="margin: 20px 0; padding: 20px; background-color: #f8f9fa; border-radius: 10px;">
780
- <h4>Assessment Overview:</h4>
781
- <ul style="list-style-type: none; padding-left: 0;">
782
- <li>📌 <strong>Basic Level:</strong> 5 questions - Perfect for beginners</li>
783
- <li>📚 <strong>Intermediate Level:</strong> 10 questions - For those with HR experience</li>
784
- <li>🎯 <strong>Advanced Level:</strong> 20 questions - Comprehensive assessment</li>
785
- <li>⏱️ <strong>Passing Score:</strong> 80% or higher</li>
786
- <li>🏆 <strong>Certificate:</strong> Awarded upon successful completion</li>
787
- </ul>
788
- <p style="margin-top: 15px;"><i>This assessment evaluates your understanding of ATGC's HR policies, procedures, and best practices.</i></p>
789
- </div>
790
- """, show_label=False)
791
 
792
  with gr.Tabs() as tabs:
793
  # Profile Setup Tab
@@ -798,19 +717,20 @@ def create_quiz_interface():
798
 
799
  text_input = gr.Textbox(
800
  label="Learning Content",
801
- value=quiz_app.fixed_content, # Set the fixed content
802
- interactive=False, # Make it non-editable
803
  lines=10
804
  )
805
 
806
- difficulty_level = gr.Radio(
807
- choices=["Basic", "Intermediate", "Advanced"],
808
- value="Basic",
809
- label="Select Difficulty Level",
810
- info="Basic: 5 questions | Intermediate: 10 questions | Advanced: 20 questions")
811
-
 
812
 
813
  with gr.Row():
 
814
  participant_photo = gr.Image(label="Your Photo (Optional)", type="filepath")
815
 
816
  generate_btn = gr.Button("Generate Assessment", variant="primary", size="lg")
@@ -866,33 +786,40 @@ def create_quiz_interface():
866
  )
867
 
868
  # Certification Tab (Hidden by default)
869
-
870
  with gr.Tab(id=3, label="🎓 Step 3: Get Certified", visible=False) as cert_tab:
871
  score_display = gr.Number(label="Your Score", visible=False)
872
  course_name = gr.Textbox(
873
  label="Certification Title",
874
- value=lambda: f"HR Procedure Assessment Certification", # Dynamic title with level
875
- interactive=False
876
  )
877
- certificate_display = gr.Image(label="Your Certificate")
878
-
879
 
 
880
  def show_certificate_tab():
881
  return [
882
  gr.update(visible=True), # Make cert_tab visible
883
- gr.update(
884
- value=f"HR Procedure Assessment Certification" # Update title with level
885
- ),
886
  gr.update(selected=3) # Switch to cert_tab
887
  ]
888
 
889
 
890
  # Helper Functions
891
- def on_generate_questions(text, level):
892
- quiz_app.selected_level = level # Store selected level
893
- num_questions = quiz_app.difficulty_levels[level] # Get number of questions for level
 
 
 
 
 
 
 
 
 
 
 
894
 
895
- success, questions = quiz_app.generate_questions(quiz_app.fixed_content, num_questions)
896
  if not success or not questions:
897
  return [
898
  "",
@@ -901,14 +828,15 @@ def create_quiz_interface():
901
  "",
902
  [],
903
  0,
904
- [None] * num_questions, # Updated to use dynamic size
905
  gr.update(selected=1),
906
  gr.update(visible=False),
907
  gr.update(visible=False)
908
  ]
909
 
910
  question = questions[0]
911
- question_md = f"""### Question 1\n{question.question}"""
 
912
 
913
  return [
914
  question_md,
@@ -983,23 +911,15 @@ def create_quiz_interface():
983
  final_answers[current_idx] = current_answer
984
 
985
  if not all(a is not None for a in final_answers[:len(questions)]):
986
- # Create list of unanswered question numbers
987
- unanswered = [i+1 for i, a in enumerate(final_answers[:len(questions)]) if a is None]
988
- warning_content = f"""
989
- <div style="background-color: #fff3cd; padding: 20px; border-radius: 10px; border-left: 5px solid #ffa000;">
990
- <h3 style="color: #ff6b6b; margin: 0;">⚠️ Please Complete All Questions</h3>
991
- <p style="margin: 10px 0;">Unanswered Questions: {', '.join(map(str, unanswered))}</p>
992
- </div>
993
- """
994
  return [
995
- warning_content, # feedback_box
996
- gr.update(visible=True), # results_group
997
- 0, # score
998
- "", # result_message
999
- gr.update(visible=True), # question_box
1000
- gr.update(visible=True), # reset_btn
1001
- gr.update(visible=False), # view_cert_btn
1002
- gr.update(selected=2) # tabs
1003
  ]
1004
 
1005
  score, passed, feedback = quiz_app.calculate_score(final_answers[:len(questions)])
@@ -1049,10 +969,11 @@ def create_quiz_interface():
1049
  gr.update(visible=passed), # view_cert_btn
1050
  gr.update(selected=2) # tabs
1051
  ]
 
1052
  # Event Handlers
1053
  generate_btn.click(
1054
  fn=on_generate_questions,
1055
- inputs=[text_input, difficulty_level], # Replace num_questions with difficulty_level
1056
  outputs=[
1057
  question_display,
1058
  question_box,
@@ -1096,7 +1017,7 @@ def create_quiz_interface():
1096
 
1097
  reset_btn.click(
1098
  fn=on_generate_questions,
1099
- inputs=[text_input, difficulty_level], # Replace num_questions with difficulty_level
1100
  outputs=[
1101
  question_display,
1102
  question_box,
@@ -1110,10 +1031,10 @@ def create_quiz_interface():
1110
  view_cert_btn
1111
  ]
1112
  )
1113
-
1114
  view_cert_btn.click(
1115
  fn=show_certificate_tab,
1116
- outputs=[cert_tab, course_name, tabs] # Add course_name to outputs
1117
  )
1118
 
1119
  current_options.change(
@@ -1123,15 +1044,11 @@ def create_quiz_interface():
1123
  )
1124
 
1125
  score_display.change(
1126
- fn=lambda s, n, c, p: quiz_app.certificate_generator.generate(
1127
- s, n,
1128
- quiz_app.get_certificate_title(c), # Add difficulty level to title
1129
- quiz_app.logo_path, p
1130
- ) or gr.update(value=None),
1131
- inputs=[score_display, name, course_name, participant_photo],
1132
  outputs=certificate_display
1133
  )
1134
-
1135
  return demo
1136
 
1137
  if __name__ == "__main__":
 
45
  }
46
  ],
47
  model="gemma2-9b-it",
48
+ temperature=0.1,
49
  max_tokens=6000
50
  )
51
 
 
525
  self.quiz_generator = QuizGenerator(api_key)
526
  self.certificate_generator = CertificateGenerator()
527
  self.current_questions: List[Question] = []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
528
 
529
  def generate_questions(self, text: str, num_questions: int) -> Tuple[bool, List[Question]]:
530
  """
 
704
 
705
  # Header
706
  gr.Markdown("""
707
+ # 🎓 CertifyMe AI
708
+ ### Transform Your Knowledge into Recognized Achievements
709
+ """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
710
 
711
  with gr.Tabs() as tabs:
712
  # Profile Setup Tab
 
717
 
718
  text_input = gr.Textbox(
719
  label="Learning Content",
720
+ placeholder="Enter the text content you want to be assessed on",
 
721
  lines=10
722
  )
723
 
724
+ num_questions = gr.Slider(
725
+ minimum=1,
726
+ maximum=20,
727
+ value=10,
728
+ step=1,
729
+ label="Number of Questions"
730
+ )
731
 
732
  with gr.Row():
733
+ company_logo = gr.Image(label="Company Logo (Optional)", type="filepath")
734
  participant_photo = gr.Image(label="Your Photo (Optional)", type="filepath")
735
 
736
  generate_btn = gr.Button("Generate Assessment", variant="primary", size="lg")
 
786
  )
787
 
788
  # Certification Tab (Hidden by default)
 
789
  with gr.Tab(id=3, label="🎓 Step 3: Get Certified", visible=False) as cert_tab:
790
  score_display = gr.Number(label="Your Score", visible=False)
791
  course_name = gr.Textbox(
792
  label="Certification Title",
793
+ value="Professional Assessment Certification",
794
+ interactive=False # Make it non-editable
795
  )
796
+ certificate_display = gr.Image(label="Your Certificate")
 
797
 
798
+ # Update view_cert_btn click handler to show certification tab
799
  def show_certificate_tab():
800
  return [
801
  gr.update(visible=True), # Make cert_tab visible
 
 
 
802
  gr.update(selected=3) # Switch to cert_tab
803
  ]
804
 
805
 
806
  # Helper Functions
807
+ def on_generate_questions(text, num_questions):
808
+ if not text.strip():
809
+ return [
810
+ "",
811
+ gr.update(visible=False),
812
+ gr.update(choices=[], visible=False),
813
+ "",
814
+ [],
815
+ 0,
816
+ [None] * 5,
817
+ gr.update(selected=1),
818
+ gr.update(visible=False),
819
+ gr.update(visible=False)
820
+ ]
821
 
822
+ success, questions = quiz_app.generate_questions(text, num_questions)
823
  if not success or not questions:
824
  return [
825
  "",
 
828
  "",
829
  [],
830
  0,
831
+ [None] * 5,
832
  gr.update(selected=1),
833
  gr.update(visible=False),
834
  gr.update(visible=False)
835
  ]
836
 
837
  question = questions[0]
838
+ question_md = f"""### Question 1
839
+ {question.question}"""
840
 
841
  return [
842
  question_md,
 
911
  final_answers[current_idx] = current_answer
912
 
913
  if not all(a is not None for a in final_answers[:len(questions)]):
 
 
 
 
 
 
 
 
914
  return [
915
+ "⚠️ Please answer all questions before submitting.",
916
+ gr.update(visible=True),
917
+ 0,
918
+ "",
919
+ gr.update(visible=True),
920
+ gr.update(visible=True),
921
+ gr.update(visible=False),
922
+ gr.update(visible=False)
923
  ]
924
 
925
  score, passed, feedback = quiz_app.calculate_score(final_answers[:len(questions)])
 
969
  gr.update(visible=passed), # view_cert_btn
970
  gr.update(selected=2) # tabs
971
  ]
972
+
973
  # Event Handlers
974
  generate_btn.click(
975
  fn=on_generate_questions,
976
+ inputs=[text_input, num_questions],
977
  outputs=[
978
  question_display,
979
  question_box,
 
1017
 
1018
  reset_btn.click(
1019
  fn=on_generate_questions,
1020
+ inputs=[text_input, num_questions],
1021
  outputs=[
1022
  question_display,
1023
  question_box,
 
1031
  view_cert_btn
1032
  ]
1033
  )
1034
+
1035
  view_cert_btn.click(
1036
  fn=show_certificate_tab,
1037
+ outputs=[cert_tab, tabs]
1038
  )
1039
 
1040
  current_options.change(
 
1044
  )
1045
 
1046
  score_display.change(
1047
+ fn=lambda s, n, c, l, p: quiz_app.certificate_generator.generate(s, n, c, l, p) or gr.update(value=None),
1048
+ inputs=[score_display, name, course_name, company_logo, participant_photo],
 
 
 
 
1049
  outputs=certificate_display
1050
  )
1051
+
1052
  return demo
1053
 
1054
  if __name__ == "__main__":