bobbypaton commited on
Commit
6a594c1
Β·
1 Parent(s): ce437cf

Add 50 heavy atom limit; CASCADE 1.0 version label; iframe headers

Browse files
Files changed (2) hide show
  1. NMR_Prediction/valid.py +9 -2
  2. app.py +1 -3
NMR_Prediction/valid.py CHANGED
@@ -1,9 +1,16 @@
1
  from rdkit import Chem
2
 
3
 
 
 
 
4
  def validate_smiles(smiles: str) -> bool:
5
- """Return True if the SMILES is parseable by RDKit and non-empty."""
6
  if not smiles or not smiles.strip():
7
  return False
8
  mol = Chem.MolFromSmiles(smiles.strip())
9
- return mol is not None
 
 
 
 
 
1
  from rdkit import Chem
2
 
3
 
4
+ MAX_HEAVY_ATOMS = 50
5
+
6
+
7
  def validate_smiles(smiles: str) -> bool:
8
+ """Return True if the SMILES is parseable, non-empty, and within size limits."""
9
  if not smiles or not smiles.strip():
10
  return False
11
  mol = Chem.MolFromSmiles(smiles.strip())
12
+ if mol is None:
13
+ return False
14
+ if mol.GetNumHeavyAtoms() > MAX_HEAVY_ATOMS:
15
+ return False
16
+ return True
app.py CHANGED
@@ -36,7 +36,7 @@ def predict():
36
  # ── Job submission ────────────────────────────────────────────────────────────
37
  def _submit_job(smiles, type_):
38
  if not validate_smiles(smiles):
39
- return jsonify({"message": "Input molecule is not allowed", "task_id": None})
40
  task_id = uuid.uuid4().hex
41
  redis_client.set(f"task_detail_{task_id}",
42
  json.dumps({"smiles": smiles, "type_": type_}))
@@ -166,7 +166,6 @@ def create_app():
166
  @app.route("/")
167
  @app.route("/cascade_v1")
168
  def root():
169
- # meta-refresh + JS redirect so HF iframe follows it
170
  return '''<!DOCTYPE html>
171
  <html>
172
  <head>
@@ -176,7 +175,6 @@ def create_app():
176
  <body></body>
177
  </html>'''
178
 
179
- # Allow HF Spaces to embed the app in an iframe
180
  @app.after_request
181
  def remove_iframe_restriction(response):
182
  response.headers.pop("X-Frame-Options", None)
 
36
  # ── Job submission ────────────────────────────────────────────────────────────
37
  def _submit_job(smiles, type_):
38
  if not validate_smiles(smiles):
39
+ return jsonify({"message": "Invalid SMILES or molecule exceeds 50 heavy atoms", "task_id": None})
40
  task_id = uuid.uuid4().hex
41
  redis_client.set(f"task_detail_{task_id}",
42
  json.dumps({"smiles": smiles, "type_": type_}))
 
166
  @app.route("/")
167
  @app.route("/cascade_v1")
168
  def root():
 
169
  return '''<!DOCTYPE html>
170
  <html>
171
  <head>
 
175
  <body></body>
176
  </html>'''
177
 
 
178
  @app.after_request
179
  def remove_iframe_restriction(response):
180
  response.headers.pop("X-Frame-Options", None)