Zhaohan Meng commited on
Commit
74c58b5
Β·
verified Β·
1 Parent(s): 3647a14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -6
app.py CHANGED
@@ -1,3 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
  import sys
3
  import argparse
@@ -9,7 +33,6 @@ import io
9
  import torch
10
  import selfies
11
  from rdkit import Chem
12
- import gradio as gr
13
  import matplotlib
14
  matplotlib.use("Agg")
15
  import matplotlib.pyplot as plt
@@ -41,11 +64,11 @@ def simple_seq_from_structure(path: str) -> str:
41
  def smiles_to_selfies(smiles: str) -> Optional[str]:
42
  try:
43
  mol = Chem.MolFromSmiles(smiles)
44
- if mol is "":
45
- return ""
46
  return selfies.encoder(smiles)
47
- except:
48
- return ""
49
 
50
  def parse_config():
51
  p = argparse.ArgumentParser()
@@ -540,4 +563,4 @@ with gr.Blocks(css=css) as demo:
540
  )
541
 
542
  if __name__ == "__main__":
543
- demo.launch(server_name="0.0.0.0", server_port=7860)
 
1
+ # ─── monkey-patch gradio_client so bool schemas don’t crash json_schema_to_python_type ───
2
+ import gradio_client.utils as _gc_utils
3
+
4
+ # back up originals
5
+ _orig_get_type = _gc_utils.get_type
6
+ _orig_json2py = _gc_utils._json_schema_to_python_type
7
+
8
+ def _patched_get_type(schema):
9
+ # treat any boolean schema as if it were an empty dict
10
+ if isinstance(schema, bool):
11
+ schema = {}
12
+ return _orig_get_type(schema)
13
+
14
+ def _patched_json_schema_to_python_type(schema, defs=None):
15
+ # treat any boolean schema as if it were an empty dict
16
+ if isinstance(schema, bool):
17
+ schema = {}
18
+ return _orig_json2py(schema, defs)
19
+
20
+ _gc_utils.get_type = _patched_get_type
21
+ _gc_utils._json_schema_to_python_type = _patched_json_schema_to_python_type
22
+
23
+ # ─── now it’s safe to import Gradio and build your interface ───────────────────────────
24
+ import gradio as gr
25
  import os
26
  import sys
27
  import argparse
 
33
  import torch
34
  import selfies
35
  from rdkit import Chem
 
36
  import matplotlib
37
  matplotlib.use("Agg")
38
  import matplotlib.pyplot as plt
 
64
  def smiles_to_selfies(smiles: str) -> Optional[str]:
65
  try:
66
  mol = Chem.MolFromSmiles(smiles)
67
+ if mol is None:
68
+ return None
69
  return selfies.encoder(smiles)
70
+ except Exception:
71
+ return None
72
 
73
  def parse_config():
74
  p = argparse.ArgumentParser()
 
563
  )
564
 
565
  if __name__ == "__main__":
566
+ demo.launch(share=True)