Spaces:
Runtime error
Runtime error
Commit
·
4b58b3f
1
Parent(s):
f911525
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,78 +1,36 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
import numpy as np
|
| 4 |
-
import modin.pandas as pd
|
| 5 |
from PIL import Image
|
| 6 |
from diffusers import DiffusionPipeline
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
else:
|
| 39 |
-
del i
|
| 40 |
-
user_home = pathlib.Path.home().resolve()
|
| 41 |
-
os.chdir(str(user_home))
|
| 42 |
-
os.chdir(user_home / "stable-diffusion-webui")
|
| 43 |
-
# download additional network model
|
| 44 |
-
print("Downloading additional network model")
|
| 45 |
-
DownLoad(r"https://civitai.com/api/download/models/39885",str(user_home / r"stable-diffusion-webui" / r"extensions" / r"sd-webui-additional-networks" / r"models"/ r"lora"),r"Better_light.safetensors")
|
| 46 |
-
# load main models
|
| 47 |
-
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 48 |
-
def load_model(model_url):
|
| 49 |
-
return DiffusionPipeline.from_pretrained(model_url, use_safetensors=True).to(device)
|
| 50 |
-
model_url = "aipicasso/cool-japan-diffusion-2-1-0" # Замените на свою полную ссылку на модель
|
| 51 |
-
pipe = load_model(model_url)
|
| 52 |
-
refiner = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0", use_safetensors=True).to(device)
|
| 53 |
-
upscaler = DiffusionPipeline.from_pretrained("stabilityai/sd-x2-latent-upscaler", torch_dtype=torch.float16, use_safetensors=True).to(device)
|
| 54 |
-
def genie(prompt, negative_prompt, height, width, scale, steps, seed, upscaling):
|
| 55 |
-
generator = torch.Generator(device=device).manual_seed(seed)
|
| 56 |
-
int_image = pipe(prompt, negative_prompt=negative_prompt, num_inference_steps=steps, height=height, width=width, guidance_scale=scale, num_images_per_prompt=1, generator=generator, output_type="latent").images
|
| 57 |
-
if upscaling == 'Yes':
|
| 58 |
-
image = refiner(prompt=prompt, image=int_image).images[0]
|
| 59 |
-
upscaled = upscaler(prompt=prompt, negative_prompt=negative_prompt, image=image, num_inference_steps=5, guidance_scale=0).images[0]
|
| 60 |
-
torch.cuda.empty_cache()
|
| 61 |
-
return (image, upscaled)
|
| 62 |
-
else:
|
| 63 |
-
image = refiner(prompt=prompt, negative_prompt=negative_prompt, image=int_image).images[0]
|
| 64 |
-
torch.cuda.empty_cache()
|
| 65 |
-
return (image, image)
|
| 66 |
-
|
| 67 |
-
gr.Interface(fn=genie, inputs=[gr.Textbox(label='Что вы хотите, чтобы ИИ генерировал'),
|
| 68 |
-
gr.Textbox(label='Что вы не хотите, чтобы ИИ генерировал'),
|
| 69 |
-
gr.Slider(512, 1024, 768, step=128, label='Высота картинки'),
|
| 70 |
-
gr.Slider(512, 1024, 768, step=128, label='Ширина картинки'),
|
| 71 |
-
gr.Slider(1, 15, 10, step=.25, label='Шкала расхождения'),
|
| 72 |
-
gr.Slider(25, maximum=100, value=50, step=25, label='Количество итераций'),
|
| 73 |
-
gr.Slider(minimum=1, step=1, maximum=999999999999999999, randomize=True, label='Зерно'),
|
| 74 |
-
gr.Radio(['Да', 'Нет'], label='Ремастеринг?')],
|
| 75 |
-
outputs=['image', 'image'],
|
| 76 |
-
title="Стабильная Диффузия - Japan-SD-2-1-0",
|
| 77 |
-
description="",
|
| 78 |
-
article="").launch(debug=True, max_threads=80)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
import numpy as np
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
from diffusers import DiffusionPipeline
|
| 6 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 7 |
+
def resize(height, width, img):
|
| 8 |
+
img = Image.open(img)
|
| 9 |
+
img = img.resize((height, width))
|
| 10 |
+
return img
|
| 11 |
+
def infer(source_img, prompt, negative_prompt, height, width, guide, steps, seed, strength):
|
| 12 |
+
generator = torch.Generator(device).manual_seed(seed)
|
| 13 |
+
source_image = resize(height, width, source_img)
|
| 14 |
+
source_image.save('source.png')
|
| 15 |
+
model_url = "https://civitai.com/api/download/models/39885"
|
| 16 |
+
pipe = DiffusionPipeline.from_pretrained(model_url, torch_dtype=torch.float16) if torch.cuda.is_available() else DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-1.0")
|
| 17 |
+
pipe = pipe.to(device)
|
| 18 |
+
image = pipe(prompt, negative_prompt=negative_prompt, image=source_image, strength=strength, guidance_scale=guide, num_inference_steps=steps).images[0]
|
| 19 |
+
return image
|
| 20 |
+
gr.Interface(
|
| 21 |
+
fn=infer,
|
| 22 |
+
inputs=[
|
| 23 |
+
gr.Image(source="upload", type="filepath", label="Raw Image. Must Be .png"),
|
| 24 |
+
gr.Textbox(label='Что вы хотит��, чтобы ИИ генерировал'),
|
| 25 |
+
gr.Textbox(label='Что вы не хотите, чтобы ИИ генерировал'),
|
| 26 |
+
gr.Slider(512, 1024, 768, step=1, label='Ширина картинки'),
|
| 27 |
+
gr.Slider(512, 1024, 768, step=1, label='Высота картинки'),
|
| 28 |
+
gr.Slider(2, 15, value=7, label='Шкала расхождения'),
|
| 29 |
+
gr.Slider(1, 25, value=10, step=1, label='Количество итераций'),
|
| 30 |
+
gr.Slider(label="Зерно", minimum=0, maximum=987654321987654321, step=1, randomize=True),
|
| 31 |
+
gr.Slider(label='Сила', minimum=0, maximum=1, step=.05, value=.5),
|
| 32 |
+
],
|
| 33 |
+
outputs='image',
|
| 34 |
+
title="Стабильная Диффузия - Dreamlike-Photoreal-2.0",
|
| 35 |
+
article=""
|
| 36 |
+
).launch(debug=True, max_threads=80)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|