From d939fe1103d38f1ac55e8da3cd789f3b4f090799 Mon Sep 17 00:00:00 2001 From: Chengsong Zhang Date: Sat, 29 Apr 2023 06:53:41 +0800 Subject: [PATCH] remove api doc in readme --- README.md | 49 ------------------------------------------------- 1 file changed, 49 deletions(-) diff --git a/README.md b/README.md index 862bafa..7fcc898 100644 --- a/README.md +++ b/README.md @@ -179,55 +179,6 @@ Mask by Category batch demo | --- | --- | --- | --- | | ![1NHa6Wc](https://user-images.githubusercontent.com/63914308/234085498-70ca1d4c-cc5a-44d4-adb2-366630e5ce24.png) | ![1NHa6Wc_0_output](https://user-images.githubusercontent.com/63914308/234085495-0bfc4114-3e81-4ace-81d6-0f0f3186df25.png) | ![1NHa6Wc_0_mask](https://user-images.githubusercontent.com/63914308/234085491-8976f46c-2617-47ee-968e-0a9dd479c63a.png) | ![1NHa6Wc_0_blend](https://user-images.githubusercontent.com/63914308/234085503-7e041373-39cd-4f20-8696-986be517f188.png) -## API Support - -### API Usage - -We have added an API endpoint to allow for automated workflows. - -The API utilizes both Segment Anything and GroundingDINO to return masks of all instances of whatever object is specified in the text prompt. - -This is an extension of the existing [Stable Diffusion WebUI API](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/API). - -There are 2 endpoints exposed -- GET `/sam-webui/heartbeat` -- POST `/sam-webui/image-mask` - -The heartbeat endpoint can be used to ensure that the API is up. - -The image-mask endpoint accepts a payload that includes your base64-encoded image. - -Below is an example of how to interface with the API using requests. - -### API Example - -``` -import base64 -import requests -from PIL import Image -from io import BytesIO - -url = "http://127.0.0.1:7860/sam-webui/image-mask" - -def image_to_base64(img_path: str) -> str: - with open(img_path, "rb") as img_file: - img_base64 = base64.b64encode(img_file.read()).decode() - return img_base64 - -payload = { - "image": image_to_base64("IMAGE_FILE_PATH"), - "prompt": "TEXT PROMPT", - "box_threshold": 0.3, - "padding": 30 #Optional param to pad masks -} -res = requests.post(url, json=payload) - -for dct in res.json(): - image_data = base64.b64decode(dct['image']) - image = Image.open(BytesIO(image_data)) - image.show() -``` - ## Contribute Disclaimer: I have not thoroughly tested this extension, so there might be bugs. Bear with me while I'm fixing them :)