mohamed20003 commited on
Commit
52af9bb
ยท
verified ยท
1 Parent(s): e0d93b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -13
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 "โŒ ุงู„ู…ู„ู ูุงุฑุบ ุฃูˆ ุบูŠุฑ ุตุงู„ุญ", None, None
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"โŒ ุฎุทุฃ ุฃุซู†ุงุก ุชุญู„ูŠู„ ู…ู„ู PDB:\n{str(e)}", None, None
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 "โŒ ู„ู… ูŠุชู… ุชูˆู„ูŠุฏ ุฃูŠ SMILES ุตุงู„ุญุฉ", html_3d, None
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 "โœ… ุชู… ุชูˆู„ูŠุฏ ุงู„ู…ุฑูƒุจุงุช ุจู†ุฌุงุญ", html_3d, smiles_file_path
97
 
98
  except Exception as e:
99
- return f"โŒ ุญุฏุซ ุฎุทุฃ:\n{str(e)}", None, None
100
 
 
101
  css = """
102
- body {background-color: #f0f9ff;}
103
- h1 {color: #004d66; text-align: center;}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  """
105
 
106
  with gr.Blocks(css=css) as demo:
107
- gr.Markdown("<h1>๐Ÿ”ฌ Drug-like Molecule Generation from PDB using ChemGPT</h1>")
108
- gr.Markdown("๐Ÿงช Upload a PDB file containing mutations in the KRAS protein. The system will generate suitable SMILES drug candidates.")
109
-
 
110
  with gr.Row():
111
  pdb_input = gr.File(label="๐Ÿ“ Upload PDB File")
112
- run_btn = gr.Button("๐Ÿš€ Generate Compounds")
 
113
  status = gr.Textbox(label="๐Ÿ“ข Status")
114
- view3d = gr.HTML(label="๐Ÿงฌ 3D Structure Viewer")
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)