Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
|
|
| 1 |
import traceback
|
| 2 |
from fastapi import FastAPI, Request
|
| 3 |
from fastapi.responses import JSONResponse, HTMLResponse
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
from quiz_logic import generator
|
| 5 |
|
| 6 |
app = FastAPI()
|
|
@@ -13,7 +20,6 @@ async def home():
|
|
| 13 |
<body style="font-family: Arial; padding: 2em;">
|
| 14 |
<h1>🧠 Smart Quiz API</h1>
|
| 15 |
<p>This is the <strong>FastAPI backend</strong> for the Smart Quiz system. It provides an API endpoint to generate AI-powered multiple-choice quiz questions based on a given topic.</p>
|
| 16 |
-
|
| 17 |
<p>
|
| 18 |
👉 To try the full interactive quiz experience, please visit the Gradio UI:
|
| 19 |
<a href="https://huggingface.co/spaces/NZLouislu/smart-quiz-ui" target="_blank" rel="noopener noreferrer">
|
|
@@ -43,4 +49,4 @@ async def generate_quiz(request: Request):
|
|
| 43 |
return {"questions": [{"question": q["question"], "options": q["options"], "answer": q["answer"]} for q in questions]}
|
| 44 |
except Exception as e:
|
| 45 |
tb = traceback.format_exc()
|
| 46 |
-
return JSONResponse(status_code=500, content={"error": str(e), "traceback": tb})
|
|
|
|
| 1 |
+
import os
|
| 2 |
import traceback
|
| 3 |
from fastapi import FastAPI, Request
|
| 4 |
from fastapi.responses import JSONResponse, HTMLResponse
|
| 5 |
+
|
| 6 |
+
cache_dir = os.environ.get("HF_HOME", os.path.join(os.getcwd(), "hf_cache"))
|
| 7 |
+
os.makedirs(cache_dir, exist_ok=True)
|
| 8 |
+
os.environ["HF_HOME"] = cache_dir
|
| 9 |
+
os.environ["HF_DATASETS_CACHE"] = cache_dir
|
| 10 |
+
|
| 11 |
from quiz_logic import generator
|
| 12 |
|
| 13 |
app = FastAPI()
|
|
|
|
| 20 |
<body style="font-family: Arial; padding: 2em;">
|
| 21 |
<h1>🧠 Smart Quiz API</h1>
|
| 22 |
<p>This is the <strong>FastAPI backend</strong> for the Smart Quiz system. It provides an API endpoint to generate AI-powered multiple-choice quiz questions based on a given topic.</p>
|
|
|
|
| 23 |
<p>
|
| 24 |
👉 To try the full interactive quiz experience, please visit the Gradio UI:
|
| 25 |
<a href="https://huggingface.co/spaces/NZLouislu/smart-quiz-ui" target="_blank" rel="noopener noreferrer">
|
|
|
|
| 49 |
return {"questions": [{"question": q["question"], "options": q["options"], "answer": q["answer"]} for q in questions]}
|
| 50 |
except Exception as e:
|
| 51 |
tb = traceback.format_exc()
|
| 52 |
+
return JSONResponse(status_code=500, content={"error": str(e), "traceback": tb})
|