Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,12 +2,10 @@ import gradio as gr
|
|
2 |
from rdkit import Chem
|
3 |
from rdkit.Chem import Descriptors
|
4 |
import pandas as pd
|
5 |
-
import matplotlib.pyplot as plt
|
6 |
import io
|
7 |
import base64
|
8 |
-
import os
|
9 |
|
10 |
-
#
|
11 |
def get_admet(smiles):
|
12 |
mol = Chem.MolFromSmiles(smiles)
|
13 |
if not mol:
|
@@ -25,11 +23,7 @@ def get_admet(smiles):
|
|
25 |
# المعالجة الرئيسية
|
26 |
def analyze_smiles(file):
|
27 |
try:
|
28 |
-
|
29 |
-
file_path = file.name if hasattr(file, "name") else file
|
30 |
-
with open(file_path, "r", encoding="utf-8") as f:
|
31 |
-
content = f.read()
|
32 |
-
|
33 |
smiles_list = [line.strip() for line in content.splitlines() if line.strip()]
|
34 |
df = pd.DataFrame({"SMILES": smiles_list})
|
35 |
admet_df = df["SMILES"].apply(get_admet)
|
@@ -41,20 +35,6 @@ def analyze_smiles(file):
|
|
41 |
excel_data = excel_buffer.getvalue()
|
42 |
excel_b64 = base64.b64encode(excel_data).decode()
|
43 |
|
44 |
-
# Plot image
|
45 |
-
plot_df = final_df.dropna(subset=["LogP"])
|
46 |
-
plt.figure(figsize=(10, 6))
|
47 |
-
plt.barh(plot_df["SMILES"], plot_df["LogP"], color="skyblue")
|
48 |
-
plt.xlabel("LogP (Lipophilicity)")
|
49 |
-
plt.title("LogP per SMILES")
|
50 |
-
plt.gca().invert_yaxis()
|
51 |
-
plt.tight_layout()
|
52 |
-
img_buffer = io.BytesIO()
|
53 |
-
plt.savefig(img_buffer, format="png")
|
54 |
-
img_buffer.seek(0)
|
55 |
-
img_b64 = base64.b64encode(img_buffer.read()).decode()
|
56 |
-
plt.close()
|
57 |
-
|
58 |
# Markdown table
|
59 |
table_md = final_df.to_markdown(index=False)
|
60 |
|
@@ -62,25 +42,23 @@ def analyze_smiles(file):
|
|
62 |
"✅ التحليل ناجح!",
|
63 |
table_md,
|
64 |
f'<a download="ADMET_Analysis.xlsx" href="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,{excel_b64}">⬇️ تحميل ملف Excel</a>',
|
65 |
-
f'<img src="data:image/png;base64,{img_b64}" width="600"/>'
|
66 |
)
|
67 |
|
68 |
except Exception as e:
|
69 |
-
return f"❌ خطأ أثناء المعالجة: {str(e)}", "", ""
|
70 |
|
71 |
# واجهة Gradio
|
72 |
with gr.Blocks() as demo:
|
73 |
-
gr.Markdown("## 🧪 تحليل ADMET من
|
74 |
|
75 |
with gr.Row():
|
76 |
-
smiles_file = gr.File(label="📄 ارفع ملف .txt يحتوي على SMILES"
|
77 |
run_btn = gr.Button("🚀 تحليل ADMET")
|
78 |
|
79 |
status = gr.Textbox(label="📢 الحالة")
|
80 |
table = gr.Textbox(label="📊 جدول النتائج (Markdown)", lines=12)
|
81 |
download = gr.HTML()
|
82 |
-
image = gr.HTML()
|
83 |
|
84 |
-
run_btn.click(fn=analyze_smiles, inputs=[smiles_file], outputs=[status, table, download
|
85 |
|
86 |
demo.launch()
|
|
|
2 |
from rdkit import Chem
|
3 |
from rdkit.Chem import Descriptors
|
4 |
import pandas as pd
|
|
|
5 |
import io
|
6 |
import base64
|
|
|
7 |
|
8 |
+
# تحليل ADMET
|
9 |
def get_admet(smiles):
|
10 |
mol = Chem.MolFromSmiles(smiles)
|
11 |
if not mol:
|
|
|
23 |
# المعالجة الرئيسية
|
24 |
def analyze_smiles(file):
|
25 |
try:
|
26 |
+
content = file.read().decode("utf-8")
|
|
|
|
|
|
|
|
|
27 |
smiles_list = [line.strip() for line in content.splitlines() if line.strip()]
|
28 |
df = pd.DataFrame({"SMILES": smiles_list})
|
29 |
admet_df = df["SMILES"].apply(get_admet)
|
|
|
35 |
excel_data = excel_buffer.getvalue()
|
36 |
excel_b64 = base64.b64encode(excel_data).decode()
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
# Markdown table
|
39 |
table_md = final_df.to_markdown(index=False)
|
40 |
|
|
|
42 |
"✅ التحليل ناجح!",
|
43 |
table_md,
|
44 |
f'<a download="ADMET_Analysis.xlsx" href="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,{excel_b64}">⬇️ تحميل ملف Excel</a>',
|
|
|
45 |
)
|
46 |
|
47 |
except Exception as e:
|
48 |
+
return f"❌ خطأ أثناء المعالجة: {str(e)}", "", ""
|
49 |
|
50 |
# واجهة Gradio
|
51 |
with gr.Blocks() as demo:
|
52 |
+
gr.Markdown("## 🧪 تحليل ADMET من قائمة SMILES")
|
53 |
|
54 |
with gr.Row():
|
55 |
+
smiles_file = gr.File(label="📄 ارفع ملف .txt يحتوي على SMILES")
|
56 |
run_btn = gr.Button("🚀 تحليل ADMET")
|
57 |
|
58 |
status = gr.Textbox(label="📢 الحالة")
|
59 |
table = gr.Textbox(label="📊 جدول النتائج (Markdown)", lines=12)
|
60 |
download = gr.HTML()
|
|
|
61 |
|
62 |
+
run_btn.click(fn=analyze_smiles, inputs=[smiles_file], outputs=[status, table, download])
|
63 |
|
64 |
demo.launch()
|