Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
add example for enhance image
  • Loading branch information
mrhan1993 committed Aug 15, 2024
1 parent 76a87df commit c64d672
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
>
> Additionally, `groundingdino-py` may encounter installation errors, especially in Chinese Windows environments. The solution can be found in the following [issue](https://github.com/IDEA-Research/GroundingDINO/issues/206).

> GenerateMask is same as DescribeImage, It is not process as a task, result will directly return
# Instructions for Using the ImageEnhance Interface
Below are examples of parameters that include the main parameters required for ImageEnhance. The V1 interface adopts a form-like approach similar to ImagePrompt to break down the enhance controller.

Expand Down
2 changes: 2 additions & 0 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
>
> 此外, `groundingdino-py` 可能会遇到安装错误, 特别是在中文 windows 环境中, 解决办法参考: [issues](https://github.com/IDEA-Research/GroundingDINO/issues/206)
> 和 DescribeImage 一样,GenerateMask 不会作为 task 处理而是直接返回结果
# ImageEnhance 接口的使用说明

以下面的参数为例,它包含了 ImageEnhance 所需要的主要参数,V1 接口采用和 ImagePrompt 类似的方式将 enhance 控制器拆分成表单形式:
Expand Down
36 changes: 36 additions & 0 deletions examples/examples_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,39 @@ def image_prompt(
cn_img2=ImageList.image_prompt_1,
)
print(json.dumps(ip_result))

# ###############################################################
# Image Enhance
# ################################################################

# Image Enhance

import requests

url = "http://localhost:8888/v1/generation/image-enhance"

# Define the file path and other form data
file_path = "./examples/imgs/source_face_man.png"
form_data = {
"enhance_checkbox": True,
"enhance_uov_method": "Disabled",
"enhance_enabled_1": True,
"enhance_mask_dino_prompt_1": "face",
"enhance_enabled_2": True,
"enhance_mask_dino_prompt_2": "eyes",
}

# Open the file and prepare it for the request
with open(file_path, "rb") as f:
image = f.read()
f.close()

# Send the request
response = requests.post(
url,
files={"enhance_input_image": image},
data=form_data,
timeout=180)

# Print the response content
print(response.text)
56 changes: 56 additions & 0 deletions examples/examples_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,59 @@ def text2image_image_prompt(params: dict) -> dict:

t2i_ip_result = text2image_image_prompt(params=t2i_ip_params)
print(json.dumps(t2i_ip_result))

# ################################################################
# Image Enhance
# ################################################################

# Image Enhance

import requests
import json

url = "http://localhost:8888/v2/generation/image-enhance"

headers = {
"Content-Type": "application/json"
}

data = {
"enhance_input_image": "https://raw.githubusercontent.com/mrhan1993/Fooocus-API/main/examples/imgs/source_face_man.png",
"enhance_checkbox": True,
"enhance_uov_method": "Vary (Strong)",
"enhance_uov_processing_order": "Before First Enhancement",
"enhance_uov_prompt_type": "Original Prompts",
"enhance_ctrlnets": [
{
"enhance_enabled": True,
"enhance_mask_dino_prompt": "face",
"enhance_prompt": "",
"enhance_negative_prompt": "",
"enhance_mask_model": "sam",
"enhance_mask_cloth_category": "full",
"enhance_mask_sam_model": "vit_b",
"enhance_mask_text_threshold": 0.25,
"enhance_mask_box_threshold": 0.3,
"enhance_mask_sam_max_detections": 0,
"enhance_inpaint_disable_initial_latent": False,
"enhance_inpaint_engine": "v2.6",
"enhance_inpaint_strength": 1.0,
"enhance_inpaint_respective_field": 0.618,
"enhance_inpaint_erode_or_dilate": 0.0,
"enhance_mask_invert": False
}
]
}

response = requests.post(
url,
headers=headers,
data=json.dumps(data),
timeout=180)

if response.status_code == 200:
print("Request successful!")
print("Response:", response.json())
else:
print("Request failed with status code:", response.status_code)
print("Response:", response.text)

0 comments on commit c64d672

Please sign in to comment.