UPDATE: API instruction

+ VersionUP (beta; alpha passed)
This commit is contained in:
Gourieff 2023-08-24 14:09:53 +07:00
parent 6bc53c1501
commit ac78afe904
3 changed files with 80 additions and 8 deletions

71
API.md Normal file
View File

@ -0,0 +1,71 @@
# <div align="center">ReActor Extension API</div>
<div align="center">
[Built-in SD WebUI API](#built-in-sd-webui-api) | [External ReActor API](#external-reactor-api)
---
</div>
Gourieff's **ReActor** SD WebUI Extension allows to operate via API: both built-in and external (POST and GET requests).
## Built-in SD WebUI API
This API is actual if you use Automatic1111 stable-diffusion-webui.
First of all - check the [SD Web API Wiki](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/API) for how to use the API.
* Call `requests.get(url=f'{address}/sdapi/v1/script-info')` to find the args that ReActor needs;
* Define ReActor script args and add like this `"alwayson_scripts": {"reactor":{"args":args}}` in the payload;
* Call the API.
You can find the [full usage example](./example/api_example.py) with all the available parameters and discriptions in the "example" folder.
## External ReActor API
ReActor extension supports for external calls via POST or GET requests while your SD WebUI server is working.
> :warning: Source and Target images must be "base64".
Example:
```
curl -X POST \
'http://127.0.0.1:7860/reactor/image' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"source_image": "data:image/png;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAABQAAD/7g...",
"target_image": "data:image/png;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAABCAAD/7g...",
"source_faces_index": [0],
"face_index": [0],
"upscaler": "4x_Struzan_300000",
"scale": 2,
"upscale_visibility": 1,
"face_restorer": "CodeFormer",
"restorer_visibility": 1,
"restore_first": 1,
"model": "inswapper_128.onnx",
"gender_source": 0,
"gender_target": 0,
"save_to_file": 0,
"result_file_path": ""
}'
```
* Set `"upscaler"` to `"None"` and `"scale"` to `1` if you don't need to upscale;
* Set `"save_to_file"` to `1` if you need to save result to a file;
* `"result_file_path"` is set to the `"outputs/api"` folder by default (please, create the folder beforehand to avoid any errors) with a timestamped filename ;(output_YYYY-MM-DD_hh-mm-ss), you can set any specific path, e.g. `"C:/stable-diffusion-webui/outputs/api/output.png"`.
You can find full usage examples with all the available parameters in the "example" folder: [cURL](./example/api_external.curl), [JSON](./example/api_external.json).
As a result you recieve a "base64" image:
```
{"image":"iVBORw0KGgoAAAANSUhEUgAABlAAAARQCAIAAAAdiYuqAAEAAElEQVR4nOz9+ZMlSXImBn6qau4vIjKzzr5wzwBCDrm/7f+/K7IHV3ZkhUIuyZHlkBhiMGig0Y0..."}
```
A list of available models can be seen by GET:
* http://127.0.0.1:7860/reactor/models
* http://127.0.0.1:7860/reactor/upscalers

View File

@ -8,7 +8,7 @@
</div>
# <div align="center">ReActor 0.4.0a for StableDiffusion</div>
# <div align="center">ReActor 0.4.0b for StableDiffusion</div>
### The Fast and Simple "[roop-based](https://github.com/s0md3v/sd-webui-roop)" FaceSwap Extension with a lot of improvements and without NSFW filter (uncensored, use it on your own [responsibility](#disclaimer))
> Ex "Roop-GE" (GE - Gourieff Edition, aka "NSFW-Roop"), the extension was renamed with the version 0.3.0<br>
@ -17,7 +17,7 @@
---
<div align="center">
<b>
<a href="#installation">Installation</a> | <a href="#usage">Usage</a> | <a href="#troubleshooting">Troubleshooting</a> | <a href="#updating">Updating</a> | <a href="#comfyui">ComfyUI</a> | <a href="#disclaimer">Disclaimer</a>
<a href="#installation">Installation</a> | <a href="#usage">Usage</a> | <a href="#api">API</a> | <a href="#troubleshooting">Troubleshooting</a> | <a href="#updating">Updating</a> | <a href="#comfyui">ComfyUI</a> | <a href="#disclaimer">Disclaimer</a>
</b>
</div>
@ -91,11 +91,6 @@
<img src="example/example.jpg" alt="example" width="808"/>
**You can use ReActor with Webui API:**
1. Check the [SD Web API Wiki](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/API) for how to use API;
2. Call `requests.get(url=f'{address}/sdapi/v1/script-info')` to find the args that ReActor needs;
3. Define ReActor script args and add like this `"alwayson_scripts": {"reactor":{"args":args}}` in the payload;
4. Call the API, there's a [full usage example](./example/api_example.py) in the example folder.
### The result face is blurry
Use the "Restore Face" option. You can also try the "Upscaler" option or for more finer control, use an upscaler from the "Extras" tab.
@ -119,6 +114,12 @@ You can choose to activate the swap on the source image or on the generated imag
Inpainting should work but only the masked part will be swapped.
## API
You can use ReActor with the built-in Webui API or via an external API.
Please follow **[this](/API.md)** page for the detailed instruction.
## Troubleshooting
**I. "You should at least have one model in models directory"**

View File

@ -1,5 +1,5 @@
app_title = "ReActor"
version_flag = "v0.4.0a"
version_flag = "v0.4.0b"
from scripts.logger import logger, get_Run, set_Run