OwenLegalSign commited on
Commit
1dcc17c
1 Parent(s): 607316b

First commit

Browse files
Files changed (2) hide show
  1. README.md +6 -12
  2. app.py +62 -0
README.md CHANGED
@@ -1,13 +1,7 @@
1
- ---
2
- title: Pharma
3
- emoji: 🏃
4
- colorFrom: blue
5
- colorTo: blue
6
- sdk: streamlit
7
- sdk_version: 1.10.0
8
- app_file: app.py
9
- pinned: false
10
- license: bigscience-openrail-m
11
- ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
1
+ # About
 
 
 
 
 
 
 
 
 
 
2
 
3
+ This app uses the `dpt-moses-ver2` model from Hugging Face to generate drug-like molecules.
4
+
5
+ You can input a SMILES string in the sidebar, and upon submission, the app will generate 20 similar SMILES strings, display them, and provide their similarity to the original input. You can also download the generated SMILES strings.
6
+
7
+ *(WIP)*
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from rdkit import Chem
3
+ from rdkit.Chem import Draw
4
+ import random
5
+
6
+ # 假設的生成 smiles 的 function
7
+
8
+
9
+ def generate_smiles(input_smiles):
10
+ # 這裡應該調用 Hugging Face 模型生成 20 個 SMILES 字串
11
+ # 為了示範,隨機生成 20 個相似的 SMILES
12
+ return [input_smiles + str(random.randint(0, 9)) for _ in range(20)]
13
+
14
+ # 計算相似度的假設 function
15
+
16
+
17
+ def calculate_similarity(smiles1, smiles2):
18
+ # 簡單的示範相似度計算
19
+ return round(random.uniform(0.5, 1.0), 2)
20
+
21
+ # 畫圖的 function
22
+
23
+
24
+ def draw_molecules(smiles_list):
25
+ mols = [Chem.MolFromSmiles(smi) for smi in smiles_list]
26
+ img = Draw.MolsToGridImage(mols, molsPerRow=5, subImgSize=(200, 200))
27
+ return img
28
+
29
+
30
+ st.sidebar.title("SMILES Input")
31
+ input_smiles = st.sidebar.text_input("Enter SMILES string:")
32
+ submit_button = st.sidebar.button("Submit")
33
+
34
+ st.title("(WIP 🚧) Drug-like Molecule Generation")
35
+ st.write("""
36
+ This app uses the `dpt-moses-ver2` model from Hugging Face to generate drug-like molecules.
37
+ You can input a SMILES string in the sidebar, and upon submission, the app will generate 20 similar SMILES strings,
38
+ display them, and provide their similarity to the original input. You can also download the generated SMILES strings.
39
+ """)
40
+
41
+ if submit_button and input_smiles:
42
+ # 生成 20 個 smiles
43
+ generated_smiles = generate_smiles(input_smiles)
44
+
45
+ # 顯示 smiles 和相似度
46
+ st.write("Generated SMILES:")
47
+ for i, smi in enumerate(generated_smiles):
48
+ similarity = calculate_similarity(input_smiles, smi)
49
+ st.write(f"{i + 1}. {smi} (Similarity: {similarity})")
50
+
51
+ # 畫分子圖
52
+ st.image(draw_molecules(generated_smiles),
53
+ caption="Generated Molecules", use_column_width=True)
54
+
55
+ # 下載 smiles 按鈕
56
+ smiles_str = "\n".join(generated_smiles)
57
+ st.download_button(
58
+ label="Download SMILES",
59
+ data=smiles_str,
60
+ file_name='generated_smiles.txt',
61
+ mime='text/plain',
62
+ )