Spaces:
Sleeping
Sleeping
Update api_server.py
Browse files- api_server.py +17 -1
api_server.py
CHANGED
|
@@ -65,7 +65,23 @@ def submit(sub: Submission):
|
|
| 65 |
total_attempted=total,
|
| 66 |
message=f"Puntuaci贸n: {correct}/{total} = {score:.1f}%"
|
| 67 |
)
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
from fastapi.responses import HTMLResponse
|
| 70 |
|
| 71 |
@app.get("/", response_class=HTMLResponse)
|
|
|
|
| 65 |
total_attempted=total,
|
| 66 |
message=f"Puntuaci贸n: {correct}/{total} = {score:.1f}%"
|
| 67 |
)
|
| 68 |
+
# GET /random-question: Fetch a single random question from the list.
|
| 69 |
+
@app.get("/random-question")
|
| 70 |
+
def get_random_question():
|
| 71 |
+
if not QUESTIONS:
|
| 72 |
+
return {"error": "No questions available"}
|
| 73 |
+
question = random.choice(QUESTIONS)
|
| 74 |
+
return question
|
| 75 |
+
|
| 76 |
+
# GET /files/{task_id}: Download a specific file associated with a given task ID.
|
| 77 |
+
@app.get("/files/{task_id}")
|
| 78 |
+
def get_file(task_id: str):
|
| 79 |
+
file_path = f"files/{task_id}.txt"
|
| 80 |
+
if not os.path.exists(file_path):
|
| 81 |
+
return {"error": "File not found"}
|
| 82 |
+
with open(file_path, "r") as file:
|
| 83 |
+
content = file.read()
|
| 84 |
+
return {"task_id": task_id, "content": content}
|
| 85 |
from fastapi.responses import HTMLResponse
|
| 86 |
|
| 87 |
@app.get("/", response_class=HTMLResponse)
|