Update app.py
Browse files
app.py
CHANGED
|
@@ -497,3 +497,59 @@ async def download_section(job_id: str, section: str):
|
|
| 497 |
return StreamingResponse(io.BytesIO(gz),
|
| 498 |
media_type="application/gzip",
|
| 499 |
headers={"Content-Disposition": f'attachment; filename="{job_id}_{section}.json.gz"'} )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 497 |
return StreamingResponse(io.BytesIO(gz),
|
| 498 |
media_type="application/gzip",
|
| 499 |
headers={"Content-Disposition": f'attachment; filename="{job_id}_{section}.json.gz"'} )
|
| 500 |
+
|
| 501 |
+
@app.get("/selfcheck")
|
| 502 |
+
async def selfcheck(
|
| 503 |
+
receptor: str = Query("bupropion"),
|
| 504 |
+
symptom: str = Query("anhedonia")
|
| 505 |
+
):
|
| 506 |
+
"""
|
| 507 |
+
Runs the same checks your GPT does:
|
| 508 |
+
- /health
|
| 509 |
+
- /mechanism_graph_manifest
|
| 510 |
+
- /heuristics/regions_from_string
|
| 511 |
+
Returns a compact PASS/FAIL summary in one JSON.
|
| 512 |
+
"""
|
| 513 |
+
out = {"input": {"receptor": receptor, "symptom": symptom}}
|
| 514 |
+
|
| 515 |
+
# health
|
| 516 |
+
try:
|
| 517 |
+
out["health"] = {"ok": True, "data": health()}
|
| 518 |
+
except Exception as e:
|
| 519 |
+
out["health"] = {"ok": False, "error": str(e)}
|
| 520 |
+
|
| 521 |
+
# manifest
|
| 522 |
+
try:
|
| 523 |
+
mani = await mechanism_graph_manifest(
|
| 524 |
+
receptor=receptor, symptom=symptom,
|
| 525 |
+
species=9606, string_limit=50, lit_page_size=10
|
| 526 |
+
)
|
| 527 |
+
out["manifest"] = {
|
| 528 |
+
"ok": True,
|
| 529 |
+
"job_id": mani.get("job_id"),
|
| 530 |
+
"sections": mani.get("sections", [])
|
| 531 |
+
}
|
| 532 |
+
except Exception as e:
|
| 533 |
+
out["manifest"] = {"ok": False, "error": str(e)}
|
| 534 |
+
|
| 535 |
+
# regions (robust to drugs)
|
| 536 |
+
try:
|
| 537 |
+
reg = await regions_from_string(
|
| 538 |
+
receptor=receptor, species=9606,
|
| 539 |
+
limit=25, regions=None, use_synonyms=True, symptom=None
|
| 540 |
+
)
|
| 541 |
+
out["regions"] = {
|
| 542 |
+
"ok": True,
|
| 543 |
+
"count": len(reg.get("regions_ranked", [])),
|
| 544 |
+
"sample": reg.get("regions_ranked", [])[:5]
|
| 545 |
+
}
|
| 546 |
+
except Exception as e:
|
| 547 |
+
out["regions"] = {"ok": False, "error": str(e)}
|
| 548 |
+
|
| 549 |
+
# overall
|
| 550 |
+
out["overall_ok"] = all([
|
| 551 |
+
out["health"].get("ok"),
|
| 552 |
+
out["manifest"].get("ok"),
|
| 553 |
+
out["regions"].get("ok"),
|
| 554 |
+
])
|
| 555 |
+
return out
|