mohamed20003 commited on
Commit
5001317
·
verified ·
1 Parent(s): 77ae812

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -11
app.py CHANGED
@@ -6,7 +6,7 @@ import matplotlib.pyplot as plt
6
  import io
7
  import base64
8
 
9
- # تحليل ADMET
10
  def get_admet(smiles):
11
  mol = Chem.MolFromSmiles(smiles)
12
  if not mol:
@@ -21,23 +21,25 @@ def get_admet(smiles):
21
  return pd.Series([mw, logp, tpsa, hba, hbd, rotb, lipinski],
22
  index=["MW", "LogP", "TPSA", "HBA", "HBD", "RotB", "Lipinski"])
23
 
24
- # المعالجة الرئيسية
25
- def analyze_smiles(file):
26
  try:
27
- with open(file.name, "r", encoding="utf-8") as f:
28
- content = f.read()
29
  smiles_list = [line.strip() for line in content.splitlines() if line.strip()]
 
 
30
  df = pd.DataFrame({"SMILES": smiles_list})
31
  admet_df = df["SMILES"].apply(get_admet)
32
  final_df = pd.concat([df, admet_df], axis=1)
33
 
34
- # Excel file
35
  excel_buffer = io.BytesIO()
36
  final_df.to_excel(excel_buffer, index=False, engine="openpyxl")
37
  excel_data = excel_buffer.getvalue()
38
  excel_b64 = base64.b64encode(excel_data).decode()
39
 
40
- # Plot image
41
  plot_df = final_df.dropna(subset=["LogP"])
42
  plt.figure(figsize=(10, 6))
43
  plt.barh(plot_df["SMILES"], plot_df["LogP"], color="skyblue")
@@ -51,7 +53,7 @@ def analyze_smiles(file):
51
  img_b64 = base64.b64encode(img_buffer.read()).decode()
52
  plt.close()
53
 
54
- # Markdown table
55
  table_md = final_df.to_markdown(index=False)
56
 
57
  return (
@@ -67,9 +69,9 @@ def analyze_smiles(file):
67
  # واجهة Gradio
68
  with gr.Blocks() as demo:
69
  gr.Markdown("## 🧪 تحليل ADMET من قائمة SMILES")
70
-
71
  with gr.Row():
72
- smiles_file = gr.File(label="📄 ارفع ملف .txt يحتوي على SMILES")
73
  run_btn = gr.Button("🚀 تحليل ADMET")
74
 
75
  status = gr.Textbox(label="📢 الحالة")
@@ -77,6 +79,10 @@ with gr.Blocks() as demo:
77
  download = gr.HTML()
78
  image = gr.HTML()
79
 
80
- run_btn.click(fn=analyze_smiles, inputs=[smiles_file], outputs=[status, table, download, image])
 
 
 
 
81
 
82
  demo.launch()
 
6
  import io
7
  import base64
8
 
9
+ # دالة لحساب خصائص ADMET
10
  def get_admet(smiles):
11
  mol = Chem.MolFromSmiles(smiles)
12
  if not mol:
 
21
  return pd.Series([mw, logp, tpsa, hba, hbd, rotb, lipinski],
22
  index=["MW", "LogP", "TPSA", "HBA", "HBD", "RotB", "Lipinski"])
23
 
24
+ # دالة رئيسية لتحليل الملف
25
+ def analyze_smiles(uploaded_file):
26
  try:
27
+ # قراءة محتوى الملف مباشرة
28
+ content = uploaded_file.decode("utf-8")
29
  smiles_list = [line.strip() for line in content.splitlines() if line.strip()]
30
+
31
+ # بناء جدول البيانات
32
  df = pd.DataFrame({"SMILES": smiles_list})
33
  admet_df = df["SMILES"].apply(get_admet)
34
  final_df = pd.concat([df, admet_df], axis=1)
35
 
36
+ # حفظ ملف Excel
37
  excel_buffer = io.BytesIO()
38
  final_df.to_excel(excel_buffer, index=False, engine="openpyxl")
39
  excel_data = excel_buffer.getvalue()
40
  excel_b64 = base64.b64encode(excel_data).decode()
41
 
42
+ # رسم مخطط LogP
43
  plot_df = final_df.dropna(subset=["LogP"])
44
  plt.figure(figsize=(10, 6))
45
  plt.barh(plot_df["SMILES"], plot_df["LogP"], color="skyblue")
 
53
  img_b64 = base64.b64encode(img_buffer.read()).decode()
54
  plt.close()
55
 
56
+ # تحويل النتائج إلى جدول Markdown
57
  table_md = final_df.to_markdown(index=False)
58
 
59
  return (
 
69
  # واجهة Gradio
70
  with gr.Blocks() as demo:
71
  gr.Markdown("## 🧪 تحليل ADMET من قائمة SMILES")
72
+
73
  with gr.Row():
74
+ smiles_file = gr.File(label="📄 ارفع ملف .txt يحتوي على SMILES", file_types=[".txt"])
75
  run_btn = gr.Button("🚀 تحليل ADMET")
76
 
77
  status = gr.Textbox(label="📢 الحالة")
 
79
  download = gr.HTML()
80
  image = gr.HTML()
81
 
82
+ run_btn.click(
83
+ fn=lambda file: analyze_smiles(file.read()),
84
+ inputs=[smiles_file],
85
+ outputs=[status, table, download, image]
86
+ )
87
 
88
  demo.launch()