Merge Gallery2

This commit is contained in:
ManInDark 2023-08-12 18:02:45 +02:00 committed by GitHub
commit b836fd5d0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 147 additions and 11 deletions

View File

@ -100,14 +100,28 @@ def init():
raise HTTPException(status_code=404, detail="Image not found")
@server_api.get("/all_images")
def get_all_images(prompt: str = "", model: str = "", db: Session = Depends(get_db)):
def get_all_images(prompt: str = "", model: str = "", page: int = 0, images_per_page: int = 50, db: Session = Depends(get_db)):
from easydiffusion.easydb.mappings import GalleryImage
images = db.query(GalleryImage)
images = db.query(GalleryImage).order_by(GalleryImage.time_created.desc())
if prompt != "":
images = images.filter(GalleryImage.path.like("%"+prompt+"%"))
if model != "":
images = images.filter(GalleryImage.use_stable_diffusion_model.like("%"+model+"%"))
images = images.offset(page*images_per_page).limit(images_per_page)
return images.all()
@server_api.get("/single_image")
def get_single_image(image_path: str, db: Session = Depends(get_db)):
from easydiffusion.easydb.mappings import GalleryImage
image_path = str(abspath(image_path))
try:
image: GalleryImage = db.query(GalleryImage).filter(GalleryImage.path == image_path).first()
head = "<head><link rel='stylesheet' href='/media/css/single-gallery.css'></head>"
body = f"<body><div><button id='use_these_settings' class='primaryButton' json='{image.settingsJSON()}'>Use these settings</button><button id='use_as_input' class='primaryButton' disabled>Use as Input</button></div><img src='/image/" + image.path + "'>" + image.htmlForm() + "</body>"
return Response(content="<html>" + head + body + "</head>", media_type="text/html")
except Exception as e:
print(e)
raise HTTPException(status_code=404, detail="Image not found")
def get_filename_from_url(url):
path = urlparse(url).path

View File

@ -25,11 +25,57 @@ class GalleryImage(Base):
prompt = Column(String)
negative_prompt = Column(String)
time_created = Column(DateTime(timezone=True), server_default=func.now())
nsfw = Column(String, server_default='unknown')
nsfw = Column(Boolean, server_default=None)
def __repr__(self):
return "<GalleryImage(path='%s', seed='%s', use_stable_diffusion_model='%s', clip_skip='%s', use_vae_model='%s', sampler_name='%s', width='%s', height='%s', num_inference_steps='%s', guidance_scale='%s', lora='%s', use_hypernetwork_model='%s', tiling='%s', use_face_correction='%s', use_upscale='%s', prompt='%s', negative_prompt='%s')>" % (
self.path, self.seed, self.use_stable_diffusion_model, self.clip_skip, self.use_vae_model, self.sampler_name, self.width, self.height, self.num_inference_steps, self.guidance_scale, self.lora, self.use_hypernetwork_model, self.tiling, self.use_face_correction, self.use_upscale, self.prompt, self.negative_prompt)
def htmlForm(self) -> str:
return "<div class='panel-box'><p>Path: " + str(self.path) + "</p>" + \
"<p>Seed: " + str(self.seed) + "</p>" + \
"<p>Stable Diffusion Model: " + str(self.use_stable_diffusion_model) + "</p>" + \
"<p>Prompt: " + str(self.prompt) + "</p>" + \
"<p>Negative Prompt: " + str(self.negative_prompt) + "</p>" + \
"<p>Clip Skip: " + str(self.clip_skip) + "</p>" + \
"<p>VAE Model: " + str(self.use_vae_model) + "</p>" + \
"<p>Sampler: " + str(self.sampler_name) + "</p>" + \
"<p>Size: " + str(self.height) + "x" + str(self.width) + "</p>" + \
"<p>Inference Steps: " + str(self.num_inference_steps) + "</p>" + \
"<p>Guidance Scale: " + str(self.guidance_scale) + "</p>" + \
"<p>LoRA: " + str(self.lora) + "</p>" + \
"<p>Hypernetwork: " + str(self.use_hypernetwork_model) + "</p>" + \
"<p>Tiling: " + str(self.tiling) + "</p>" + \
"<p>Face Correction: " + str(self.use_face_correction) + "</p>" + \
"<p>Upscale: " + str(self.use_upscale) + "</p>" + \
"<p>Time Created: " + str(self.time_created) + "</p>" + \
"<p>NSFW: " + str(self.nsfw) + "</p></div>"
def settingsJSON(self) -> str:
# some are still missing: prompt strength, lora
json = {
"numOutputsTotal": 1,
"seed": self.seed,
"reqBody": {
"prompt": self.prompt,
"negative_prompt": self.negative_prompt,
"width": self.width,
"height": self.height,
"seed": self.seed,
"num_inference_steps": self.num_inference_steps,
"guidance_scale": self.guidance_scale,
"use_face_correction": self.use_face_correction,
"use_upscale": self.use_upscale,
"sampler_name": self.sampler_name,
"use_stable_diffusion_model": self.use_stable_diffusion_model,
"clip_skip": self.clip_skip,
"tiling": self.tiling,
"use_vae_model": self.use_vae_model,
"use_hypernetwork_model": self.use_hypernetwork_model
}}
from json import dumps
return dumps(json)
from easydiffusion.easydb.database import engine
GalleryImage.metadata.create_all(engine)

