Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webui api #8

Open
nguyenvuducthuy opened this issue Mar 18, 2023 · 5 comments
Open

Webui api #8

nguyenvuducthuy opened this issue Mar 18, 2023 · 5 comments

Comments

@nguyenvuducthuy
Copy link

Hi,
How can I use it with webui api?

@luburn
Copy link

luburn commented Mar 18, 2023

like the WebUI from the automatic1111 repo? if yes:

  • launch the WebUI, go to extensions
  • click on install from URL and paste the URL of git (from the code button)
  • install and restart the website
  • go into text2img
  • put your prompt with the colors
  • there should be a row called Cutoff, enable it
  • in the target token add the colors and separate them with a comma.
  • generate the picture.
    Color
    image

@nguyenvuducthuy
Copy link
Author

Thanks, but I am not mean that. I mean how can I use it inside a script instead of UI, I try this but not sure it work or not :)
image

@Hugo-Matias
Copy link

@nguyenvuducthuy Did you find a solution? I took a look at the scripts/cutoff.py file and noticed that these are the arguments passed into the process function:

enabled: bool,
targets_: str,
weight: Union[float,int],
disable_neg: bool,
strong: bool,
padding: Union[str,int],
intp: str,
debug: bool

Apart from this there is also the returned values from the ui function, most of all are named equal except targets_ => targets and intp => lerp.

I'm still not sure if the api has an handler out of the box without the script providing a specific implementation to call the arguments but it's worth a shot.

@Hugo-Matias
Copy link

Hugo-Matias commented Mar 21, 2023

Ok, seems like my assumptions were correct. We can use the process function signature to pass in the arguments to the call payload. Here is a working example:

 {
  "enable_hr": false,
  "prompt": "red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background",
  "seed": 1329830405,
  "sampler_name": "DDIM",
  "batch_size": 1,
  "n_iter": 1,
  "steps": 20,
  "cfg_scale": 7,
  "width": 512,
  "height": 512,
  "alwayson_scripts": {
	"Cutoff": {
		"args": [
			true,  // enabled: bool
			"red, blue, green, yellow",  // targets: string
			2,  // weight: float
			false,  // disable_neg: bool
			false,  // strong: bool (Cutoff strongly)
			"",  // padding: string or int (Padding token (ID or single token))
			"Lerp",  // inpt: string (Interpolation method) Possible values: ["Lerp", "SLerp" ]
			true,  //debug: bool (useful if you want to make sure it's working, check the output below)
		]
	}
  }
}

If you copy this into Swagger or your app, make sure you delete the json comments they are for demonstration purposes only.

Notice that the args parameter is a List of mixed type values, I haven't tested with a Dictionary like used by ControlNet because I think that implementation is specific for that script and how they hijack the call but I might be wrong.

Since we have a bool to log debug info, we can use it to make sure the script is being triggered right before inference, this is the output of the example I provided:

