Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
dnth committed Nov 1, 2024
1 parent 33b8b7a commit cad0900
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 37 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,40 @@ xinfer.serve_model(
)
```

You can now query the endpoint with an image and prompt.

```bash
curl -X 'POST' \
'http://127.0.0.1:8000/infer' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"image": "https://raw.githubusercontent.com/dnth/x.infer/refs/heads/main/assets/demo/00aa2580828a9009.jpg",
"infer_kwargs": {"prompt": "Caption this image"}
}'
```

Or in Python:

```python
import requests

url = "http://127.0.0.1:8000/infer"
headers = {
"accept": "application/json",
"Content-Type": "application/json"
}
payload = {
"image": "https://raw.githubusercontent.com/dnth/x.infer/refs/heads/main/assets/demo/00aa2580828a9009.jpg",
"infer_kwargs": {
"prompt": "Caption this image"
}
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())
```

### Add Your Own Model

+ **Step 1:** Create a new model class that implements the `BaseModel` interface.
Expand Down
64 changes: 64 additions & 0 deletions nbs/query.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'response': 'A parade with a marching band and a flag-bearing figure passes through a town, with spectators lining the street and a church steeple visible in the background.'}\n"
]
}
],
"source": [
"import requests\n",
"\n",
"url = \"http://127.0.0.1:8000/infer\"\n",
"headers = {\n",
" \"accept\": \"application/json\",\n",
" \"Content-Type\": \"application/json\"\n",
"}\n",
"payload = {\n",
" \"image\": \"https://raw.githubusercontent.com/dnth/x.infer/refs/heads/main/assets/demo/00aa2580828a9009.jpg\",\n",
" \"infer_kwargs\": {\n",
" \"prompt\": \"Caption this image\"\n",
" }\n",
"}\n",
"\n",
"response = requests.post(url, headers=headers, json=payload)\n",
"print(response.json())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "xinfer",
"language": "python",
"name": "python3"
},
"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.15"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
78 changes: 41 additions & 37 deletions nbs/serving.ipynb

Large diffs are not rendered by default.

0 comments on commit cad0900

Please sign in to comment.