File size: 3,811 Bytes
0fc970e
 
c43755d
0fc970e
 
 
b32a57f
636d008
0fc970e
 
 
 
 
bddcd79
 
 
 
 
 
 
 
 
 
 
 
 
ec9fa05
 
 
 
 
 
 
 
bddcd79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5bf7c30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bddcd79
5bf7c30
 
 
 
 
 
 
 
 
 
 
 
bddcd79
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
---
title: BrushNet
emoji: 
colorFrom: yellow
colorTo: indigo
sdk: gradio
sdk_version: 3.50.2
python_version: 3.9
app_file: app.py
pinned: false
license: apache-2.0
---

# BrushNetApi

This repo implements an API that allows other applications to call it with http request.

## Instructions to Run the Application

Create a virtual environment and install dependencies.
```
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```

## Run Honcho to Start all the Services

```
honcho start
```

## Or Run the Redis, Celery and Web Server in seperate tabs

Start Redis Server
```
redis-server
```

Start the Celery Worker
```
# In a new terminal window:
./start_celery_worker.sh
```

Run the FastAPI Application
```
# In a new terminal window:
uvicorn app_api:app --host 0.0.0.0 --port 8000
```

## How to Use the API

a. Initiate Image Generation

Send a POST request to /inpaint with the required parameters.

Request Body
```
{
  "input_image": "<base64-encoded input image>",
  "input_mask": "<base64-encoded input mask>",
  "prompt": "A beautiful cake on the table",
  "negative_prompt": "ugly, low quality",
  "control_strength": 1.0,
  "guidance_scale": 12.0,
  "num_inference_steps": 50,
  "seed": 551793204,
  "randomize_seed": false,
  "blended": false,
  "invert_mask": true,
  "count": 1,
  "webhook_url": "http://your-webhook-url.com/notify"  # Optional
}
```
Response
```
{
  "job_id": "<task_id>"
}
```

b. Check Task Status

Send a GET request to /status/{job_id}.

Response
```
{
  "status": "PENDING"  # Or "STARTED", "SUCCESS", "FAILURE"
}
```

c. Retrieve Result

Once the status is “SUCCESS”, send a GET request to /result/{job_id}.

Response:
```
{
  "images": ["<base64-encoded image>", "..."]
}
```

d. Webhook Notification

If you provided a webhook_url in your request, the server will send a POST request to that URL with the images once the task is complete.

```
{
  "images": ["<base64-encoded image>", "..."]
}
```

The webhook functionality is included in the generate_image_task function. If a webhook_url is provided in the request, the server will send a POST request to that URL with the generated images.




# BrushNet(original README below )

This repository contains the gradio demo of the paper "BrushNet: A Plug-and-Play Image Inpainting Model with Decomposed Dual-Branch Diffusion"

Keywords: Image Inpainting, Diffusion Models, Image Generation

> [Xuan Ju](https://github.com/juxuan27)<sup>12</sup>, [Xian Liu](https://alvinliu0.github.io/)<sup>12</sup>, [Xintao Wang](https://xinntao.github.io/)<sup>1*</sup>, [Yuxuan Bian](https://scholar.google.com.hk/citations?user=HzemVzoAAAAJ&hl=zh-CN&oi=ao)<sup>2</sup>, [Ying Shan](https://www.linkedin.com/in/YingShanProfile/)<sup>1</sup>, [Qiang Xu](https://cure-lab.github.io/)<sup>2*</sup><br>
> <sup>1</sup>ARC Lab, Tencent PCG <sup>2</sup>The Chinese University of Hong Kong <sup>*</sup>Corresponding Author


<p align="center">
  <a href="https://tencentarc.github.io/BrushNet/">Project Page</a> |
  <a href="https://github.com/TencentARC/BrushNet">Code</a> |
  <a href="https://arxiv.org/abs/2403.06976">Arxiv</a> |
  <a href="https://forms.gle/9TgMZ8tm49UYsZ9s5">Data</a> |
  <a href="https://drive.google.com/file/d/1IkEBWcd2Fui2WHcckap4QFPcCI0gkHBh/view">Video</a> |
</p>


## 🤝🏼 Cite Us

```
@misc{ju2024brushnet,
  title={BrushNet: A Plug-and-Play Image Inpainting Model with Decomposed Dual-Branch Diffusion},
  author={Xuan Ju and Xian Liu and Xintao Wang and Yuxuan Bian and Ying Shan and Qiang Xu},
  year={2024},
  eprint={2403.06976},
  archivePrefix={arXiv},
  primaryClass={cs.CV}
}
```


## 💖 Acknowledgement
<span id="acknowledgement"></span>

Our code is modified based on [diffusers](https://github.com/huggingface/diffusers), thanks to all the contributors!