Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -525,7 +525,18 @@ class QuizApp:
|
|
| 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 |
"""
|
| 531 |
Generate quiz questions using the QuizGenerator
|
|
@@ -728,13 +739,19 @@ def create_quiz_interface():
|
|
| 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")
|
|
|
|
|
|
|
|
|
|
| 737 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 738 |
# Assessment Tab
|
| 739 |
with gr.Tab(id=2, label="📝 Step 2: Take Assessment"):
|
| 740 |
with gr.Column() as main_container:
|
|
@@ -819,7 +836,14 @@ def create_quiz_interface():
|
|
| 819 |
gr.update(visible=False)
|
| 820 |
]
|
| 821 |
|
| 822 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 823 |
if not success or not questions:
|
| 824 |
return [
|
| 825 |
"",
|
|
@@ -836,7 +860,7 @@ def create_quiz_interface():
|
|
| 836 |
|
| 837 |
question = questions[0]
|
| 838 |
question_md = f"""### Question 1
|
| 839 |
-
{question.question}"""
|
| 840 |
|
| 841 |
return [
|
| 842 |
question_md,
|
|
@@ -972,7 +996,7 @@ def create_quiz_interface():
|
|
| 972 |
|
| 973 |
# Event Handlers
|
| 974 |
generate_btn.click(
|
| 975 |
-
fn=on_generate_questions,
|
| 976 |
inputs=[text_input, num_questions],
|
| 977 |
outputs=[
|
| 978 |
question_display,
|
|
|
|
| 525 |
self.quiz_generator = QuizGenerator(api_key)
|
| 526 |
self.certificate_generator = CertificateGenerator()
|
| 527 |
self.current_questions: List[Question] = []
|
| 528 |
+
self.learning_content: Optional[str] = None # Store learning content
|
| 529 |
+
self.logo_path = "atgc_logo.png" # Fixed path to ATGC logo
|
| 530 |
|
| 531 |
+
def set_learning_content(self, text: str) -> None:
|
| 532 |
+
"""Set the learning content if not already set"""
|
| 533 |
+
if not self.learning_content:
|
| 534 |
+
self.learning_content = text.strip()
|
| 535 |
+
|
| 536 |
+
def clear_learning_content(self) -> None:
|
| 537 |
+
"""Clear the stored learning content"""
|
| 538 |
+
self.learning_content = None
|
| 539 |
+
|
| 540 |
def generate_questions(self, text: str, num_questions: int) -> Tuple[bool, List[Question]]:
|
| 541 |
"""
|
| 542 |
Generate quiz questions using the QuizGenerator
|
|
|
|
| 739 |
step=1,
|
| 740 |
label="Number of Questions"
|
| 741 |
)
|
| 742 |
+
clear_btn = gr.Button("Clear Learning Content", variant="secondary", size="sm")
|
| 743 |
with gr.Row():
|
|
|
|
| 744 |
participant_photo = gr.Image(label="Your Photo (Optional)", type="filepath")
|
| 745 |
|
| 746 |
generate_btn = gr.Button("Generate Assessment", variant="primary", size="lg")
|
| 747 |
+
def clear_content():
|
| 748 |
+
quiz_app.clear_learning_content()
|
| 749 |
+
return gr.update(value="")
|
| 750 |
|
| 751 |
+
clear_btn.click(
|
| 752 |
+
fn=clear_content,
|
| 753 |
+
outputs=[text_input]
|
| 754 |
+
)
|
| 755 |
# Assessment Tab
|
| 756 |
with gr.Tab(id=2, label="📝 Step 2: Take Assessment"):
|
| 757 |
with gr.Column() as main_container:
|
|
|
|
| 836 |
gr.update(visible=False)
|
| 837 |
]
|
| 838 |
|
| 839 |
+
# Store content if not already stored
|
| 840 |
+
if not quiz_app.learning_content:
|
| 841 |
+
quiz_app.learning_content = text.strip()
|
| 842 |
+
|
| 843 |
+
# Use stored content instead of new text if available
|
| 844 |
+
content_to_use = quiz_app.learning_content or text
|
| 845 |
+
|
| 846 |
+
success, questions = quiz_app.generate_questions(content_to_use, num_questions)
|
| 847 |
if not success or not questions:
|
| 848 |
return [
|
| 849 |
"",
|
|
|
|
| 860 |
|
| 861 |
question = questions[0]
|
| 862 |
question_md = f"""### Question 1
|
| 863 |
+
{question.question}"""
|
| 864 |
|
| 865 |
return [
|
| 866 |
question_md,
|
|
|
|
| 996 |
|
| 997 |
# Event Handlers
|
| 998 |
generate_btn.click(
|
| 999 |
+
fn=on_generate_questions, # Using the same function name
|
| 1000 |
inputs=[text_input, num_questions],
|
| 1001 |
outputs=[
|
| 1002 |
question_display,
|