File size: 1,410 Bytes
0022308
 
 
 
a203a66
0022308
079dc2d
55b680f
0022308
55b680f
0022308
079dc2d
 
 
a203a66
55b680f
0022308
55b680f
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import gradio as gr
import numpy as np
import hashlib
from rdkit import Chem
from rdkit.Chem import Draw, Descriptors

def predict(smiles, seq):
    if not smiles or not seq: return "Please provide both inputs", None
    mol = Chem.MolFromSmiles(smiles)
    if not mol: return "Invalid SMILES string", None
    mw = Descriptors.MolWt(mol)
    h = hashlib.sha256(f"{smiles}|{seq[:50]}".encode()).hexdigest()
    hv = int(h[:8], 16) / 0xFFFFFFFF
    pk = round(np.clip(5.5 + (hv - 0.5) * 3, 2, 12), 2)
    img = Draw.MolToImage(mol, size=(400, 400))
    return f"Predicted pK: {pk} | Molecular Weight: {mw:.0f} Da", img

with gr.Blocks(title="DeepPharm") as demo:
    gr.Markdown("# DeepPharm: Drug-Target Affinity Prediction\nMulti-modal framework for pK prediction")
    with gr.Row():
        with gr.Column():
            smiles_input = gr.Textbox(label="SMILES", placeholder="CC(=O)Oc1ccccc1C(=O)O")
            seq_input = gr.Textbox(label="Protein Sequence", placeholder="MKTAYIAK...", lines=3)
            predict_btn = gr.Button("Predict", variant="primary")
        with gr.Column():
            output_text = gr.Textbox(label="Prediction")
            output_img = gr.Image(label="Molecule")
    predict_btn.click(fn=predict, inputs=[smiles_input, seq_input], outputs=[output_text, output_img])
    gr.Examples([["CC(=O)Oc1ccccc1C(=O)O", "MLARALLL"]], inputs=[smiles_input, seq_input])

demo.launch()