mohamed20003 commited on
Commit
161f144
·
verified ·
1 Parent(s): 5b65237

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -5
app.py CHANGED
@@ -14,6 +14,7 @@ torch.manual_seed(int(time.time()))
14
  if torch.cuda.is_available():
15
  torch.cuda.manual_seed_all(int(time.time()))
16
 
 
17
  model_name = "ncfrey/ChemGPT-1.2B"
18
  tokenizer = AutoTokenizer.from_pretrained(model_name)
19
  model = AutoModelForCausalLM.from_pretrained(model_name)
@@ -64,7 +65,9 @@ def generate_multiple_valid_smiles(prompt, n=10, max_length=100):
64
 
65
  def generate_from_pdb(pdb_file):
66
  try:
67
- pdb_str = pdb_file.read().decode('utf-8', errors='ignore')
 
 
68
  if len(pdb_str.strip()) == 0:
69
  return "❌ الملف فارغ أو غير صالح", None, None
70
 
@@ -75,6 +78,7 @@ def generate_from_pdb(pdb_file):
75
  return f"❌ خطأ أثناء تحليل ملف PDB:\n{str(e)}", None, None
76
 
77
  html_3d = get_protein_3d_html(pdb_str)
 
78
  prompt = "Generate a molecule in SELFIES that binds to the mutated KRAS protein"
79
  smiles_list = generate_multiple_valid_smiles(prompt, n=10)
80
 
@@ -87,6 +91,7 @@ def generate_from_pdb(pdb_file):
87
  f.write(smiles_txt)
88
 
89
  return "✅ تم توليد المركبات بنجاح", html_3d, smiles_file_path
 
90
  except Exception as e:
91
  return f"❌ حدث خطأ:\n{str(e)}", None, None
92
 
@@ -98,12 +103,18 @@ h1 {color: #004d66; text-align: center;}
98
  with gr.Blocks(css=css) as demo:
99
  gr.Markdown("<h1>🔬 Drug-like Molecule Generation from PDB using ChemGPT</h1>")
100
  gr.Markdown("🧪 Upload a PDB file containing mutations in the KRAS protein. The system will generate suitable SMILES drug candidates.")
 
101
  with gr.Row():
102
  pdb_input = gr.File(label="📁 Upload PDB File")
103
- run_btn = gr.Button("🚀 Generate Compounds")
104
  status = gr.Textbox(label="📢 Status")
105
- view3d = gr.HTML(label="🧬 3D Structure Viewer")
106
  file_output = gr.File(label="📄 Download SMILES File")
107
- run_btn.click(fn=generate_from_pdb, inputs=pdb_input, outputs=[status, view3d, file_output])
 
 
 
 
108
 
109
- demo.launch()
 
 
14
  if torch.cuda.is_available():
15
  torch.cuda.manual_seed_all(int(time.time()))
16
 
17
+ # تحميل النموذج
18
  model_name = "ncfrey/ChemGPT-1.2B"
19
  tokenizer = AutoTokenizer.from_pretrained(model_name)
20
  model = AutoModelForCausalLM.from_pretrained(model_name)
 
65
 
66
  def generate_from_pdb(pdb_file):
67
  try:
68
+ with open(pdb_file.name, 'r', encoding='utf-8', errors='ignore') as f:
69
+ pdb_str = f.read()
70
+
71
  if len(pdb_str.strip()) == 0:
72
  return "❌ الملف فارغ أو غير صالح", None, None
73
 
 
78
  return f"❌ خطأ أثناء تحليل ملف PDB:\n{str(e)}", None, None
79
 
80
  html_3d = get_protein_3d_html(pdb_str)
81
+
82
  prompt = "Generate a molecule in SELFIES that binds to the mutated KRAS protein"
83
  smiles_list = generate_multiple_valid_smiles(prompt, n=10)
84
 
 
91
  f.write(smiles_txt)
92
 
93
  return "✅ تم توليد المركبات بنجاح", html_3d, smiles_file_path
94
+
95
  except Exception as e:
96
  return f"❌ حدث خطأ:\n{str(e)}", None, None
97
 
 
103
  with gr.Blocks(css=css) as demo:
104
  gr.Markdown("<h1>🔬 Drug-like Molecule Generation from PDB using ChemGPT</h1>")
105
  gr.Markdown("🧪 Upload a PDB file containing mutations in the KRAS protein. The system will generate suitable SMILES drug candidates.")
106
+
107
  with gr.Row():
108
  pdb_input = gr.File(label="📁 Upload PDB File")
109
+ run_btn = gr.Button("🚀 Generate Molecules")
110
  status = gr.Textbox(label="📢 Status")
111
+ view3d = gr.HTML(label="🧬 3D Structure View")
112
  file_output = gr.File(label="📄 Download SMILES File")
113
+ run_btn.click(
114
+ fn=generate_from_pdb,
115
+ inputs=pdb_input,
116
+ outputs=[status, view3d, file_output]
117
+ )
118
 
119
+ if __name__ == "__main__":
120
+ demo.launch()