Git Product home page Git Product logo

Comments (5)

Hugo-Matias avatar Hugo-Matias commented on July 2, 2024 3

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.

from sd-webui-cutoff.

luburn avatar luburn commented on July 2, 2024

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

from sd-webui-cutoff.

nguyenvuducthuy avatar nguyenvuducthuy commented on July 2, 2024

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

from sd-webui-cutoff.

Hugo-Matias avatar Hugo-Matias commented on July 2, 2024

@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.

from sd-webui-cutoff.

nguyenvuducthuy avatar nguyenvuducthuy commented on July 2, 2024

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

from sd-webui-cutoff.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.