[4717e2]: / DEMO / web_ui_gradio.ipynb

Download this file

90 lines (89 with data), 2.5 kB

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Dataset already downloaded in the local system...\n",
      "Running locally at: http://127.0.0.1:7860/\n",
      "Running on External URL: https://37678.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 0x7fba2f2a2e90>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "(<gradio.networking.serve_files_in_background.<locals>.HTTPServer at 0x7fba2cc15250>,\n",
       " 'http://127.0.0.1:7860/',\n",
       " 'https://37678.gradio.app')"
      ]
     },
     "execution_count": 2,
     "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",
    "model = models.model_pretrained(model = 'MPNN_CNN_BindingDB')\n",
    "\n",
    "def DTI_pred(drug, target):\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.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"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}