Merge pull request #3549 from vladmandic/dev

refresh master
This commit is contained in:
Vladimir Mandic
2024-11-02 09:53:12 -04:00
committed by GitHub
28 changed files with 144 additions and 87 deletions
+2
View File
@@ -90,6 +90,8 @@
"getENActiveTab": "readonly",
"quickApplyStyle": "readonly",
"quickSaveStyle": "readonly",
"setupExtraNetworks": "readonly",
"showNetworks": "readonly",
// from python
"localization": "readonly",
// progressbar.js
+14 -7
View File
@@ -1,14 +1,10 @@
# Change Log for SD.Next
## Update for 2024-11-01
## Update for 2024-11-02
Smaller release just 3 days after the last one, but with some important fixes and improvements.
Smaller release just few days after the last one, but with some important fixes and improvements.
This release can be considered an LTS release before we kick off the next round of major updates.
- XYZ grid:
- optional per-image time benchmark info
- UI:
- add additional [hotkeys](https://github.com/vladmandic/automatic/wiki/Hotkeys)
- Docs:
- add built-in [changelog](https://github.com/vladmandic/automatic/blob/master/CHANGELOG.md) search
since changelog is the best up-to-date source of info
@@ -21,6 +17,13 @@ This release can be considered an LTS release before we kick off the next round
- SD3: all-in-one safetensors
- *examples*: [large](https://civitai.com/models/882666/sd35-large-google-flan?modelVersionId=1003031), [medium](https://civitai.com/models/900327)
- *note*: enable *bnb* on-the-fly quantization for even bigger gains
- UI:
- add additional [hotkeys](https://github.com/vladmandic/automatic/wiki/Hotkeys)
- add show networks on startup setting
- better mapping of networks previews
- optimize networks display load
- XYZ grid:
- optional per-image time benchmark info
- CLI:
- refactor command line params
run `webui.sh`/`webui.bat` with `--help` to see all options
@@ -28,6 +31,7 @@ This release can be considered an LTS release before we kick off the next round
- Repo: move screenshots to GH pages
- Update requirements
- Fixes:
- custom watermark add alphablending
- detailer min/max size as fractions of image size
- ipadapter load on-demand
- ipadapter face use correct yolo model
@@ -36,7 +40,10 @@ This release can be considered an LTS release before we kick off the next round
- fix diffusers load from folder
- fix lora enum logging on windows
- fix xyz grid with batch count
- move dowwloads of some auxillary models to hfcache instead of models folder
- fix vqa models ignoring hfcache folder setting
- fix network height in standard vs modern ui
- fix k-diff enum on startup
- move downloads of some auxillary models to hfcache instead of models folder
## Update for 2024-10-29
+1
View File
@@ -82,6 +82,7 @@ def watermark(params, file):
exif = get_exif(image)
wm = None
if params.command == 'read':
fn = params.input
wm = get_watermark(image, params)
Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 53 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 315 KiB

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 47 KiB

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 33 KiB

+11
View File
@@ -0,0 +1,11 @@
{
"stabilityai--stable-diffusion-3-medium-diffusers": "models/Reference/stabilityai--stable-diffusion-3.jpg",
"stabilityai--stable-diffusion-3.5-medium": "models/Reference/stabilityai--stable-diffusion-3_5.jpg",
"stabilityai--stable-diffusion-3.5-large": "models/Reference/stabilityai--stable-diffusion-3_5.jpg",
"Disty0--FLUX.1-dev-qint8": "models/Reference/black-forest-labs--FLUX.1-dev.jpg",
"Disty0--FLUX.1-dev-qint4": "models/Reference/black-forest-labs--FLUX.1-dev.jpg",
"sayakpaul--flux.1-dev-nf4": "models/Reference/black-forest-labs--FLUX.1-dev.jpg",
"THUDM--CogVideoX-2b": "models/Reference/THUDM--CogView3-Plus-3B.jpg",
"THUDM--CogVideoX-5b": "models/Reference/THUDM--CogView3-Plus-3B.jpg",
"THUDM--CogVideoX-5b-I2V": "models/Reference/THUDM--CogView3-Plus-3B.jpg"
}
+54 -34
View File
@@ -375,6 +375,7 @@ function setupExtraNetworksForTab(tabname) {
if (!tabs) return;
// buttons
const btnShow = gradioApp().getElementById(`${tabname}_extra_networks_btn`);
const btnRefresh = gradioApp().getElementById(`${tabname}_extra_refresh`);
const btnScan = gradioApp().getElementById(`${tabname}_extra_scan`);
const btnSave = gradioApp().getElementById(`${tabname}_extra_save`);
@@ -448,50 +449,69 @@ function setupExtraNetworksForTab(tabname) {
// en style
if (!en) return;
let lastView;
let heightInitialized = false;
const intersectionObserver = new IntersectionObserver((entries) => {
for (const el of Array.from(gradioApp().querySelectorAll('.extra-networks-page'))) {
el.style.height = `${window.opts.extra_networks_height}vh`;
el.parentElement.style.width = '-webkit-fill-available';
if (!heightInitialized) {
heightInitialized = true;
let h = 0;
const target = window.opts.extra_networks_card_cover === 'sidebar' ? 0 : window.opts.extra_networks_height;
if (window.opts.theme_type === 'Standard') h = target > 0 ? target : 55;
else h = target > 0 ? target : 87;
for (const el of Array.from(gradioApp().getElementById(`${tabname}_extra_tabs`).querySelectorAll('.extra-networks-page'))) {
if (h > 0) el.style.height = `${h}vh`;
el.parentElement.style.width = '-webkit-fill-available';
}
}
if (entries[0].intersectionRatio > 0) {
refreshENpage();
// sortExtraNetworks('fixed');
if (window.opts.extra_networks_card_cover === 'cover') {
en.style.transition = '';
en.style.zIndex = 100;
en.style.top = '13em';
en.style.position = 'absolute';
en.style.right = 'unset';
en.style.width = 'unset';
en.style.height = 'unset';
gradioApp().getElementById(`${tabname}_settings`).parentNode.style.width = 'unset';
} else if (window.opts.extra_networks_card_cover === 'sidebar') {
en.style.zIndex = 100;
en.style.position = 'absolute';
en.style.right = '0';
en.style.top = '13em';
en.style.height = 'auto';
en.style.transition = 'width 0.3s ease';
en.style.width = `${window.opts.extra_networks_sidebar_width}vw`;
gradioApp().getElementById(`${tabname}_settings`).parentNode.style.width = `${100 - 2 - window.opts.extra_networks_sidebar_width}vw`;
if (lastView !== entries[0].intersectionRatio > 0) {
lastView = entries[0].intersectionRatio > 0;
if (lastView) {
refreshENpage();
// sortExtraNetworks('fixed');
if (window.opts.extra_networks_card_cover === 'cover') {
en.style.position = 'absolute';
en.style.height = 'unset';
en.style.width = 'unset';
en.style.right = 'unset';
en.style.top = '13em';
en.style.transition = '';
en.style.zIndex = 100;
gradioApp().getElementById(`${tabname}_settings`).parentNode.style.width = 'unset';
} else if (window.opts.extra_networks_card_cover === 'sidebar') {
en.style.position = 'absolute';
en.style.height = 'auto';
en.style.width = `${window.opts.extra_networks_sidebar_width}vw`;
en.style.right = '0';
en.style.top = '13em';
en.style.transition = 'width 0.3s ease';
en.style.zIndex = 100;
gradioApp().getElementById(`${tabname}_settings`).parentNode.style.width = `${100 - 2 - window.opts.extra_networks_sidebar_width}vw`;
} else {
en.style.position = 'relative';
en.style.height = 'unset';
en.style.width = 'unset';
en.style.right = 'unset';
en.style.top = 0;
en.style.transition = '';
en.style.zIndex = 0;
gradioApp().getElementById(`${tabname}_settings`).parentNode.style.width = 'unset';
}
} else {
en.style.transition = '';
en.style.zIndex = 0;
en.style.top = 0;
en.style.position = 'relative';
en.style.right = 'unset';
en.style.width = 'unset';
en.style.height = 'unset';
if (window.opts.extra_networks_card_cover === 'sidebar') en.style.width = 0;
gradioApp().getElementById(`${tabname}_settings`).parentNode.style.width = 'unset';
}
} else {
if (window.opts.extra_networks_card_cover === 'sidebar') en.style.width = 0;
gradioApp().getElementById(`${tabname}_settings`).parentNode.style.width = 'unset';
}
});
intersectionObserver.observe(en); // monitor visibility
}
async function showNetworks() {
for (const tabname of ['txt2img', 'img2img', 'control']) {
if (window.opts.extra_networks_show) gradioApp().getElementById(`${tabname}_extra_networks_btn`).click();
}
log('showNetworks');
}
async function setupExtraNetworks() {
setupExtraNetworksForTab('txt2img');
setupExtraNetworksForTab('img2img');
+2 -2
View File
@@ -3,7 +3,7 @@ const appStartTime = performance.now();
async function preloadImages() {
const dark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
const imagePromises = [];
const num = Math.floor(10 * Math.random());
const num = Math.floor(9.99 * Math.random());
const imageUrls = [
`file=html/logo-bg-${dark ? 'dark' : 'light'}.jpg`,
`file=html/logo-bg-${num}.jpg`,
@@ -27,7 +27,7 @@ async function preloadImages() {
async function createSplash() {
const dark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
log('createSplash', { theme: dark ? 'dark' : 'light' });
const num = Math.floor(11 * Math.random());
const num = Math.floor(9.99 * Math.random());
const splash = `
<div id="splash" class="splash" style="background: ${dark ? 'black' : 'white'}">
<div class="loading"><div class="loader"></div></div>
+1 -1
View File
@@ -203,7 +203,7 @@ table.settings-value-table td { padding: 0.4em; border: 1px solid #ccc; max-widt
#extensions .date { opacity: 0.85; font-size: var(--text-sm); }
/* extra networks */
#txt2img_extra_networks, #img2img_extra_networks, #control_extra_networks { width: 0; }
.extra_networks_root { width: 0; position: absolute; height: auto; right: 0; top: 13em; z-index: 100; } /* default is sidebar view */
.extra-networks { background: var(--background-color); padding: var(--block-label-padding); }
.extra-networks > div { margin: 0; border-bottom: none !important; gap: 0.3em 0; }
.extra-networks .second-line { display: flex; width: -moz-available; width: -webkit-fill-available; gap: 0.3em; box-shadow: var(--input-shadow); }
+1
View File
@@ -32,6 +32,7 @@ async function initStartup() {
removeSplash();
// post startup tasks that may take longer but are not critical
showNetworks();
setHints();
applyStyles();
initIndexDB();
+10 -2
View File
@@ -374,6 +374,8 @@ def set_watermark(image, watermark):
wm_image = None
try:
wm_image = Image.open(shared.opts.image_watermark_image)
if wm_image.mode != 'RGBA':
wm_image = wm_image.convert('RGBA')
except Exception as e:
shared.log.warning(f'Set image watermark: fn="{shared.opts.image_watermark_image}" {e}')
if wm_image is not None:
@@ -392,8 +394,14 @@ def set_watermark(image, watermark):
try:
for x in range(wm_image.width):
for y in range(wm_image.height):
r, g, b, _a = wm_image.getpixel((x, y))
if not (r == 0 and g == 0 and b == 0):
rgba = wm_image.getpixel((x, y))
orig = image.getpixel((x+position[0], y+position[1]))
# alpha blend
a = rgba[3] / 255
r = int(rgba[0] * a + orig[0] * (1 - a))
g = int(rgba[1] * a + orig[1] * (1 - a))
b = int(rgba[2] * a + orig[2] * (1 - a))
if not a == 0:
image.putpixel((x+position[0], y+position[1]), (r, g, b))
shared.log.debug(f'Set image watermark: fn="{shared.opts.image_watermark_image}" image={wm_image} position={position}')
except Exception as e:
+5 -6
View File
@@ -25,7 +25,6 @@ class YoloResult:
self.box = box
self.mask = mask
self.item = item
self.size = size
self.width = width
self.height = height
self.args = args
@@ -127,17 +126,17 @@ class YoloRestorer(Detailer):
box = box.tolist()
mask_image = None
w, h = box[2] - box[0], box[3] - box[1]
size = w * h / (image.width * image.height)
min_size = (shared.opts.detailer_min_size if shared.opts.detailer_min_size > 0 else 0) * min(w, h)
max_size = (shared.opts.detailer_max_size if shared.opts.detailer_max_size > 0 else 1) * max(w, h)
if (min(w, h) > min_size) and (max(w, h) < max_size):
x_size, y_size = w/image.width, h/image.height
min_size = shared.opts.detailer_min_size if shared.opts.detailer_min_size > 0 and shared.opts.detailer_min_size < 1 else 0
max_size = shared.opts.detailer_max_size if shared.opts.detailer_max_size > 0 and shared.opts.detailer_max_size < 1 else 1
if x_size >= min_size and y_size >=min_size and x_size <= max_size and y_size <= max_size:
if mask:
mask_image = image.copy()
mask_image = Image.new('L', image.size, 0)
draw = ImageDraw.Draw(mask_image)
draw.rectangle(box, fill="white", outline=None, width=0)
cropped = image.crop(box)
result.append(YoloResult(cls=cls, label=label, score=round(score, 2), box=box, mask=mask_image, item=cropped, size=size, width=w, height=h, args=args))
result.append(YoloResult(cls=cls, label=label, score=round(score, 2), box=box, mask=mask_image, item=cropped, width=w, height=h, args=args))
if len(result) >= shared.opts.detailer_max:
break
return result
+14 -8
View File
@@ -877,8 +877,9 @@ options_templates.update(options_section(('interrogate', "Interrogate"), {
}))
options_templates.update(options_section(('extra_networks', "Networks"), {
"extra_networks_sep1": OptionInfo("<h2>Extra networks UI</h2>", "", gr.HTML),
"extra_networks": OptionInfo(["All"], "Networks", gr.Dropdown, lambda: {"multiselect":True, "choices": ['All'] + [en.title for en in extra_networks]}),
"extra_networks_sep1": OptionInfo("<h2>Networks UI</h2>", "", gr.HTML),
"extra_networks_show": OptionInfo(True, "UI show on startup"),
"extra_networks": OptionInfo(["All"], "Available networks", gr.Dropdown, lambda: {"multiselect":True, "choices": ['All'] + [en.title for en in extra_networks]}),
"extra_networks_sort": OptionInfo("Default", "Sort order", gr.Dropdown, {"choices": ['Default', 'Name [A-Z]', 'Name [Z-A]', 'Date [Newest]', 'Date [Oldest]', 'Size [Largest]', 'Size [Smallest]']}),
"extra_networks_view": OptionInfo("gallery", "UI view", gr.Radio, {"choices": ["gallery", "list"]}),
"extra_networks_card_cover": OptionInfo("sidebar", "UI position", gr.Radio, {"choices": ["cover", "inline", "sidebar"]}),
@@ -888,13 +889,18 @@ options_templates.update(options_section(('extra_networks', "Networks"), {
"extra_networks_card_square": OptionInfo(True, "UI disable variable aspect ratio"),
"extra_networks_fetch": OptionInfo(True, "UI fetch network info on mouse-over"),
"extra_networks_card_fit": OptionInfo("cover", "UI image contain method", gr.Radio, {"choices": ["contain", "cover", "fill"], "visible": False}),
"extra_networks_sep2": OptionInfo("<h2>Extra networks general</h2>", "", gr.HTML),
"extra_network_reference": OptionInfo(False, "Use reference values when available", gr.Checkbox),
"extra_network_skip_indexing": OptionInfo(False, "Build info on first access", gr.Checkbox),
"extra_networks_default_multiplier": OptionInfo(1.0, "Default strength", gr.Slider, {"minimum": 0.0, "maximum": 2.0, "step": 0.01}),
"extra_networks_model_sep": OptionInfo("<h2>Models</h2>", "", gr.HTML),
"extra_network_reference": OptionInfo(False, "Use reference values when available", gr.Checkbox),
"extra_networks_embed_sep": OptionInfo("<h2>Embeddings</h2>", "", gr.HTML),
"diffusers_convert_embed": OptionInfo(False, "Auto-convert SD 1.5 embeddings to SDXL ", gr.Checkbox, {"visible": native}),
"extra_networks_sep3": OptionInfo("<h2>Extra networks settings</h2>", "", gr.HTML),
"extra_networks_styles_sep": OptionInfo("<h2>Styles</h2>", "", gr.HTML),
"extra_networks_styles": OptionInfo(True, "Show built-in styles"),
"extra_networks_wildcard_sep": OptionInfo("<h2>Wildcards</h2>", "", gr.HTML),
"wildcards_enabled": OptionInfo(True, "Enable file wildcards support"),
"extra_networks_lora_sep": OptionInfo("<h2>LoRA</h2>", "", gr.HTML),
"extra_networks_default_multiplier": OptionInfo(1.0, "Default strength", gr.Slider, {"minimum": 0.0, "maximum": 2.0, "step": 0.01}),
"lora_preferred_name": OptionInfo("filename", "LoRA preferred name", gr.Radio, {"choices": ["filename", "alias"]}),
"lora_add_hashes_to_infotext": OptionInfo(False, "LoRA add hash info"),
"lora_force_diffusers": OptionInfo(False if not cmd_opts.use_openvino else True, "LoRA force loading of all models using Diffusers"),
@@ -905,9 +911,9 @@ options_templates.update(options_section(('extra_networks', "Networks"), {
"lora_quant": OptionInfo("NF4","LoRA precision in quantized models", gr.Radio, {"choices": ["NF4", "FP4"]}),
"lora_functional": OptionInfo(False, "Use Kohya method for handling multiple LoRA", gr.Checkbox, { "visible": False }),
"lora_load_gpu": OptionInfo(True if not cmd_opts.lowvram else False, "Load LoRA directly to GPU"),
"hypernetwork_enabled": OptionInfo(False, "Enable Hypernetwork support"),
"hypernetwork_enabled": OptionInfo(False, "Enable Hypernetwork support", gr.Checkbox, {"visible": False}),
"sd_hypernetwork": OptionInfo("None", "Add hypernetwork to prompt", gr.Dropdown, { "choices": ["None"], "visible": False }),
"wildcards_enabled": OptionInfo(True, "Enable file wildcards support"),
}))
options_templates.update(options_section((None, "Hidden options"), {
+1 -1
View File
@@ -152,7 +152,7 @@ def create_ui(_blocks: gr.Blocks=None):
with gr.Row():
override_settings = ui_common.create_override_inputs('control')
with gr.Row(variant='compact', elem_id="control_extra_networks", visible=False) as extra_networks_ui:
with gr.Row(variant='compact', elem_id="control_extra_networks", elem_classes=["extra_networks_root"], visible=False) as extra_networks_ui:
from modules import timer, ui_extra_networks
extra_networks_ui = ui_extra_networks.create_ui(extra_networks_ui, btn_extra, 'control', skip_indexing=shared.opts.extra_network_skip_indexing)
timer.startup.record('ui-networks')
+10
View File
@@ -50,6 +50,7 @@ card_list = '''
</div>
</div>
'''
preview_map = None
def init_api(app):
@@ -350,6 +351,9 @@ class ExtraNetworksPage:
return self.link_preview(preview_file)
def update_all_previews(self, items):
global preview_map # pylint: disable=global-statement
if preview_map is None:
preview_map = shared.readfile('html/previews.json', silent=True)
t0 = time.time()
reference_path = os.path.abspath(os.path.join('models', 'Reference'))
possible_paths = list(set([os.path.dirname(item['filename']) for item in items] + [reference_path]))
@@ -378,8 +382,14 @@ class ExtraNetworksPage:
self.missing_thumbs.append(all_previews[file_idx])
item['preview'] = self.link_preview(all_previews[file_idx])
break
if item.get('preview', None) is None:
found = preview_map.get(base, None)
if found is not None:
item['preview'] = self.link_preview(found)
debug(f'EN mapped-preview: {item["name"]}={found}')
if item.get('preview', None) is None:
item['preview'] = self.link_preview('html/card-no-preview.png')
debug(f'EN missing-preview: {item["name"]}')
self.preview_time += time.time() - t0
+1 -1
View File
@@ -41,7 +41,7 @@ def create_ui():
img2img_prompt, img2img_prompt_styles, img2img_negative_prompt, img2img_submit, img2img_reprocess, img2img_paste, img2img_extra_networks_button, img2img_token_counter, img2img_token_button, img2img_negative_token_counter, img2img_negative_token_button = ui_sections.create_toprow(is_img2img=True, id_part="img2img")
img2img_prompt_img = gr.File(label="", elem_id="img2img_prompt_image", file_count="single", type="binary", visible=False)
with gr.Row(variant='compact', elem_id="img2img_extra_networks", visible=False) as extra_networks_ui:
with gr.Row(variant='compact', elem_id="img2img_extra_networks", elem_classes=["extra_networks_root"], visible=False) as extra_networks_ui:
from modules import ui_extra_networks
extra_networks_ui_img2img = ui_extra_networks.create_ui(extra_networks_ui, img2img_extra_networks_button, 'img2img', skip_indexing=shared.opts.extra_network_skip_indexing)
timer.startup.record('ui-networks')
+1 -1
View File
@@ -25,7 +25,7 @@ def create_ui():
txt_prompt_img = gr.File(label="", elem_id="txt2img_prompt_image", file_count="single", type="binary", visible=False)
txt_prompt_img.change(fn=modules.images.image_data, inputs=[txt_prompt_img], outputs=[txt2img_prompt, txt_prompt_img])
with gr.Row(variant='compact', elem_id="txt2img_extra_networks", visible=False) as extra_networks_ui:
with gr.Row(variant='compact', elem_id="txt2img_extra_networks", elem_classes=["extra_networks_root"], visible=False) as extra_networks_ui:
from modules import ui_extra_networks
extra_networks_ui = ui_extra_networks.create_ui(extra_networks_ui, txt2img_extra_networks_button, 'txt2img', skip_indexing=shared.opts.extra_network_skip_indexing)
timer.startup.record('ui-networks')
+12 -12
View File
@@ -30,8 +30,8 @@ MODELS = {
def git(question: str, image: Image.Image, repo: str = None):
global processor, model, loaded # pylint: disable=global-statement
if model is None or loaded != repo:
model = transformers.GitForCausalLM.from_pretrained(repo)
processor = transformers.GitProcessor.from_pretrained(repo)
model = transformers.GitForCausalLM.from_pretrained(repo, cache_dir=shared.opts.hfcache_dir)
processor = transformers.GitProcessor.from_pretrained(repo, cache_dir=shared.opts.hfcache_dir)
loaded = repo
model.to(devices.device, devices.dtype)
shared.log.debug(f'VQA: class={model.__class__.__name__} processor={processor.__class__} model={repo}')
@@ -55,8 +55,8 @@ def git(question: str, image: Image.Image, repo: str = None):
def blip(question: str, image: Image.Image, repo: str = None):
global processor, model, loaded # pylint: disable=global-statement
if model is None or loaded != repo:
model = transformers.BlipForQuestionAnswering.from_pretrained(repo)
processor = transformers.BlipProcessor.from_pretrained(repo)
model = transformers.BlipForQuestionAnswering.from_pretrained(repo, cache_dir=shared.opts.hfcache_dir)
processor = transformers.BlipProcessor.from_pretrained(repo, cache_dir=shared.opts.hfcache_dir)
loaded = repo
model.to(devices.device, devices.dtype)
inputs = processor(image, question, return_tensors="pt")
@@ -73,8 +73,8 @@ def blip(question: str, image: Image.Image, repo: str = None):
def vilt(question: str, image: Image.Image, repo: str = None):
global processor, model, loaded # pylint: disable=global-statement
if model is None or loaded != repo:
model = transformers.ViltForQuestionAnswering.from_pretrained(repo)
processor = transformers.ViltProcessor.from_pretrained(repo)
model = transformers.ViltForQuestionAnswering.from_pretrained(repo, cache_dir=shared.opts.hfcache_dir)
processor = transformers.ViltProcessor.from_pretrained(repo, cache_dir=shared.opts.hfcache_dir)
loaded = repo
model.to(devices.device)
shared.log.debug(f'VQA: class={model.__class__.__name__} processor={processor.__class__} model={repo}')
@@ -94,8 +94,8 @@ def vilt(question: str, image: Image.Image, repo: str = None):
def pix(question: str, image: Image.Image, repo: str = None):
global processor, model, loaded # pylint: disable=global-statement
if model is None or loaded != repo:
model = transformers.Pix2StructForConditionalGeneration.from_pretrained(repo)
processor = transformers.Pix2StructProcessor.from_pretrained(repo)
model = transformers.Pix2StructForConditionalGeneration.from_pretrained(repo, cache_dir=shared.opts.hfcache_dir)
processor = transformers.Pix2StructProcessor.from_pretrained(repo, cache_dir=shared.opts.hfcache_dir)
loaded = repo
model.to(devices.device)
shared.log.debug(f'VQA: class={model.__class__.__name__} processor={processor.__class__} model={repo}')
@@ -115,8 +115,8 @@ def pix(question: str, image: Image.Image, repo: str = None):
def moondream(question: str, image: Image.Image, repo: str = None):
global processor, model, loaded # pylint: disable=global-statement
if model is None or loaded != repo:
model = transformers.AutoModelForCausalLM.from_pretrained(repo, trust_remote_code=True) # revision = "2024-03-05"
processor = transformers.AutoTokenizer.from_pretrained(repo) # revision = "2024-03-05"
model = transformers.AutoModelForCausalLM.from_pretrained(repo, trust_remote_code=True, cache_dir=shared.opts.hfcache_dir) # revision = "2024-03-05"
processor = transformers.AutoTokenizer.from_pretrained(repo, cache_dir=shared.opts.hfcache_dir)
loaded = repo
model.eval()
model.to(devices.device, devices.dtype)
@@ -142,8 +142,8 @@ def florence(question: str, image: Image.Image, repo: str = None, revision: str
return R
if model is None or loaded != repo:
transformers.dynamic_module_utils.get_imports = get_imports
model = transformers.AutoModelForCausalLM.from_pretrained(repo, trust_remote_code=True, revision=revision)
processor = transformers.AutoProcessor.from_pretrained(repo, trust_remote_code=True, revision=revision)
model = transformers.AutoModelForCausalLM.from_pretrained(repo, trust_remote_code=True, revision=revision, cache_dir=shared.opts.hfcache_dir)
processor = transformers.AutoProcessor.from_pretrained(repo, trust_remote_code=True, revision=revision, cache_dir=shared.opts.hfcache_dir)
transformers.dynamic_module_utils.get_imports = _get_imports
loaded = repo
model.eval()
+3 -11
View File
@@ -1,5 +1,4 @@
import inspect
import importlib
import gradio as gr
import diffusers
from modules import scripts, processing, shared, sd_models
@@ -8,10 +7,7 @@ from modules import scripts, processing, shared, sd_models
class Script(scripts.Script):
supported_models = ['sd', 'sdxl']
orig_pipe = None
try:
library = importlib.import_module('k_diffusion')
except Exception:
library = None
library = None
def title(self):
return 'K-Diffusion'
@@ -28,10 +24,8 @@ class Script(scripts.Script):
def samplers(self):
samplers = []
sampling = getattr(self.library, 'sampling', None)
if sampling is None:
return samplers
for s in dir(sampling):
from modules import sd_samplers_kdiffusion
for s in dir(sd_samplers_kdiffusion.k_sampling):
if s.startswith('sample_'):
samplers.append(s.replace('sample_', ''))
return samplers
@@ -43,8 +37,6 @@ class Script(scripts.Script):
if shared.sd_model_type not in self.supported_models:
shared.log.warning(f'K-Diffusion: class={shared.sd_model.__class__.__name__} model={shared.sd_model_type} required={self.supported_models}')
return None
if self.library is None:
return
cls = None
if shared.sd_model_type == "sd":
cls = diffusers.pipelines.StableDiffusionKDiffusionPipeline
+1 -1
Submodule wiki updated: a64e3776fd...b36c2e1a4c