File size: 6,616 Bytes
1e15feb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6a7a5d41-e6d7-4efa-a481-3182963ca888",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting gradio_client\n",
      "  Downloading gradio_client-1.3.0-py3-none-any.whl.metadata (7.1 kB)\n",
      "Requirement already satisfied: fsspec in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from gradio_client) (2024.6.1)\n",
      "Requirement already satisfied: httpx>=0.24.1 in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from gradio_client) (0.27.0)\n",
      "Collecting huggingface-hub>=0.19.3 (from gradio_client)\n",
      "  Downloading huggingface_hub-0.24.7-py3-none-any.whl.metadata (13 kB)\n",
      "Requirement already satisfied: packaging in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from gradio_client) (24.1)\n",
      "Requirement already satisfied: typing-extensions~=4.0 in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from gradio_client) (4.12.2)\n",
      "Requirement already satisfied: websockets<13.0,>=10.0 in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from gradio_client) (12.0)\n",
      "Requirement already satisfied: anyio in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from httpx>=0.24.1->gradio_client) (4.4.0)\n",
      "Requirement already satisfied: certifi in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from httpx>=0.24.1->gradio_client) (2024.7.4)\n",
      "Requirement already satisfied: httpcore==1.* in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from httpx>=0.24.1->gradio_client) (1.0.5)\n",
      "Requirement already satisfied: idna in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from httpx>=0.24.1->gradio_client) (3.7)\n",
      "Requirement already satisfied: sniffio in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from httpx>=0.24.1->gradio_client) (1.3.1)\n",
      "Requirement already satisfied: h11<0.15,>=0.13 in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from httpcore==1.*->httpx>=0.24.1->gradio_client) (0.14.0)\n",
      "Requirement already satisfied: filelock in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from huggingface-hub>=0.19.3->gradio_client) (3.15.4)\n",
      "Requirement already satisfied: pyyaml>=5.1 in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from huggingface-hub>=0.19.3->gradio_client) (6.0.1)\n",
      "Requirement already satisfied: requests in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from huggingface-hub>=0.19.3->gradio_client) (2.32.3)\n",
      "Requirement already satisfied: tqdm>=4.42.1 in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from huggingface-hub>=0.19.3->gradio_client) (4.66.5)\n",
      "Requirement already satisfied: exceptiongroup>=1.0.2 in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from anyio->httpx>=0.24.1->gradio_client) (1.2.2)\n",
      "Requirement already satisfied: charset-normalizer<4,>=2 in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from requests->huggingface-hub>=0.19.3->gradio_client) (3.3.2)\n",
      "Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from requests->huggingface-hub>=0.19.3->gradio_client) (2.2.2)\n",
      "Downloading gradio_client-1.3.0-py3-none-any.whl (318 kB)\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m318.7/318.7 kB\u001b[0m \u001b[31m3.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n",
      "\u001b[?25hDownloading huggingface_hub-0.24.7-py3-none-any.whl (417 kB)\n",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m417.5/417.5 kB\u001b[0m \u001b[31m11.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[?25hInstalling collected packages: huggingface-hub, gradio_client\n",
      "Successfully installed gradio_client-1.3.0 huggingface-hub-0.24.7\n"
     ]
    }
   ],
   "source": [
    "!pip install gradio_client"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "2c0171fa-ee2a-40b7-8578-aa8516b4ece9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Loaded as API: http://localhost:7860/ βœ”\n",
      "/private/var/folders/tt/x223wxwj6dzg3vjjgc_6y5bm0000gn/T/gradio/328e454ac0bf982b2abd88177da33ef6158d0cd32809949938608b942a6aa743/gradio.pdb 1.3538727760314941\n"
     ]
    }
   ],
   "source": [
    "from gradio_client import Client, handle_file\n",
    "from pathlib import Path\n",
    "\n",
    "client = Client(\"http://localhost:7860/\")\n",
    "result = client.predict(\n",
    "\t\treceptor_pdb=handle_file('./8i5w_R.pdb'),\n",
    "\t\tligand_pdb=handle_file('./8i5w_L.pdb'),\n",
    "\t\treceptor_fasta=None,\n",
    "\t\tligand_fasta=None,\n",
    "\t\tapi_name=\"/predict\"\n",
    ")\n",
    "output_pdb, runtime = Path(result[0]), result[1]\n",
    "print(output_pdb, runtime)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "c530fde1-7f57-4991-a53e-b3855657f9fc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(PosixPath('pinder-inference-outputs/gradio.pdb'), True)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import shutil\n",
    "\n",
    "local_dir = Path(\"./pinder-inference-outputs\")\n",
    "local_dir.mkdir(exist_ok=True, parents=True)\n",
    "\n",
    "output_pdb = Path(shutil.copy(output_pdb, local_dir))\n",
    "output_pdb, output_pdb.is_file() \n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "pinder",
   "language": "python",
   "name": "pinder"
  },
  "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.10.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}