[0a9449]: / DEMO / web_ui_gradio_training_datasets.ipynb

Download this file

117 lines (116 with data), 3.5 kB

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Dataset already downloaded in the local system...\n",
      "Downloading finished... Beginning to extract zip file...\n",
      "pretrained model Successfully Downloaded...\n",
      "Downloading finished... Beginning to extract zip file...\n",
      "pretrained model Successfully Downloaded...\n",
      "Running locally at: http://127.0.0.1:7860/\n",
      "Running on External URL: https://50750.gradio.app\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "        <iframe\n",
       "            width=\"1000\"\n",
       "            height=\"500\"\n",
       "            src=\"http://127.0.0.1:7860/\"\n",
       "            frameborder=\"0\"\n",
       "            allowfullscreen\n",
       "        ></iframe>\n",
       "        "
      ],
      "text/plain": [
       "<IPython.lib.display.IFrame at 0x7fdac72df090>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "(<gradio.networking.serve_files_in_background.<locals>.HTTPServer at 0x7fdae2d17e10>,\n",
       " 'http://127.0.0.1:7860/',\n",
       " 'https://50750.gradio.app')"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import os\n",
    "os.chdir('../')\n",
    "from DeepPurpose import utils\n",
    "from DeepPurpose import DTI as models\n",
    "import gradio\n",
    "\n",
    "\n",
    "model_binding = models.model_pretrained(model = 'MPNN_CNN_BindingDB')\n",
    "model_kiba = models.model_pretrained(model = 'MPNN_CNN_KIBA')\n",
    "model_davis = models.model_pretrained(model = 'MPNN_CNN_DAVIS')\n",
    "\n",
    "def DTI_pred(data, drug, target):\n",
    "    if data == 'BindingDB':\n",
    "        model = model_binding\n",
    "    elif data == 'KIBA':\n",
    "        model = model_kiba\n",
    "    elif data == 'DAVIS':\n",
    "        model = model_davis\n",
    "\n",
    "    X_pred = utils.data_process(X_drug = [drug], X_target = [target], y = [0],\n",
    "                                drug_encoding = 'MPNN', target_encoding = 'CNN', \n",
    "                                split_method='no_split')\n",
    "    y_pred = model.predict(X_pred)\n",
    "    return str(y_pred[0])\n",
    "\n",
    "gradio.Interface(DTI_pred, \n",
    "                 [gradio.inputs.Dropdown(label = \"Training Dataset\", choices = ['BindingDB', 'DAVIS', 'KIBA']),\n",
    "                  gradio.inputs.Textbox(lines = 5, label = \"Drug SMILES\"),\n",
    "                  gradio.inputs.Textbox(lines = 5, label = \"Target Amino Acid Sequence\")], \n",
    "                 gradio.outputs.Textbox(label = \"Predicted Affinity\")).launch(share=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:DeepPurpose]",
   "language": "python",
   "name": "conda-env-DeepPurpose-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}