Spaces:
Running

tfrere HF Staff Cursor commited on
Commit
543de2f
·
1 Parent(s): d5563b7

Add /fold endpoint proxying NVIDIA NIM ESMFold

Browse files

Frontend §5 (the "From sequence to structure" section) needs predicted
3D structures to render. We proxy through the backend so the NIM API key
stays on the server.

Body: {"sequence": "<AA>"}
Returns: {"pdb": str, "n_residues": int, "plddt_mean": float, "cached": bool}
or {"error": str} on failure.

Implementation notes:
- httpx (already pulled in transitively by openai) replaces urllib so SSL
works out of the box on macOS without certifi gymnastics. Declared
explicitly in requirements.txt.
- Sequence is filtered to the 20 standard AAs before submission — NIM
rejects anything outside that charset (incl. stop codons "*"), and
callers shouldn't need to know the exact regex.
- Truncated to 1024 aa (NIM's hard cap).
- pLDDT mean is extracted from the B-factor column on CA atoms so the
frontend can show a global confidence score without re-parsing the PDB.
- sha1(sequence) → result FIFO cache (max 256 entries) since ESMFold is
deterministic. Demo viewers re-folding the same gene over and over
cost zero NIM calls.

Smoke-tested locally:
47 aa peptide → 0.55s, pLDDT 66.9
HBB 147 aa → 0.62s, pLDDT 93.8
cache hit → 0.037s (16x speedup)

Co-authored-by: Cursor <cursoragent@cursor.com>

2 files changed +109
Files changed (2)
app.py+108
requirements.txt+1