namberino commited on
Commit
2f5ff1a
·
1 Parent(s): 2f8b4ba

Add debugging msgs

Browse files
Files changed (1) hide show
  1. fastapi_app.py +14 -2
fastapi_app.py CHANGED
@@ -17,11 +17,11 @@ if not os.path.exists(tmp_folder):
17
  class GenerateRequest(BaseModel):
18
  topics: List[str] = Field(..., description="List of topics for MCQ generation")
19
  question_per_topic: int = Field(1, ge=1, le=10, description="Number of questions per topic")
20
- difficulty: str = Field(
21
  DifficultyLevel.MEDIUM,
22
  description="Difficulty level for generated questions"
23
  )
24
- qtype: str = Field(
25
  QuestionType.DEFINITION,
26
  description="Type of question to generate"
27
  )
@@ -68,10 +68,14 @@ async def mcq_gen(
68
  ):
69
  if not generator:
70
  raise HTTPException(status_code=500, detail="Generator not initialized")
 
 
71
 
72
  topic_list = [t.strip() for t in topics.split(',') if t.strip()]
73
  if not topic_list:
74
  raise HTTPException(status_code=400, detail="At least one topic must be provided")
 
 
75
 
76
  # Validate and convert enum values
77
  try:
@@ -80,12 +84,16 @@ async def mcq_gen(
80
  valid_difficulties = [d.value for d in DifficultyLevel]
81
  raise HTTPException(status_code=400, detail=f"Invalid difficulty. Must be one of: {valid_difficulties}")
82
 
 
 
83
  try:
84
  qtype_enum = QuestionType(qtype.lower())
85
  except ValueError:
86
  valid_types = [q.value for q in QuestionType]
87
  raise HTTPException(status_code=400, detail=f"Invalid question type. Must be one of: {valid_types}")
88
 
 
 
89
  # Save uploaded PDF to temporary folder
90
  filename = file.filename if file.filename else "uploaded_file"
91
  file_path = os.path.join(tmp_folder, filename)
@@ -93,6 +101,8 @@ async def mcq_gen(
93
  shutil.copyfileobj(file.file, buffer)
94
  file.file.close()
95
 
 
 
96
  try:
97
  # Load and index the uploaded document
98
  docs, _ = generator.load_documents(tmp_folder)
@@ -100,6 +110,8 @@ async def mcq_gen(
100
  except Exception as e:
101
  raise HTTPException(status_code=500, detail=f"Document processing error: {e}")
102
 
 
 
103
  start_time = time.time()
104
  try:
105
  mcqs = generator.generate_batch(
 
17
  class GenerateRequest(BaseModel):
18
  topics: List[str] = Field(..., description="List of topics for MCQ generation")
19
  question_per_topic: int = Field(1, ge=1, le=10, description="Number of questions per topic")
20
+ difficulty: Optional[DifficultyLevel] = Field(
21
  DifficultyLevel.MEDIUM,
22
  description="Difficulty level for generated questions"
23
  )
24
+ qtype: Optional[QuestionType] = Field(
25
  QuestionType.DEFINITION,
26
  description="Type of question to generate"
27
  )
 
68
  ):
69
  if not generator:
70
  raise HTTPException(status_code=500, detail="Generator not initialized")
71
+
72
+ print("generator initialized")
73
 
74
  topic_list = [t.strip() for t in topics.split(',') if t.strip()]
75
  if not topic_list:
76
  raise HTTPException(status_code=400, detail="At least one topic must be provided")
77
+
78
+ print("topic validated")
79
 
80
  # Validate and convert enum values
81
  try:
 
84
  valid_difficulties = [d.value for d in DifficultyLevel]
85
  raise HTTPException(status_code=400, detail=f"Invalid difficulty. Must be one of: {valid_difficulties}")
86
 
87
+ print("difficulty validated")
88
+
89
  try:
90
  qtype_enum = QuestionType(qtype.lower())
91
  except ValueError:
92
  valid_types = [q.value for q in QuestionType]
93
  raise HTTPException(status_code=400, detail=f"Invalid question type. Must be one of: {valid_types}")
94
 
95
+ print("question type validated")
96
+
97
  # Save uploaded PDF to temporary folder
98
  filename = file.filename if file.filename else "uploaded_file"
99
  file_path = os.path.join(tmp_folder, filename)
 
101
  shutil.copyfileobj(file.file, buffer)
102
  file.file.close()
103
 
104
+ print(f"file read and written to {file_path}")
105
+
106
  try:
107
  # Load and index the uploaded document
108
  docs, _ = generator.load_documents(tmp_folder)
 
110
  except Exception as e:
111
  raise HTTPException(status_code=500, detail=f"Document processing error: {e}")
112
 
113
+ print("loaded and indexed the document")
114
+
115
  start_time = time.time()
116
  try:
117
  mcqs = generator.generate_batch(