Spaces:
Sleeping
Sleeping
namberino
commited on
Commit
·
fee5e22
1
Parent(s):
bfd59d7
Update generator
Browse files
app.py
CHANGED
|
@@ -147,6 +147,7 @@ async def generate_saved_endpoint(
|
|
| 147 |
}
|
| 148 |
|
| 149 |
all_mcqs = {}
|
|
|
|
| 150 |
|
| 151 |
for difficulty, n_questions in difficulty_counts.items():
|
| 152 |
try:
|
|
@@ -161,14 +162,27 @@ async def generate_saved_endpoint(
|
|
| 161 |
enable_fiddler=enable_fiddler,
|
| 162 |
target_difficulty=difficulty,
|
| 163 |
)
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
if isinstance(
|
| 169 |
-
|
| 170 |
else:
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
except Exception as e:
|
| 174 |
raise HTTPException(status_code=500, detail=f"Generation from saved file failed: {e}")
|
|
|
|
| 147 |
}
|
| 148 |
|
| 149 |
all_mcqs = {}
|
| 150 |
+
counter = 1
|
| 151 |
|
| 152 |
for difficulty, n_questions in difficulty_counts.items():
|
| 153 |
try:
|
|
|
|
| 162 |
enable_fiddler=enable_fiddler,
|
| 163 |
target_difficulty=difficulty,
|
| 164 |
)
|
| 165 |
+
questions_list = []
|
| 166 |
+
if isinstance(mcqs, dict):
|
| 167 |
+
# if dict values are lists or single objects, collect them
|
| 168 |
+
for v in mcqs.values():
|
| 169 |
+
if isinstance(v, list):
|
| 170 |
+
questions_list.extend(v)
|
| 171 |
else:
|
| 172 |
+
questions_list.append(v)
|
| 173 |
+
elif isinstance(mcqs, list):
|
| 174 |
+
questions_list = mcqs
|
| 175 |
+
else:
|
| 176 |
+
# unexpected shape — skip or handle as needed
|
| 177 |
+
continue
|
| 178 |
+
|
| 179 |
+
# assign sequential ids (as strings). use `counter` for numeric keys if preferred.
|
| 180 |
+
for qobj in questions_list:
|
| 181 |
+
if isinstance(qobj, dict):
|
| 182 |
+
# optional: keep which difficulty the question came from
|
| 183 |
+
qobj["_difficulty"] = difficulty
|
| 184 |
+
all_mcqs[str(counter)] = qobj
|
| 185 |
+
counter += 1
|
| 186 |
|
| 187 |
except Exception as e:
|
| 188 |
raise HTTPException(status_code=500, detail=f"Generation from saved file failed: {e}")
|