Commit ·
c48847e
1
Parent(s): 7d9b175
docs: update nb w/evaluate endpoint example and point to deployed endpoint
Browse files- inference-api-dev-template.ipynb +150 -12
inference-api-dev-template.ipynb
CHANGED
|
@@ -45,9 +45,25 @@
|
|
| 45 |
"!pip install gradio_client"
|
| 46 |
]
|
| 47 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
{
|
| 49 |
"cell_type": "code",
|
| 50 |
-
"execution_count":
|
| 51 |
"id": "2c0171fa-ee2a-40b7-8578-aa8516b4ece9",
|
| 52 |
"metadata": {},
|
| 53 |
"outputs": [
|
|
@@ -55,8 +71,8 @@
|
|
| 55 |
"name": "stdout",
|
| 56 |
"output_type": "stream",
|
| 57 |
"text": [
|
| 58 |
-
"Loaded as API:
|
| 59 |
-
"/private/var/folders/tt/x223wxwj6dzg3vjjgc_6y5bm0000gn/T/gradio/
|
| 60 |
]
|
| 61 |
}
|
| 62 |
],
|
|
@@ -64,13 +80,16 @@
|
|
| 64 |
"from gradio_client import Client, handle_file\n",
|
| 65 |
"from pathlib import Path\n",
|
| 66 |
"\n",
|
| 67 |
-
"
|
|
|
|
|
|
|
|
|
|
| 68 |
"result = client.predict(\n",
|
| 69 |
-
"
|
| 70 |
-
"
|
| 71 |
-
"
|
| 72 |
-
"
|
| 73 |
-
"
|
| 74 |
")\n",
|
| 75 |
"output_pdb, runtime = Path(result[0]), result[1]\n",
|
| 76 |
"print(output_pdb, runtime)\n"
|
|
@@ -78,17 +97,17 @@
|
|
| 78 |
},
|
| 79 |
{
|
| 80 |
"cell_type": "code",
|
| 81 |
-
"execution_count":
|
| 82 |
"id": "c530fde1-7f57-4991-a53e-b3855657f9fc",
|
| 83 |
"metadata": {},
|
| 84 |
"outputs": [
|
| 85 |
{
|
| 86 |
"data": {
|
| 87 |
"text/plain": [
|
| 88 |
-
"(PosixPath('pinder-inference-outputs/
|
| 89 |
]
|
| 90 |
},
|
| 91 |
-
"execution_count":
|
| 92 |
"metadata": {},
|
| 93 |
"output_type": "execute_result"
|
| 94 |
}
|
|
@@ -103,6 +122,125 @@
|
|
| 103 |
"output_pdb, output_pdb.is_file() \n",
|
| 104 |
"\n"
|
| 105 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
}
|
| 107 |
],
|
| 108 |
"metadata": {
|
|
|
|
| 45 |
"!pip install gradio_client"
|
| 46 |
]
|
| 47 |
},
|
| 48 |
+
{
|
| 49 |
+
"cell_type": "markdown",
|
| 50 |
+
"id": "549b9b2c-3074-446b-962e-90c8efd2bd59",
|
| 51 |
+
"metadata": {},
|
| 52 |
+
"source": [
|
| 53 |
+
"# PINDER inference and evaluation template API examples"
|
| 54 |
+
]
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"cell_type": "markdown",
|
| 58 |
+
"id": "b979671e-97d6-4c52-bc6e-279a09d722c8",
|
| 59 |
+
"metadata": {},
|
| 60 |
+
"source": [
|
| 61 |
+
"## Run inference via predict endpoint"
|
| 62 |
+
]
|
| 63 |
+
},
|
| 64 |
{
|
| 65 |
"cell_type": "code",
|
| 66 |
+
"execution_count": 10,
|
| 67 |
"id": "2c0171fa-ee2a-40b7-8578-aa8516b4ece9",
|
| 68 |
"metadata": {},
|
| 69 |
"outputs": [
|
|
|
|
| 71 |
"name": "stdout",
|
| 72 |
"output_type": "stream",
|
| 73 |
"text": [
|
| 74 |
+
"Loaded as API: https://danielkovtun-pinder-inference-template.hf.space/ ✔\n",
|
| 75 |
+
"/private/var/folders/tt/x223wxwj6dzg3vjjgc_6y5bm0000gn/T/gradio/0cda59c2805986a9e5956ed00cb552b3c86f05915da91e6e14a0a31b962e664b/3g9w_R--3g9w_L.pdb 1.2273471355438232\n"
|
| 76 |
]
|
| 77 |
}
|
| 78 |
],
|
|
|
|
| 80 |
"from gradio_client import Client, handle_file\n",
|
| 81 |
"from pathlib import Path\n",
|
| 82 |
"\n",
|
| 83 |
+
"uri = \"https://danielkovtun-pinder-inference-template.hf.space/\"\n",
|
| 84 |
+
"# If running docker container locally\n",
|
| 85 |
+
"dev_uri = \"http://localhost:7860/\"\n",
|
| 86 |
+
"client = Client(uri)\n",
|
| 87 |
"result = client.predict(\n",
|
| 88 |
+
" receptor_pdb=handle_file(\"./3g9w_R.pdb\"),\n",
|
| 89 |
+
" ligand_pdb=handle_file(\"./3g9w_L.pdb\"),\n",
|
| 90 |
+
" receptor_fasta=None, # optional in this implementation\n",
|
| 91 |
+
" ligand_fasta=None,\n",
|
| 92 |
+
" api_name=\"/predict\"\n",
|
| 93 |
")\n",
|
| 94 |
"output_pdb, runtime = Path(result[0]), result[1]\n",
|
| 95 |
"print(output_pdb, runtime)\n"
|
|
|
|
| 97 |
},
|
| 98 |
{
|
| 99 |
"cell_type": "code",
|
| 100 |
+
"execution_count": 11,
|
| 101 |
"id": "c530fde1-7f57-4991-a53e-b3855657f9fc",
|
| 102 |
"metadata": {},
|
| 103 |
"outputs": [
|
| 104 |
{
|
| 105 |
"data": {
|
| 106 |
"text/plain": [
|
| 107 |
+
"(PosixPath('pinder-inference-outputs/3g9w_R--3g9w_L.pdb'), True)"
|
| 108 |
]
|
| 109 |
},
|
| 110 |
+
"execution_count": 11,
|
| 111 |
"metadata": {},
|
| 112 |
"output_type": "execute_result"
|
| 113 |
}
|
|
|
|
| 122 |
"output_pdb, output_pdb.is_file() \n",
|
| 123 |
"\n"
|
| 124 |
]
|
| 125 |
+
},
|
| 126 |
+
{
|
| 127 |
+
"cell_type": "markdown",
|
| 128 |
+
"id": "b3c1c03e-74c1-4010-b385-e4366d43cd6f",
|
| 129 |
+
"metadata": {},
|
| 130 |
+
"source": [
|
| 131 |
+
"## Fetch evaluation metrics via evaluate endpoint"
|
| 132 |
+
]
|
| 133 |
+
},
|
| 134 |
+
{
|
| 135 |
+
"cell_type": "code",
|
| 136 |
+
"execution_count": 13,
|
| 137 |
+
"id": "e5e26250-f20d-484d-84e2-320cdfef830a",
|
| 138 |
+
"metadata": {},
|
| 139 |
+
"outputs": [
|
| 140 |
+
{
|
| 141 |
+
"name": "stdout",
|
| 142 |
+
"output_type": "stream",
|
| 143 |
+
"text": [
|
| 144 |
+
"Loaded as API: http://localhost:7860/ ✔\n"
|
| 145 |
+
]
|
| 146 |
+
},
|
| 147 |
+
{
|
| 148 |
+
"data": {
|
| 149 |
+
"text/plain": [
|
| 150 |
+
"{'headers': ['system', 'L_rms', 'I_rms', 'F_nat', 'DOCKQ', 'CAPRI_class'],\n",
|
| 151 |
+
" 'data': [['3g9w__A1_Q71LX4--3g9w__D1_P05556',\n",
|
| 152 |
+
" 34.781349182128906,\n",
|
| 153 |
+
" 15.405366897583008,\n",
|
| 154 |
+
" 0.0,\n",
|
| 155 |
+
" 0.021916405918697517,\n",
|
| 156 |
+
" 'Incorrect']],\n",
|
| 157 |
+
" 'metadata': None}"
|
| 158 |
+
]
|
| 159 |
+
},
|
| 160 |
+
"execution_count": 13,
|
| 161 |
+
"metadata": {},
|
| 162 |
+
"output_type": "execute_result"
|
| 163 |
+
}
|
| 164 |
+
],
|
| 165 |
+
"source": [
|
| 166 |
+
"client = Client(uri)\n",
|
| 167 |
+
"result = client.predict(\n",
|
| 168 |
+
" system_id=\"3g9w__A1_Q71LX4--3g9w__D1_P05556\",\n",
|
| 169 |
+
" prediction_pdb=handle_file(\"3g9w_R--3g9w_L.pdb\"),\n",
|
| 170 |
+
" api_name=\"/evaluate\"\n",
|
| 171 |
+
")\n",
|
| 172 |
+
"metrics, pred_native, runtime = result\n",
|
| 173 |
+
"metrics"
|
| 174 |
+
]
|
| 175 |
+
},
|
| 176 |
+
{
|
| 177 |
+
"cell_type": "code",
|
| 178 |
+
"execution_count": 14,
|
| 179 |
+
"id": "eef0d108-5d76-4bef-bd0c-4952d433ccaf",
|
| 180 |
+
"metadata": {},
|
| 181 |
+
"outputs": [
|
| 182 |
+
{
|
| 183 |
+
"data": {
|
| 184 |
+
"text/html": [
|
| 185 |
+
"<div>\n",
|
| 186 |
+
"<style scoped>\n",
|
| 187 |
+
" .dataframe tbody tr th:only-of-type {\n",
|
| 188 |
+
" vertical-align: middle;\n",
|
| 189 |
+
" }\n",
|
| 190 |
+
"\n",
|
| 191 |
+
" .dataframe tbody tr th {\n",
|
| 192 |
+
" vertical-align: top;\n",
|
| 193 |
+
" }\n",
|
| 194 |
+
"\n",
|
| 195 |
+
" .dataframe thead th {\n",
|
| 196 |
+
" text-align: right;\n",
|
| 197 |
+
" }\n",
|
| 198 |
+
"</style>\n",
|
| 199 |
+
"<table border=\"1\" class=\"dataframe\">\n",
|
| 200 |
+
" <thead>\n",
|
| 201 |
+
" <tr style=\"text-align: right;\">\n",
|
| 202 |
+
" <th></th>\n",
|
| 203 |
+
" <th>system</th>\n",
|
| 204 |
+
" <th>L_rms</th>\n",
|
| 205 |
+
" <th>I_rms</th>\n",
|
| 206 |
+
" <th>F_nat</th>\n",
|
| 207 |
+
" <th>DOCKQ</th>\n",
|
| 208 |
+
" <th>CAPRI_class</th>\n",
|
| 209 |
+
" </tr>\n",
|
| 210 |
+
" </thead>\n",
|
| 211 |
+
" <tbody>\n",
|
| 212 |
+
" <tr>\n",
|
| 213 |
+
" <th>0</th>\n",
|
| 214 |
+
" <td>3g9w__A1_Q71LX4--3g9w__D1_P05556</td>\n",
|
| 215 |
+
" <td>34.781349</td>\n",
|
| 216 |
+
" <td>15.405367</td>\n",
|
| 217 |
+
" <td>0.0</td>\n",
|
| 218 |
+
" <td>0.021916</td>\n",
|
| 219 |
+
" <td>Incorrect</td>\n",
|
| 220 |
+
" </tr>\n",
|
| 221 |
+
" </tbody>\n",
|
| 222 |
+
"</table>\n",
|
| 223 |
+
"</div>"
|
| 224 |
+
],
|
| 225 |
+
"text/plain": [
|
| 226 |
+
" system L_rms I_rms F_nat DOCKQ \\\n",
|
| 227 |
+
"0 3g9w__A1_Q71LX4--3g9w__D1_P05556 34.781349 15.405367 0.0 0.021916 \n",
|
| 228 |
+
"\n",
|
| 229 |
+
" CAPRI_class \n",
|
| 230 |
+
"0 Incorrect "
|
| 231 |
+
]
|
| 232 |
+
},
|
| 233 |
+
"execution_count": 14,
|
| 234 |
+
"metadata": {},
|
| 235 |
+
"output_type": "execute_result"
|
| 236 |
+
}
|
| 237 |
+
],
|
| 238 |
+
"source": [
|
| 239 |
+
"import pandas as pd\n",
|
| 240 |
+
"\n",
|
| 241 |
+
"metric_df = pd.DataFrame(metrics[\"data\"], columns=metrics[\"headers\"])\n",
|
| 242 |
+
"metric_df"
|
| 243 |
+
]
|
| 244 |
}
|
| 245 |
],
|
| 246 |
"metadata": {
|