danielkovtun commited on
Commit
1e15feb
Β·
1 Parent(s): 70c766d

feat: add example notebook for using predict endpoint w/local docker container

Browse files
Files changed (1) hide show
  1. inference-api-dev-template.ipynb +129 -0
inference-api-dev-template.ipynb ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "6a7a5d41-e6d7-4efa-a481-3182963ca888",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stdout",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "Collecting gradio_client\n",
14
+ " Downloading gradio_client-1.3.0-py3-none-any.whl.metadata (7.1 kB)\n",
15
+ "Requirement already satisfied: fsspec in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from gradio_client) (2024.6.1)\n",
16
+ "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",
17
+ "Collecting huggingface-hub>=0.19.3 (from gradio_client)\n",
18
+ " Downloading huggingface_hub-0.24.7-py3-none-any.whl.metadata (13 kB)\n",
19
+ "Requirement already satisfied: packaging in /Users/danielkovtun/mamba-m1/envs/pinder/lib/python3.10/site-packages (from gradio_client) (24.1)\n",
20
+ "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",
21
+ "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",
22
+ "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",
23
+ "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",
24
+ "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",
25
+ "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",
26
+ "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",
27
+ "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",
28
+ "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",
29
+ "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",
30
+ "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",
31
+ "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",
32
+ "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",
33
+ "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",
34
+ "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",
35
+ "Downloading gradio_client-1.3.0-py3-none-any.whl (318 kB)\n",
36
+ "\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",
37
+ "\u001b[?25hDownloading huggingface_hub-0.24.7-py3-none-any.whl (417 kB)\n",
38
+ "\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",
39
+ "\u001b[?25hInstalling collected packages: huggingface-hub, gradio_client\n",
40
+ "Successfully installed gradio_client-1.3.0 huggingface-hub-0.24.7\n"
41
+ ]
42
+ }
43
+ ],
44
+ "source": [
45
+ "!pip install gradio_client"
46
+ ]
47
+ },
48
+ {
49
+ "cell_type": "code",
50
+ "execution_count": 5,
51
+ "id": "2c0171fa-ee2a-40b7-8578-aa8516b4ece9",
52
+ "metadata": {},
53
+ "outputs": [
54
+ {
55
+ "name": "stdout",
56
+ "output_type": "stream",
57
+ "text": [
58
+ "Loaded as API: http://localhost:7860/ βœ”\n",
59
+ "/private/var/folders/tt/x223wxwj6dzg3vjjgc_6y5bm0000gn/T/gradio/328e454ac0bf982b2abd88177da33ef6158d0cd32809949938608b942a6aa743/gradio.pdb 1.3538727760314941\n"
60
+ ]
61
+ }
62
+ ],
63
+ "source": [
64
+ "from gradio_client import Client, handle_file\n",
65
+ "from pathlib import Path\n",
66
+ "\n",
67
+ "client = Client(\"http://localhost:7860/\")\n",
68
+ "result = client.predict(\n",
69
+ "\t\treceptor_pdb=handle_file('./8i5w_R.pdb'),\n",
70
+ "\t\tligand_pdb=handle_file('./8i5w_L.pdb'),\n",
71
+ "\t\treceptor_fasta=None,\n",
72
+ "\t\tligand_fasta=None,\n",
73
+ "\t\tapi_name=\"/predict\"\n",
74
+ ")\n",
75
+ "output_pdb, runtime = Path(result[0]), result[1]\n",
76
+ "print(output_pdb, runtime)\n"
77
+ ]
78
+ },
79
+ {
80
+ "cell_type": "code",
81
+ "execution_count": 6,
82
+ "id": "c530fde1-7f57-4991-a53e-b3855657f9fc",
83
+ "metadata": {},
84
+ "outputs": [
85
+ {
86
+ "data": {
87
+ "text/plain": [
88
+ "(PosixPath('pinder-inference-outputs/gradio.pdb'), True)"
89
+ ]
90
+ },
91
+ "execution_count": 6,
92
+ "metadata": {},
93
+ "output_type": "execute_result"
94
+ }
95
+ ],
96
+ "source": [
97
+ "import shutil\n",
98
+ "\n",
99
+ "local_dir = Path(\"./pinder-inference-outputs\")\n",
100
+ "local_dir.mkdir(exist_ok=True, parents=True)\n",
101
+ "\n",
102
+ "output_pdb = Path(shutil.copy(output_pdb, local_dir))\n",
103
+ "output_pdb, output_pdb.is_file() \n",
104
+ "\n"
105
+ ]
106
+ }
107
+ ],
108
+ "metadata": {
109
+ "kernelspec": {
110
+ "display_name": "pinder",
111
+ "language": "python",
112
+ "name": "pinder"
113
+ },
114
+ "language_info": {
115
+ "codemirror_mode": {
116
+ "name": "ipython",
117
+ "version": 3
118
+ },
119
+ "file_extension": ".py",
120
+ "mimetype": "text/x-python",
121
+ "name": "python",
122
+ "nbconvert_exporter": "python",
123
+ "pygments_lexer": "ipython3",
124
+ "version": "3.10.14"
125
+ }
126
+ },
127
+ "nbformat": 4,
128
+ "nbformat_minor": 5
129
+ }