File size: 4,446 Bytes
050c4cd
031d78f
 
050c4cd
031d78f
050c4cd
031d78f
050c4cd
 
031d78f
 
 
 
050c4cd
 
031d78f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
---
title: TuringDNA Assistant
emoji: 🧬
colorFrom: gray
colorTo: blue
sdk: gradio
sdk_version: 4.44.0
app_file: app.py
pinned: false
license: apache-2.0
hardware: zero-a10g
short_description: Protein biology Q&A backend for the TuringDNA engine.
suggested_hardware: zero-a10g
---

# TuringDNA Assistant

Self-hosted biomedical LLM that powers the in-app chat panel on
[turingdna.com/app](https://turingdna.com/app). Loads **BioMistral-7B**
(an open-source Mistral fine-tuned on biomedical corpora) on a
ZeroGPU-shared NVIDIA A100, exposes a Gradio `ChatInterface` for direct
testing, and an auto-generated `/run/predict` API the Flask app calls
via `gradio_client`.

## Architecture

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  winter4000/syntheogenesis            (Flask + vanilla JS, CPU)     β”‚
β”‚  └── dee/server.py /api/chat                                        β”‚
β”‚        └── gradio_client.predict() ──────────────────────────┐      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”˜
                                                                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  winter4000/turingdna-assistant       (Gradio, ZeroGPU)             β”‚
β”‚  β”œβ”€β”€ app.py     Gradio ChatInterface                                β”‚
β”‚  └── llm.py     BioMistral-7B in bf16, @spaces.GPU(duration=60)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

Two-Space split so the existing Flask engine doesn't need a rewrite and
the model lives where the GPU does.

## Why ZeroGPU?

ZeroGPU gives shared A100 access to HF PRO subscribers at no per-hour
cost (just the $9/mo subscription). The decorator pattern:
- Model loads on CPU at import (~14 GB in bf16, fits comfortably in
  ZeroGPU's 60 GB host RAM)
- `@spaces.GPU(duration=60)` moves the model to GPU only during a
  generation call, then releases β€” so we share the A100 efficiently
  with other ZeroGPU Spaces

First call after the Space wakes up: ~10–30 s (cold-start + GPU acquire).
Subsequent calls: ~25–80 tokens/sec.

## Model

[BioMistral/BioMistral-7B](https://huggingface.co/BioMistral/BioMistral-7B)
β€” Apache-2.0, biomedical-domain fine-tune of Mistral-7B-Instruct-v0.1.
Knows enzyme mechanisms, active sites, conserved domains, codon
optimization, expression systems, and cloning vocab better than vanilla
Mistral. Same Mistral instruct template (`[INST] ... [/INST]`).

Fallback if BioMistral fetch fails: `mistralai/Mistral-7B-Instruct-v0.2`.

## System prompt

Baked into `llm.py`. The assistant is told it's the chat backend for
TuringDNA, knows the codebase's Ξ”LL sign convention (positive Ξ”LL =
mutation is MORE likely than WT under ESM-2, i.e. more tolerated;
negative = less likely, i.e. disruptive), and is instructed to be
concise + not hallucinate domain boundaries.

## Local development

```bash
pip install -r requirements.txt
python app.py
```

Local runs use CPU-only fp16 (~2 tok/s on Mac M1, ~1 tok/s on Intel
Mac). Production runs on ZeroGPU A100. The `@spaces.GPU` decorator
is a no-op locally so the same code works in both contexts.

## Calling from outside

```python
from gradio_client import Client

client = Client("winter4000/turingdna-assistant")
response = client.predict(
    message="What does a Ξ”LL of +1.2 for V8L mean?",
    history=[],
    api_name="/chat",
)
print(response)
```

## Files

- `app.py` β€” Gradio app entry (ChatInterface + Gradio launches its own
  API endpoints)
- `llm.py` β€” model loading + Mistral prompt formatting + ZeroGPU
  inference function
- `requirements.txt` β€” Gradio, transformers, spaces, torch, accelerate
- `README.md` β€” this file (also the HF Space metadata via YAML
  frontmatter at the top)