Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,16 +31,15 @@ async def home():
|
|
| 31 |
|
| 32 |
@app.post("/generate_quiz")
|
| 33 |
async def generate_quiz(request: Request):
|
| 34 |
-
data = await request.json()
|
| 35 |
-
topic = data.get("topic", "").strip()
|
| 36 |
-
n_questions = int(data.get("n_questions", 3))
|
| 37 |
-
difficulty = data.get("difficulty", "medium")
|
| 38 |
-
|
| 39 |
-
if not topic:
|
| 40 |
-
return JSONResponse(status_code=400, content={"error": "Topic is required."})
|
| 41 |
-
|
| 42 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
questions = generator.generate_questions(topic, n_questions, difficulty)
|
| 44 |
return {"questions": [{"question": q["question"], "options": q["options"], "answer": q["answer"]} for q in questions]}
|
| 45 |
except Exception as e:
|
| 46 |
-
|
|
|
|
|
|
| 31 |
|
| 32 |
@app.post("/generate_quiz")
|
| 33 |
async def generate_quiz(request: Request):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
try:
|
| 35 |
+
data = await request.json()
|
| 36 |
+
topic = (data.get("topic") or "").strip()
|
| 37 |
+
n_questions = int(data.get("n_questions", 3))
|
| 38 |
+
difficulty = data.get("difficulty", "medium")
|
| 39 |
+
if not topic:
|
| 40 |
+
return JSONResponse(status_code=400, content={"error": "Topic is required."})
|
| 41 |
questions = generator.generate_questions(topic, n_questions, difficulty)
|
| 42 |
return {"questions": [{"question": q["question"], "options": q["options"], "answer": q["answer"]} for q in questions]}
|
| 43 |
except Exception as e:
|
| 44 |
+
tb = traceback.format_exc()
|
| 45 |
+
return JSONResponse(status_code=500, content={"error": str(e), "traceback": tb})
|