Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
from Bio import PDB
|
2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
3 |
from rdkit import Chem
|
@@ -72,13 +73,13 @@ def generate_from_pdb(pdb_file):
|
|
72 |
pdb_str = pdb_bytes.decode('utf-8', errors='ignore')
|
73 |
|
74 |
if len(pdb_str.strip()) == 0:
|
75 |
-
return "โ
|
76 |
|
77 |
pdb_file_io = io.StringIO(pdb_str)
|
78 |
try:
|
79 |
load_pdb(pdb_file_io)
|
80 |
except Exception as e:
|
81 |
-
return f"โ
|
82 |
|
83 |
html_3d = get_protein_3d_html(pdb_str)
|
84 |
|
@@ -86,32 +87,55 @@ def generate_from_pdb(pdb_file):
|
|
86 |
smiles_list = generate_multiple_valid_smiles(prompt, n=10)
|
87 |
|
88 |
if not smiles_list:
|
89 |
-
return "โ
|
90 |
|
91 |
smiles_txt = "\n".join(smiles_list)
|
92 |
smiles_file_path = "/tmp/generated_smiles.txt"
|
93 |
with open(smiles_file_path, "w") as f:
|
94 |
f.write(smiles_txt)
|
95 |
|
96 |
-
return "โ
|
97 |
|
98 |
except Exception as e:
|
99 |
-
return f"โ
|
100 |
|
|
|
101 |
css = """
|
102 |
-
body {
|
103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
"""
|
105 |
|
106 |
with gr.Blocks(css=css) as demo:
|
107 |
-
gr.Markdown("
|
108 |
-
|
109 |
-
|
|
|
110 |
with gr.Row():
|
111 |
pdb_input = gr.File(label="๐ Upload PDB File")
|
112 |
-
run_btn = gr.Button("๐ Generate
|
|
|
113 |
status = gr.Textbox(label="๐ข Status")
|
114 |
-
view3d = gr.HTML(label="๐งฌ 3D Structure
|
115 |
file_output = gr.File(label="๐ Download SMILES File")
|
116 |
|
117 |
run_btn.click(
|
@@ -120,4 +144,4 @@ with gr.Blocks(css=css) as demo:
|
|
120 |
outputs=[status, view3d, file_output]
|
121 |
)
|
122 |
|
123 |
-
demo.launch()
|
|
|
1 |
+
# app.py
|
2 |
from Bio import PDB
|
3 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
4 |
from rdkit import Chem
|
|
|
73 |
pdb_str = pdb_bytes.decode('utf-8', errors='ignore')
|
74 |
|
75 |
if len(pdb_str.strip()) == 0:
|
76 |
+
return "โ The file is empty or invalid.", None, None
|
77 |
|
78 |
pdb_file_io = io.StringIO(pdb_str)
|
79 |
try:
|
80 |
load_pdb(pdb_file_io)
|
81 |
except Exception as e:
|
82 |
+
return f"โ Error parsing the PDB file:\n{str(e)}", None, None
|
83 |
|
84 |
html_3d = get_protein_3d_html(pdb_str)
|
85 |
|
|
|
87 |
smiles_list = generate_multiple_valid_smiles(prompt, n=10)
|
88 |
|
89 |
if not smiles_list:
|
90 |
+
return "โ No valid SMILES generated.", html_3d, None
|
91 |
|
92 |
smiles_txt = "\n".join(smiles_list)
|
93 |
smiles_file_path = "/tmp/generated_smiles.txt"
|
94 |
with open(smiles_file_path, "w") as f:
|
95 |
f.write(smiles_txt)
|
96 |
|
97 |
+
return "โ
Molecules generated successfully.", html_3d, smiles_file_path
|
98 |
|
99 |
except Exception as e:
|
100 |
+
return f"โ An unexpected error occurred:\n{str(e)}", None, None
|
101 |
|
102 |
+
# CSS to beautify the interface
|
103 |
css = """
|
104 |
+
body {
|
105 |
+
background-color: #f0f9ff;
|
106 |
+
font-family: 'Segoe UI', sans-serif;
|
107 |
+
}
|
108 |
+
h1 {
|
109 |
+
color: #003d66;
|
110 |
+
text-align: center;
|
111 |
+
font-size: 32px;
|
112 |
+
}
|
113 |
+
.gr-box {
|
114 |
+
border: 1px solid #cce7ff;
|
115 |
+
background-color: #ffffff;
|
116 |
+
border-radius: 15px;
|
117 |
+
padding: 20px;
|
118 |
+
box-shadow: 0 2px 8px rgba(0, 128, 255, 0.1);
|
119 |
+
}
|
120 |
+
button {
|
121 |
+
background-color: #007acc !important;
|
122 |
+
color: white !important;
|
123 |
+
font-weight: bold;
|
124 |
+
border-radius: 10px !important;
|
125 |
+
}
|
126 |
"""
|
127 |
|
128 |
with gr.Blocks(css=css) as demo:
|
129 |
+
gr.Markdown("""
|
130 |
+
<h1>๐ฌ Drug-like Molecule Generation from PDB using ChemGPT</h1>
|
131 |
+
<p>๐งช Upload a PDB file containing mutations in the KRAS protein. The system will generate suitable SMILES drug candidates.</p>
|
132 |
+
""")
|
133 |
with gr.Row():
|
134 |
pdb_input = gr.File(label="๐ Upload PDB File")
|
135 |
+
run_btn = gr.Button("๐ Generate Molecules")
|
136 |
+
|
137 |
status = gr.Textbox(label="๐ข Status")
|
138 |
+
view3d = gr.HTML(label="๐งฌ 3D Structure View")
|
139 |
file_output = gr.File(label="๐ Download SMILES File")
|
140 |
|
141 |
run_btn.click(
|
|
|
144 |
outputs=[status, view3d, file_output]
|
145 |
)
|
146 |
|
147 |
+
demo.launch(share=True)
|