Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions training/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,57 @@ def api_suggest(qs: str = ""):
return {"items": items}


# --- Aroma PREVIEW (illustrative, NOT a trained model) -------------------------
# Well-known odor characters for a handful of famous flavor molecules, so the demo can
# SHOW what an unlocked aroma read looks like. These are common-knowledge descriptors
# used as an illustration — the real model trains on a customer's expert-labeled odor
# data (see docs/AROMA.md). Clearly flagged "preview" in the UI; never passed off as live.
_AROMA_PREVIEW_RAW = [
("O=Cc1ccc(O)c(OC)c1", [("vanilla", 0.95), ("sweet", 0.6), ("creamy", 0.4), ("woody", 0.25)]),
("CC1=CCC(CC1)C(C)=C", [("citrus", 0.9), ("orange", 0.7), ("fresh", 0.5), ("terpene", 0.3)]),
("CC(C)C1CCC(C)CC1O", [("minty", 0.9), ("cooling", 0.7), ("fresh", 0.5), ("herbal", 0.3)]),
("C=CCc1ccc(O)c(OC)c1", [("clove", 0.9), ("spicy", 0.7), ("woody", 0.4), ("sweet", 0.3)]),
("O=Cc1ccccc1", [("almond", 0.95), ("cherry", 0.5), ("sweet", 0.4)]),
("O=C/C=C/c1ccccc1", [("cinnamon", 0.95), ("spicy", 0.6), ("sweet", 0.4), ("warm", 0.3)]),
("CC(C)=CCCC(C)(O)C=C", [("floral", 0.85), ("lavender", 0.6), ("citrus", 0.4), ("woody", 0.25)]),
("CCCC(=O)OCC", [("fruity", 0.9), ("pineapple", 0.7), ("sweet", 0.5)]),
("CC(=O)C(C)=O", [("buttery", 0.95), ("creamy", 0.6)]),
("CC(C)=CCC/C(C)=C/CO", [("rose", 0.85), ("floral", 0.7), ("citrus", 0.3)]),
("CCOC(C)=O", [("solvent", 0.6), ("fruity", 0.5), ("sweet", 0.3)]),
("O=Cc1ccco1", [("almond", 0.7), ("bready", 0.6), ("caramel", 0.5), ("sweet", 0.3)]),
("Cc1ccc(C(C)C)cc1O", [("thyme", 0.85), ("herbal", 0.7), ("medicinal", 0.4), ("spicy", 0.3)]),
("COc1ccccc1O", [("smoky", 0.85), ("medicinal", 0.6), ("woody", 0.5), ("spicy", 0.3)]),
("C/C=C/c1ccc(OC)cc1", [("anise", 0.9), ("licorice", 0.7), ("sweet", 0.5)]),
("CC(=O)CCc1ccc(O)cc1", [("raspberry", 0.9), ("jammy", 0.6), ("sweet", 0.5)]),
]


def _aroma_index():
out = {}
for smi, descs in _AROMA_PREVIEW_RAW:
m = Chem.MolFromSmiles(smi)
if m is not None:
out[Chem.MolToInchiKey(m).split("-")[0]] = descs
return out


_AROMA_PREVIEW = _aroma_index()


@app.post("/api/aroma")
def api_aroma(q: Query):
"""ILLUSTRATIVE aroma preview for a few well-known molecules — NOT a live model."""
smi = _resolve(q.smiles)
mol = Chem.MolFromSmiles(smi) if smi else None
if mol is None:
return {"available": False}
descs = _AROMA_PREVIEW.get(Chem.MolToInchiKey(mol).split("-")[0])
if not descs:
return {"available": False}
return {"available": True, "preview": True,
"descriptors": [{"odor": n, "score": s} for n, s in descs]}


@app.get("/", response_class=HTMLResponse)
def home():
return Path("workbench.html").read_text()
23 changes: 21 additions & 2 deletions training/workbench.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@
.aroma-lead b{color:var(--aroma)}
.aroma-note{font-size:13px;color:var(--muted);margin:0;line-height:1.55;max-width:760px}
.aroma-note b{color:var(--ink)}
.aroma-prev-tag{font-size:11px;font-weight:650;text-transform:uppercase;letter-spacing:.05em;color:var(--aroma);margin:0 0 10px}
.ameter{margin:8px 0}
.arow{display:flex;justify-content:space-between;align-items:baseline;margin-bottom:4px}
.aname{font-weight:600;font-size:13px;text-transform:capitalize}
.aval{font-family:var(--mono);font-size:12px;color:var(--muted)}
.atrack{height:8px;background:#EDEFEC;border-radius:5px;overflow:hidden}
.afill{height:100%;background:var(--aroma);border-radius:5px;transition:width .5s ease}
.kv{display:grid;grid-template-columns:auto 1fr;gap:6px 16px;margin-bottom:10px}
.kv .k{font-weight:600;font-size:13px}
.kv .v{font-family:var(--mono);font-size:13px;color:var(--muted)}
Expand Down Expand Up @@ -166,6 +173,7 @@ <h2>Behavior &amp; safety</h2>

<div class="card aroma-card" id="aromaCard" style="display:none">
<h2>Aroma</h2>
<div id="aromaPreview" style="display:none;margin-bottom:14px"></div>
<div class="aroma-lead">Aroma prediction unlocks with <b>your</b> data.</div>
<p class="aroma-note">The public demo predicts <b>taste</b> from open data. A useful
aroma model needs expert-labeled odor data — so we train it <b>on-premise, on your
Expand Down Expand Up @@ -217,14 +225,16 @@ <h2>Aroma</h2>
go.disabled = true; go.textContent = 'Reading…';
$('err').style.display='none';
try{
const [p, n, s, nm] = await Promise.all([
const [p, n, s, nm, ar] = await Promise.all([
post('/api/predict',{smiles:text}),
post('/api/neighbors',{smiles:text, k:8}),
post('/api/structure',{smiles:text}),
post('/api/names',{smiles:text})
post('/api/names',{smiles:text}),
post('/api/aroma',{smiles:text})
]);
if(p.error){ throw new Error(p.error); }
render(p, n.neighbors||[], (s&&s.svg)||null, nm||{});
renderAroma(ar||{});
}catch(e){
$('results').style.display='none'; $('behaviorCard').style.display='none'; $('aromaCard').style.display='none'; $('footnote').style.display='none';
$('err').textContent = e.message; $('err').style.display='block';
Expand Down Expand Up @@ -340,6 +350,15 @@ <h2>Aroma</h2>
$('behavior').innerHTML = html;
}

function renderAroma(ar){
const box=$('aromaPreview');
if(ar && ar.available && (ar.descriptors||[]).length){
box.innerHTML='<div class="aroma-prev-tag">▸ preview — illustrative of the unlocked read (not a live prediction)</div>'+
ar.descriptors.map(d=>{ const pct=Math.round(d.score*100); return `<div class="ameter"><div class="arow"><span class="aname">${d.odor}</span><span class="aval">${pct}%</span></div><div class="atrack"><div class="afill" style="width:${pct}%"></div></div></div>`; }).join('');
box.style.display='block';
} else { box.style.display='none'; }
}

function chip(key, on, color, label){
const style = on && color ? `style="background:${color}"` : '';
return `<span class="chip ${on?'on':''}" ${style}>${label}</span>`;
Expand Down
Loading