[Cutoff] replace: red, blue, green, yellow
[Cutoff] to: _</w> (318)
[Cutoff] original:
[Cutoff]       #0:
[Cutoff] replace: red, blue, green, yellow
[Cutoff] to: _</w> (318)
[Cutoff] original: red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
[Cutoff]       #0: red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
[Cutoff]       #1: red ferrari 458 italia, clear blue sky, green mountains,  _  house in the background
[Cutoff]       #2: red ferrari 458 italia, clear blue sky,  _  mountains, yellow house in the background
[Cutoff]       #3: red ferrari 458 italia, clear blue sky,  _  mountains,  _  house in the background
[Cutoff]       #4: red ferrari 458 italia, clear  _  sky, green mountains, yellow house in the background
[Cutoff]       #5: red ferrari 458 italia, clear  _  sky, green mountains,  _  house in the background
[Cutoff]       #6: red ferrari 458 italia, clear  _  sky,  _  mountains, yellow house in the background
[Cutoff]       #7: red ferrari 458 italia, clear  _  sky,  _  mountains,  _  house in the background
[Cutoff]       #8:  _  ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
[Cutoff]       #9:  _  ferrari 458 italia, clear blue sky, green mountains,  _  house in the background
[Cutoff]       #10:  _  ferrari 458 italia, clear blue sky,  _  mountains, yellow house in the background
[Cutoff]       #11:  _  ferrari 458 italia, clear blue sky,  _  mountains,  _  house in the background
[Cutoff]       #12:  _  ferrari 458 italia, clear  _  sky, green mountains, yellow house in the background
[Cutoff]       #13:  _  ferrari 458 italia, clear  _  sky, green mountains,  _  house in the background
[Cutoff]       #14:  _  ferrari 458 italia, clear  _  sky,  _  mountains, yellow house in the background
[Cutoff]       #15:  _  ferrari 458 italia, clear  _  sky,  _  mountains,  _  house in the background
000 <|startoftext|>  red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
007 ,</w>            red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
011 ,</w>            red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
014 ,</w>            red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
020 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
021 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
022 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
023 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
024 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
025 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
026 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
027 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
028 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
029 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
030 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
031 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
032 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
033 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
034 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
035 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
036 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
037 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
038 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
039 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
040 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
041 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
042 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
043 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
044 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
045 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
046 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
047 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
048 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
049 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
050 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
051 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
052 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
053 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
054 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
055 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
056 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
057 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
058 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
059 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
060 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
061 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
062 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
063 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
064 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
065 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
066 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
067 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
068 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
069 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
070 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
071 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
072 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
073 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
074 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
075 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
076 <|endoftext|>    red ferrari 458 italia, clear blue sky, green mountains, yellow house in the background
001 red</w>          red ferrari 458 italia, clear  _  sky,  _  mountains,  _  house in the background
002 ferrari</w>      red ferrari 458 italia, clear  _  sky,  _  mountains,  _  house in the background
003 4</w>            red ferrari 458 italia, clear  _  sky,  _  mountains,  _  house in the background
004 5</w>            red ferrari 458 italia, clear  _  sky,  _  mountains,  _  house in the background
005 8</w>            red ferrari 458 italia, clear  _  sky,  _  mountains,  _  house in the background
006 italia</w>       red ferrari 458 italia, clear  _  sky,  _  mountains,  _  house in the background
008 clear</w>         _  ferrari 458 italia, clear blue sky,  _  mountains,  _  house in the background
009 blue</w>          _  ferrari 458 italia, clear blue sky,  _  mountains,  _  house in the background
010 sky</w>           _  ferrari 458 italia, clear blue sky,  _  mountains,  _  house in the background
012 green</w>         _  ferrari 458 italia, clear  _  sky, green mountains,  _  house in the background
013 mountains</w>     _  ferrari 458 italia, clear  _  sky, green mountains,  _  house in the background
015 yellow</w>        _  ferrari 458 italia, clear  _  sky,  _  mountains, yellow house in the background
016 house</w>         _  ferrari 458 italia, clear  _  sky,  _  mountains, yellow house in the background
017 in</w>            _  ferrari 458 italia, clear  _  sky,  _  mountains, yellow house in the background
018 the</w>           _  ferrari 458 italia, clear  _  sky,  _  mountains, yellow house in the background
019 background</w>    _  ferrari 458 italia, clear  _  sky,  _  mountains, yellow house in the background

I don't understand what the script is doing in the background but it seems to be working as if it was called from the webui. Is there something abnormal that you can spot in there?

As for the results. Most likely is improper prompting (should have used red car ferrari... instead of red ferrari) but they seem to contradict the log...
Script Disabled
Script Enabled

Further testing needs to be done but this is really promissing already!

EDIT: After a few more generations it seems to be replicating the same behavior from the webui so the api call seems to be working as expected.

Quick question regarding the padding token, the default value is _</w> (318) but what exactly is it doing and how would changing it affect the output? My success rate isn't very high with the prompt I've tested earlier but it's better than not using the script so it's still a win.

I also noticed that sometimes it helps not targeting all the colors but only the ones that get confused by the AI, "red,yellow" in this case.

@nguyenvuducthuy
Copy link
Author

thanks look like it working in my tool, but the result rate isn't high ... I will check more to see why

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants