Update app.py
Browse files
app.py
CHANGED
|
@@ -1,80 +1,44 @@
|
|
| 1 |
-
幫我移除不需要的註解
|
| 2 |
-
|
| 3 |
import gradio as gr
|
| 4 |
-
import numpy as np
|
| 5 |
-
import random
|
| 6 |
-
from diffusers import DiffusionPipeline
|
| 7 |
-
from optimum.intel.openvino.modeling_diffusion import OVModelVaeDecoder, OVBaseModel, OVStableDiffusionPipeline
|
| 8 |
import torch
|
| 9 |
-
from
|
| 10 |
-
import openvino.runtime as ov
|
| 11 |
-
from typing import Optional, Dict
|
| 12 |
-
#from diffusers import EulerAncestralDiscreteScheduler, LCMScheduler
|
| 13 |
-
|
| 14 |
-
#LCMScheduler 產生垃圾
|
| 15 |
-
#EulerDiscreteScheduler 尚可
|
| 16 |
-
#EulerAncestralDiscreteScheduler 很不錯chatgpt推薦
|
| 17 |
-
|
| 18 |
|
| 19 |
model_id = "hsuwill000/Fluently-v4-LCM-openvino"
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
#512*512 好 太大會變形
|
| 25 |
-
HIGH=1024
|
| 26 |
-
WIDTH=512
|
| 27 |
|
| 28 |
batch_size = -1
|
| 29 |
|
| 30 |
pipe = OVStableDiffusionPipeline.from_pretrained(
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
safety_checker=None,
|
| 39 |
-
use_safetensors=False,
|
| 40 |
-
)
|
| 41 |
print(pipe.scheduler.compatibles)
|
| 42 |
-
#pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
|
| 43 |
-
#pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
|
| 44 |
-
|
| 45 |
-
#pipe.load_lora_weights(adapter_id)
|
| 46 |
-
#pipe.fuse_lora()
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
pipe.reshape( batch_size=-1, height=HIGH, width=WIDTH, num_images_per_prompt=1)
|
| 50 |
-
#pipe.load_textual_inversion("./badhandv4.pt", "badhandv4")
|
| 51 |
-
#pipe.load_textual_inversion("./Konpeto.pt", "Konpeto")
|
| 52 |
-
#<shigure-ui-style>
|
| 53 |
-
#pipe.load_textual_inversion("sd-concepts-library/shigure-ui-style")
|
| 54 |
-
#pipe.load_textual_inversion("sd-concepts-library/ruan-jia")
|
| 55 |
-
#pipe.load_textual_inversion("sd-concepts-library/agm-style-nao")
|
| 56 |
|
|
|
|
| 57 |
|
| 58 |
pipe.compile()
|
| 59 |
|
| 60 |
-
prompt=""
|
| 61 |
-
negative_prompt="EasyNegative, "
|
| 62 |
-
|
| 63 |
-
def infer(prompt,negative_prompt):
|
| 64 |
|
|
|
|
| 65 |
image = pipe(
|
| 66 |
-
prompt
|
| 67 |
-
negative_prompt
|
| 68 |
-
width
|
| 69 |
-
height
|
| 70 |
guidance_scale=1.0,
|
| 71 |
num_inference_steps=8,
|
| 72 |
num_images_per_prompt=1,
|
| 73 |
-
).images[0]
|
| 74 |
|
| 75 |
return image
|
| 76 |
|
| 77 |
-
|
| 78 |
examples = [
|
| 79 |
"(Digital art, highres, best quality, 8K, masterpiece, anime screencap, perfect eyes:1.4, ultra detailed:1.5),1girl,flat chest,short messy pink hair,blue eyes,tall,thick thighs,light blue hoodie,collar,light blue shirt,black sport shorts,bulge,black thigh highs,femboy,okoto no ko,smiling,blushing,looking at viewer,inside,livingroom,sitting on couch,nighttime,dark,hand_to_mouth,",
|
| 80 |
"1girl, silver hair, symbol-shaped pupils, yellow eyes, smiling, light particles, light rays, wallpaper, star guardian, serious face, red inner hair, power aura, grandmaster1, golden and white clothes",
|
|
@@ -82,14 +46,13 @@ examples = [
|
|
| 82 |
"((colofrul:1.7)),((best quality)), ((masterpiece)), ((ultra-detailed)), (illustration), (detailed light), (an extremely delicate and beautiful),incredibly_absurdres,(glowing),(1girl:1.7),solo,a beautiful girl,(((cowboy shot))),standding,((Hosiery)),((beautiful off-shoulder lace-trimmed layered strapless dress+white stocking):1.25),((Belts)),(leg loops),((Hosiery)),((flower headdress)),((long white hair)),(((beautiful eyes))),BREAK,((english text)),(flower:1.35),(garden),(((border:1.75))),",
|
| 83 |
]
|
| 84 |
|
| 85 |
-
css="""
|
| 86 |
#col-container {
|
| 87 |
margin: 0 auto;
|
| 88 |
max-width: 520px;
|
| 89 |
}
|
| 90 |
"""
|
| 91 |
|
| 92 |
-
|
| 93 |
power_device = "CPU"
|
| 94 |
|
| 95 |
with gr.Blocks(css=css) as demo:
|
|
@@ -113,16 +76,16 @@ with gr.Blocks(css=css) as demo:
|
|
| 113 |
result = gr.Image(label="Result", show_label=False)
|
| 114 |
|
| 115 |
gr.Examples(
|
| 116 |
-
examples
|
| 117 |
-
fn
|
| 118 |
-
inputs
|
| 119 |
-
outputs
|
| 120 |
)
|
| 121 |
|
| 122 |
run_button.click(
|
| 123 |
-
fn
|
| 124 |
-
inputs
|
| 125 |
-
outputs
|
| 126 |
)
|
| 127 |
|
| 128 |
-
demo.queue().launch()
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import torch
|
| 3 |
+
from optimum.intel.openvino.modeling_diffusion import OVStableDiffusionPipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
model_id = "hsuwill000/Fluently-v4-LCM-openvino"
|
| 6 |
|
| 7 |
+
HIGH = 1024
|
| 8 |
+
WIDTH = 512
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
batch_size = -1
|
| 11 |
|
| 12 |
pipe = OVStableDiffusionPipeline.from_pretrained(
|
| 13 |
+
model_id,
|
| 14 |
+
compile=False,
|
| 15 |
+
ov_config={"CACHE_DIR": ""},
|
| 16 |
+
torch_dtype=torch.int8, # fast
|
| 17 |
+
safety_checker=None,
|
| 18 |
+
use_safetensors=False,
|
| 19 |
+
)
|
|
|
|
|
|
|
|
|
|
| 20 |
print(pipe.scheduler.compatibles)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
pipe.reshape(batch_size=-1, height=HIGH, width=WIDTH, num_images_per_prompt=1)
|
| 23 |
|
| 24 |
pipe.compile()
|
| 25 |
|
| 26 |
+
prompt = ""
|
| 27 |
+
negative_prompt = "EasyNegative, "
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
def infer(prompt, negative_prompt):
|
| 30 |
image = pipe(
|
| 31 |
+
prompt=prompt,
|
| 32 |
+
negative_prompt=negative_prompt,
|
| 33 |
+
width=WIDTH,
|
| 34 |
+
height=HIGH,
|
| 35 |
guidance_scale=1.0,
|
| 36 |
num_inference_steps=8,
|
| 37 |
num_images_per_prompt=1,
|
| 38 |
+
).images[0]
|
| 39 |
|
| 40 |
return image
|
| 41 |
|
|
|
|
| 42 |
examples = [
|
| 43 |
"(Digital art, highres, best quality, 8K, masterpiece, anime screencap, perfect eyes:1.4, ultra detailed:1.5),1girl,flat chest,short messy pink hair,blue eyes,tall,thick thighs,light blue hoodie,collar,light blue shirt,black sport shorts,bulge,black thigh highs,femboy,okoto no ko,smiling,blushing,looking at viewer,inside,livingroom,sitting on couch,nighttime,dark,hand_to_mouth,",
|
| 44 |
"1girl, silver hair, symbol-shaped pupils, yellow eyes, smiling, light particles, light rays, wallpaper, star guardian, serious face, red inner hair, power aura, grandmaster1, golden and white clothes",
|
|
|
|
| 46 |
"((colofrul:1.7)),((best quality)), ((masterpiece)), ((ultra-detailed)), (illustration), (detailed light), (an extremely delicate and beautiful),incredibly_absurdres,(glowing),(1girl:1.7),solo,a beautiful girl,(((cowboy shot))),standding,((Hosiery)),((beautiful off-shoulder lace-trimmed layered strapless dress+white stocking):1.25),((Belts)),(leg loops),((Hosiery)),((flower headdress)),((long white hair)),(((beautiful eyes))),BREAK,((english text)),(flower:1.35),(garden),(((border:1.75))),",
|
| 47 |
]
|
| 48 |
|
| 49 |
+
css = """
|
| 50 |
#col-container {
|
| 51 |
margin: 0 auto;
|
| 52 |
max-width: 520px;
|
| 53 |
}
|
| 54 |
"""
|
| 55 |
|
|
|
|
| 56 |
power_device = "CPU"
|
| 57 |
|
| 58 |
with gr.Blocks(css=css) as demo:
|
|
|
|
| 76 |
result = gr.Image(label="Result", show_label=False)
|
| 77 |
|
| 78 |
gr.Examples(
|
| 79 |
+
examples=examples,
|
| 80 |
+
fn=infer,
|
| 81 |
+
inputs=[prompt],
|
| 82 |
+
outputs=[result]
|
| 83 |
)
|
| 84 |
|
| 85 |
run_button.click(
|
| 86 |
+
fn=infer,
|
| 87 |
+
inputs=[prompt],
|
| 88 |
+
outputs=[result]
|
| 89 |
)
|
| 90 |
|
| 91 |
+
demo.queue().launch()
|