smitathkr1 commited on
Commit
90ab822
·
verified ·
1 Parent(s): e503dc0

Upload requirements.txt with huggingface_hub

Browse files
Files changed (1) hide show
  1. requirements.txt +107 -4
requirements.txt CHANGED
@@ -1,4 +1,107 @@
1
- # RDKit dependencies
2
- rdkit
3
- gradio==4.44.1
4
- huggingface_hub==0.19.4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from rdkit import Chem
3
+ from rdkit.Chem import Descriptors, Draw
4
+ import cirpy
5
+
6
+
7
+ def _mol_from_smiles(smiles: str):
8
+ mol = Chem.MolFromSmiles(smiles)
9
+ if mol is None:
10
+ raise gr.Error("Invalid SMILES string.")
11
+ return mol
12
+
13
+
14
+ def smiles_to_canonical(smiles: str) -> str:
15
+ mol = _mol_from_smiles(smiles)
16
+ return Chem.MolToSmiles(mol)
17
+
18
+
19
+ def molecular_weight(smiles: str) -> float:
20
+ mol = _mol_from_smiles(smiles)
21
+ return float(Descriptors.MolWt(mol))
22
+
23
+
24
+ def logp(smiles: str) -> float:
25
+ mol = _mol_from_smiles(smiles)
26
+ return float(Descriptors.MolLogP(mol))
27
+
28
+
29
+ def tpsa(smiles: str) -> float:
30
+ mol = _mol_from_smiles(smiles)
31
+ return float(Descriptors.TPSA(mol))
32
+
33
+
34
+ def mol_image(smiles: str):
35
+ mol = _mol_from_smiles(smiles)
36
+ return Draw.MolToImage(mol)
37
+
38
+
39
+ def name_to_smiles(name: str) -> str:
40
+ """Convert chemical name to SMILES using Chemical Identifier Resolver (CIR)"""
41
+ try:
42
+ smiles = cirpy.resolve(name, 'smiles')
43
+ if smiles is None:
44
+ raise gr.Error(f"Could not find SMILES for chemical name: {name}")
45
+ return smiles
46
+ except Exception as e:
47
+ raise gr.Error(f"Error converting name to SMILES: {str(e)}")
48
+
49
+
50
+ smiles_interface = gr.Interface(
51
+ fn=smiles_to_canonical,
52
+ inputs=gr.Textbox(label="SMILES"),
53
+ outputs=gr.Textbox(label="Canonical SMILES"),
54
+ api_name="smiles_to_mol",
55
+ description="Convert an input SMILES string to its canonical form.",
56
+ )
57
+
58
+ name_interface = gr.Interface(
59
+ fn=name_to_smiles,
60
+ inputs=gr.Textbox(label="Chemical Name", placeholder="e.g., aspirin, caffeine, benzene"),
61
+ outputs=gr.Textbox(label="SMILES"),
62
+ api_name="name_to_smiles",
63
+ description="Convert a chemical name to SMILES notation.",
64
+ examples=[["aspirin"], ["caffeine"], ["benzene"], ["ethanol"]],
65
+ )
66
+
67
+ mw_interface = gr.Interface(
68
+ fn=molecular_weight,
69
+ inputs=gr.Textbox(label="SMILES"),
70
+ outputs=gr.Number(label="Molecular Weight (g/mol)"),
71
+ api_name="molecular_weight",
72
+ description="Compute the molecular weight from a SMILES string.",
73
+ )
74
+
75
+ logp_interface = gr.Interface(
76
+ fn=logp,
77
+ inputs=gr.Textbox(label="SMILES"),
78
+ outputs=gr.Number(label="logP"),
79
+ api_name="logp",
80
+ description="Calculate the octanol/water partition coefficient (logP).",
81
+ )
82
+
83
+ tpsa_interface = gr.Interface(
84
+ fn=tpsa,
85
+ inputs=gr.Textbox(label="SMILES"),
86
+ outputs=gr.Number(label="TPSA"),
87
+ api_name="tpsa",
88
+ description="Calculate the topological polar surface area (TPSA).",
89
+ )
90
+
91
+
92
+ demo = gr.TabbedInterface(
93
+ [name_interface, smiles_interface, mw_interface, logp_interface, tpsa_interface],
94
+ [
95
+ "Name to SMILES",
96
+ "SMILES to Canonical",
97
+ "Molecular Weight",
98
+ "LogP",
99
+ "TPSA",
100
+ ],
101
+ title="RDKit API",
102
+ css=".gradio-container {max-width: 800px; margin: auto;}",
103
+ )
104
+
105
+
106
+ if __name__ == "__main__":
107
+ demo.queue().launch(server_name="0.0.0.0", server_port=7860)