mohamed20003 commited on
Commit
6501c66
·
verified ·
1 Parent(s): 5001317

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -21,25 +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(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,7 +53,7 @@ def analyze_smiles(uploaded_file):
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 (
@@ -80,7 +80,7 @@ with gr.Blocks() as demo:
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
  )
 
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
+ # قراءة محتوى الملف باستخدام .read() ثم decode
28
+ content = file.read().decode("utf-8")
29
  smiles_list = [line.strip() for line in content.splitlines() if line.strip()]
30
 
31
+ # إنشاء DataFrame وتحليل ADMET
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 (
 
80
  image = gr.HTML()
81
 
82
  run_btn.click(
83
+ fn=analyze_smiles,
84
  inputs=[smiles_file],
85
  outputs=[status, table, download, image]
86
  )