Spaces:
Sleeping
Sleeping
Delete verify_generation.py
Browse files- verify_generation.py +0 -124
verify_generation.py
DELETED
|
@@ -1,124 +0,0 @@
|
|
| 1 |
-
import logging
|
| 2 |
-
from exam_question_system import ExamQuestionSystem
|
| 3 |
-
from option_generator import OptionGenerator
|
| 4 |
-
|
| 5 |
-
# Configure logging
|
| 6 |
-
logging.basicConfig(level=logging.INFO)
|
| 7 |
-
|
| 8 |
-
def verify_generation():
|
| 9 |
-
# Mock content
|
| 10 |
-
content = """
|
| 11 |
-
Data visualization is the graphical representation of information and data.
|
| 12 |
-
By using visual elements like charts, graphs, and maps, data visualization
|
| 13 |
-
tools provide an accessible way to see and understand trends, outliers, and
|
| 14 |
-
patterns in data. In the world of Big Data, data visualization tools and
|
| 15 |
-
technologies are essential to analyze massive amounts of information and
|
| 16 |
-
make data-driven decisions.
|
| 17 |
-
|
| 18 |
-
Design principles in data visualization include understanding the audience,
|
| 19 |
-
choosing the right chart type, and using color effectively. Good design
|
| 20 |
-
makes complex data more accessible, understandable, and usable.
|
| 21 |
-
|
| 22 |
-
Exploratory Data Analysis (EDA) is an approach to analyzing data sets to
|
| 23 |
-
summarize their main characteristics, often with visual methods. A statistical
|
| 24 |
-
model can be used or not, but primarily EDA is for seeing what the data can
|
| 25 |
-
tell us beyond the formal modeling or hypothesis testing task.
|
| 26 |
-
"""
|
| 27 |
-
|
| 28 |
-
print("Initializing ExamQuestionSystem...")
|
| 29 |
-
system = ExamQuestionSystem(use_transformers=False) # Use rule-based for speed in test
|
| 30 |
-
|
| 31 |
-
print("\nGenerating questions (Target: 2 MCQ, 1 Short, 1 Long)...")
|
| 32 |
-
# We simulate the logic in app.py
|
| 33 |
-
num_mcq = 2
|
| 34 |
-
num_short = 1
|
| 35 |
-
num_long = 1
|
| 36 |
-
total_needed = num_mcq + num_short + num_long
|
| 37 |
-
|
| 38 |
-
results = system.generate_exam_questions(
|
| 39 |
-
input_text=content,
|
| 40 |
-
max_questions=total_needed,
|
| 41 |
-
include_mcq=False,
|
| 42 |
-
syllabus_text=content
|
| 43 |
-
)
|
| 44 |
-
|
| 45 |
-
all_questions = results.get('questions', [])
|
| 46 |
-
print(f"\nTotal questions generated: {len(all_questions)}")
|
| 47 |
-
|
| 48 |
-
# Simulate app.py distribution logic
|
| 49 |
-
generated_questions = {
|
| 50 |
-
'mcq_questions': [],
|
| 51 |
-
'short_questions': [],
|
| 52 |
-
'long_questions': []
|
| 53 |
-
}
|
| 54 |
-
|
| 55 |
-
# Filter out questions that are too simple for Long answers
|
| 56 |
-
long_candidates = [q for q in all_questions if len(q.get('context', '').split()) > 10]
|
| 57 |
-
short_candidates = [q for q in all_questions if q not in long_candidates]
|
| 58 |
-
|
| 59 |
-
# If we don't have enough long candidates, take from short
|
| 60 |
-
if len(long_candidates) < num_long:
|
| 61 |
-
needed = num_long - len(long_candidates)
|
| 62 |
-
long_candidates.extend(short_candidates[:needed])
|
| 63 |
-
short_candidates = short_candidates[needed:]
|
| 64 |
-
|
| 65 |
-
# 3. Process Long Questions
|
| 66 |
-
for _ in range(num_long):
|
| 67 |
-
if long_candidates:
|
| 68 |
-
q = long_candidates.pop(0)
|
| 69 |
-
q['type'] = 'long_answer'
|
| 70 |
-
generated_questions['long_questions'].append(q)
|
| 71 |
-
if q in all_questions:
|
| 72 |
-
all_questions.remove(q)
|
| 73 |
-
|
| 74 |
-
# 2. Process Short Questions
|
| 75 |
-
for _ in range(num_short):
|
| 76 |
-
if short_candidates:
|
| 77 |
-
q = short_candidates.pop(0)
|
| 78 |
-
q['type'] = 'short_answer'
|
| 79 |
-
generated_questions['short_questions'].append(q)
|
| 80 |
-
if q in all_questions:
|
| 81 |
-
all_questions.remove(q)
|
| 82 |
-
elif all_questions:
|
| 83 |
-
q = all_questions.pop(0)
|
| 84 |
-
q['type'] = 'short_answer'
|
| 85 |
-
generated_questions['short_questions'].append(q)
|
| 86 |
-
|
| 87 |
-
# 1. Process MCQs
|
| 88 |
-
global_keywords = [k[1] for k in results.get('keywords', [])]
|
| 89 |
-
print(f"\nGlobal Keywords (Cleaned): {global_keywords}")
|
| 90 |
-
|
| 91 |
-
for _ in range(num_mcq):
|
| 92 |
-
if all_questions:
|
| 93 |
-
q = all_questions.pop(0)
|
| 94 |
-
try:
|
| 95 |
-
mcq_data = system.option_generator.create_mcq_options(
|
| 96 |
-
q['question'],
|
| 97 |
-
q['context'],
|
| 98 |
-
correct_answer=q.get('correct_answer'),
|
| 99 |
-
global_keywords=global_keywords
|
| 100 |
-
)
|
| 101 |
-
if mcq_data and 'options' in mcq_data:
|
| 102 |
-
q.update(mcq_data)
|
| 103 |
-
q['type'] = 'mcq'
|
| 104 |
-
generated_questions['mcq_questions'].append(q)
|
| 105 |
-
except Exception as e:
|
| 106 |
-
print(f"Error generating options: {e}")
|
| 107 |
-
|
| 108 |
-
# Print Results
|
| 109 |
-
print("\n--- Generation Results ---")
|
| 110 |
-
print(f"MCQs: {len(generated_questions['mcq_questions'])}")
|
| 111 |
-
for q in generated_questions['mcq_questions']:
|
| 112 |
-
print(f" Q: {q['question']}")
|
| 113 |
-
print(f" Options: {q.get('options')}")
|
| 114 |
-
|
| 115 |
-
print(f"\nShort Questions: {len(generated_questions['short_questions'])}")
|
| 116 |
-
for q in generated_questions['short_questions']:
|
| 117 |
-
print(f" Q: {q['question']}")
|
| 118 |
-
|
| 119 |
-
print(f"\nLong Questions: {len(generated_questions['long_questions'])}")
|
| 120 |
-
for q in generated_questions['long_questions']:
|
| 121 |
-
print(f" Q: {q['question']}")
|
| 122 |
-
|
| 123 |
-
if __name__ == "__main__":
|
| 124 |
-
verify_generation()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|