Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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(
|
26 |
try:
|
27 |
-
# قراءة محتوى الملف
|
28 |
-
content =
|
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 |
-
#
|
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 |
-
# رسم
|
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 |
-
#
|
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=
|
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 |
)
|