View File

@ -518,9 +518,13 @@
</div>
<div id="tab-content-gallery" class="tab-content">
<div id="gallery-search">
<button class="primaryButton" onclick="decrementGalleryPage()"><i class="fa-solid fa-arrow-left"></i></button>
<textarea id="gallery-prompt-search" onkeydown="gallery_keyDown_handler(event)" placeholder="Search for a prompt..."></textarea>
<textarea id="gallery-model-search" onkeydown="gallery_keyDown_handler(event)" placeholder="Search for a model..."></textarea>
<button class="primaryButton" onclick="refreshGallery()">Refresh</button>
<label for="gallery-page">Page:</label>
<input id="gallery-page" name="Page" value="0" size="1" onkeypress="gallery_keyDown_handler(event)">
<button class="primaryButton" id="gallery-refresh" onclick="refreshGallery()">Load</button>
<button class="primaryButton" onclick="incrementGalleryPage()"><i class="fa-solid fa-arrow-right"></i></button>
</div>
<div class="gallery">
<div class="gallery-container" id="imagecontainer"></div>

View File

@ -0,0 +1,42 @@
@import url("/media/css/themes.css");
@import url("/media/css/main.css");
body {
display: flex;
flex-direction: column;
align-items: center;
background-color: var(--background-color1);
}
img {
border-radius: 5px;
}
p, h1, h2, h3, h4, h5, h6 {
color: var(--text-color);
cursor: default;
margin: 6px;
}
::-moz-selection {
/* Code for Firefox */
color: none;
background: none;
}
::selection {
color: none;
background: none;
}
button {
margin: 8px;
}
div {
margin: 16px;
}
:disabled {
color: gray;
}

View File

@ -3088,6 +3088,19 @@ let recentResolutionsValues = []
function galleryImage(item) {
let div = document.createElement("div")
let img = document.createElement("img")
img.addEventListener("click", (event) => {
let w;
w = window.open("/single_image?image_path=" + item.path, "_blank")
w.addEventListener("DOMContentLoaded", () => {
w.document.getElementsByTagName("body")[0].classList.add(themeField.value)
w.document.getElementById("use_these_settings").addEventListener("click", () => {
restoreTaskToUI(JSON.parse(w.document.getElementById("use_these_settings").getAttribute("json")))
})
w.document.getElementById("use_as_input").addEventListener("click", () => {
alert("use as input")
})
})
})
img.src = "/image/" + item.path
img.dataset["request"] = JSON.stringify(item)
@ -3097,19 +3110,36 @@ function galleryImage(item) {
function refreshGallery() {
let container = document.getElementById("imagecontainer")
params = new URLSearchParams({
prompt: promptsearchfield,
model: modelsearchfield
let params = new URLSearchParams({
prompt: document.getElementById("gallery-prompt-search").value,
model: document.getElementById("gallery-model-search").value,
page: document.getElementById("gallery-page").value
})
container.innerHTML=""
container.innerHTML = ""
fetch('/all_images?' + params)
.then(response => response.json())
.then(json => {
console.log(json)
json.forEach( item => {
if (document.getElementById("gallery-page").value > 0 && json.length == 0) {
decrementGalleryPage()
alert("No more images")
return
}
json.forEach(item => {
container.appendChild(galleryImage(item))
})
})
})
document.getElementById("gallery-refresh").innerText = "Refresh"
}
function decrementGalleryPage() {
let page = Math.max(document.getElementById("gallery-page").value - 1, 0)
document.getElementById("gallery-page").value = page
refreshGallery()
}
function incrementGalleryPage() {
document.getElementById("gallery-page").value++
refreshGallery()
}
function gallery_keyDown_handler(event) {