Skip to content

Instantly share code, notes, and snippets.

@opparco
opparco / xyz_grid-replace-lora-args.patch
Last active April 25, 2023 00:45
Prompt S/R for LoRA and LyCORIS arguments
diff --git a/scripts/xyz_grid.py b/scripts/xyz_grid.py
index 3895a795..a5765c3a 100644
--- a/scripts/xyz_grid.py
+++ b/scripts/xyz_grid.py
@@ -36,11 +36,24 @@ def apply_field(field):
def apply_prompt(p, x, xs):
- if xs[0] not in p.prompt and xs[0] not in p.negative_prompt:
- raise RuntimeError(f"Prompt S/R did not find {xs[0]} in prompt or negative prompt.")
@opparco
opparco / client-sample.py
Created November 15, 2022 05:22
gradio api txt2img client sample
import requests
def main():
prompt = "((masterpiece)), ((best quality)), ((illustration)), nsfw, beautiful thicc cute victorian girl, loli face, Feminine, Anders Zorn, ((cleavage of huge breasts)), puffy nipple, :d, blouse, long skirt"
negative_prompt = "[[octane]], [[nsfw]], low hand,low arms,hand,arms,fingers,legs, lower body,thighs, cropped, worst quality, low quality,quality"
sampling_methods = [
"Euler a",
"Euler",
diff --git a/modules/ui.py b/modules/ui.py
index 5dce7f3..3a5cc55 100644
--- a/modules/ui.py
+++ b/modules/ui.py
@@ -775,7 +775,7 @@ def create_ui(wrap_gradio_gpu_call):
show_progress=False,
)
- txt2img_prompt.submit(**txt2img_args)
+ txt2img_prompt.submit(api_name='txt2img', **txt2img_args)
@opparco
opparco / mix_model.py
Created September 14, 2022 13:48
Generate a mixed model of the two models.
import argparse
import torch
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"--ckpt0",
type=str,
diff --git a/ldm/modules/attention.py b/ldm/modules/attention.py
index f4eff39..f90c6c4 100644
--- a/ldm/modules/attention.py
+++ b/ldm/modules/attention.py
@@ -174,23 +174,27 @@ class CrossAttention(nn.Module):
context = default(context, x)
k = self.to_k(context)
v = self.to_v(context)
+ del context, x
@opparco
opparco / prompt2tokens.py
Created September 2, 2022 15:54
Get the number of tokens using the same tokenizer that Stable Diffusion uses.
"""
Get the number of tokens using the same tokenizer that Stable Diffusion uses.
author: opparco
"""
import argparse
from transformers import CLIPTokenizer
def main():
@opparco
opparco / parser.y
Created December 2, 2021 06:13
postposition option
class BCDice::Command::Parser
token NUMBER R U C F PLUS MINUS ASTERISK SLASH PARENL PARENR AT SHARP DOLLAR CMP_OP QUESTION NOTATION
expect 2
rule
expr: notation option modifier target option
{
raise ParseError unless @modifier
notation, option, modifier, target, post_option = val
for code in "1000".."9999"
a, b, c, d = code.bytes.map {|byte| byte - 0x30}
n = code.to_i
x = a + b + c + d
# min(x) = 1
# max(x) = 36
next if x == 1
@opparco
opparco / NodeMap.cpp
Last active February 15, 2021 04:25
CBPFO4 NodeMap
#include <set>
#include "NodeMap.h"
std::unordered_map<NiNode *, std::unordered_map<std::string, NiNode *> > m_nodes_container;
void DeleteNodeMap(NiNode * rootnode)
{
_DMESSAGE("DeleteNodeMap rootnode %p", rootnode);
m_nodes_container.erase(rootnode);
@opparco
opparco / opal_mt-1.js
Created October 3, 2020 09:58
random test
// https://github.com/opal/opal/blob/b1074a37150f9b0b53a35f0efa4a1cbddc02ba29/opal/corelib/random/mersenne_twister.rb
// node opal_mt.js
var mt19937 = (function() {
/* Period parameters */
var N = 624;
var M = 397;
var MATRIX_A = 0x9908b0df; /* constant vector a */
var UMASK = 0x80000000; /* most significant w-r bits */
var LMASK = 0x7fffffff; /* least significant r bits */
var MIXBITS = function(u,v) { return ( ((u) & UMASK) | ((v) & LMASK) ); };