Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,31 @@
|
|
| 1 |
from fastapi import FastAPI, Request
|
| 2 |
-
from fastapi.responses import JSONResponse
|
| 3 |
from quiz_logic import generator
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
@app.post("/generate_quiz")
|
| 8 |
async def generate_quiz(request: Request):
|
| 9 |
data = await request.json()
|
|
@@ -24,4 +46,4 @@ async def generate_quiz(request: Request):
|
|
| 24 |
})
|
| 25 |
return {"questions": questions}
|
| 26 |
except Exception as e:
|
| 27 |
-
return JSONResponse(status_code=500, content={"error": str(e)})
|
|
|
|
| 1 |
from fastapi import FastAPI, Request
|
| 2 |
+
from fastapi.responses import JSONResponse, HTMLResponse
|
| 3 |
from quiz_logic import generator
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
|
| 7 |
+
@app.get("/", response_class=HTMLResponse)
|
| 8 |
+
async def home():
|
| 9 |
+
return """
|
| 10 |
+
<html>
|
| 11 |
+
<head><title>Smart Quiz API</title></head>
|
| 12 |
+
<body style="font-family: Arial; padding: 2em;">
|
| 13 |
+
<h1>🧠 Smart Quiz API</h1>
|
| 14 |
+
<p>This is the backend API for generating AI-powered quiz questions.</p>
|
| 15 |
+
<p>To experience the full quiz interface, please visit:</p>
|
| 16 |
+
<p>https://huggingface.co/spaces/NZLouislu/smart-quiz-ui</p>
|
| 17 |
+
<hr>
|
| 18 |
+
<h2>📡 API Usage</h2>
|
| 19 |
+
<p>Send a POST request to <code>/generate_quiz</code> with JSON body:</p>
|
| 20 |
+
<pre>{
|
| 21 |
+
"topic": "New Zealand",
|
| 22 |
+
"n_questions": 3,
|
| 23 |
+
"difficulty": "medium"
|
| 24 |
+
}</pre>
|
| 25 |
+
</body>
|
| 26 |
+
</html>
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
@app.post("/generate_quiz")
|
| 30 |
async def generate_quiz(request: Request):
|
| 31 |
data = await request.json()
|
|
|
|
| 46 |
})
|
| 47 |
return {"questions": questions}
|
| 48 |
except Exception as e:
|
| 49 |
+
return JSONResponse(status_code=500, content={"error": str(e)})
|