Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
import random
|
| 4 |
+
from diffusers import DiffusionPipeline
|
| 5 |
+
from optimum.intel.openvino.modeling_diffusion import OVModelVaeDecoder, OVBaseModel, OVStableDiffusionPipeline
|
| 6 |
+
import torch
|
| 7 |
+
from huggingface_hub import snapshot_download
|
| 8 |
+
import openvino.runtime as ov
|
| 9 |
+
from typing import Optional, Dict
|
| 10 |
+
|
| 11 |
+
model_id = "hsuwill000/anything-v5-openvino"
|
| 12 |
+
|
| 13 |
+
#1024*512 記憶體不足
|
| 14 |
+
HIGH=512
|
| 15 |
+
WIDTH=512
|
| 16 |
+
|
| 17 |
+
batch_size = -1
|
| 18 |
+
|
| 19 |
+
pipe = OVStableDiffusionPipeline.from_pretrained(
|
| 20 |
+
model_id,
|
| 21 |
+
compile = False,
|
| 22 |
+
ov_config = {"CACHE_DIR":""},
|
| 23 |
+
torch_dtype=torch.int8, #快
|
| 24 |
+
#torch_dtype=torch.bfloat16, #中
|
| 25 |
+
#variant="fp16",
|
| 26 |
+
#torch_dtype=torch.IntTensor, #慢
|
| 27 |
+
use_safetensors=False,
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
pipe.reshape( batch_size=-1, height=HIGH, width=WIDTH, num_images_per_prompt=1)
|
| 33 |
+
#pipe.load_textual_inversion("./badhandv4.pt", "badhandv4")
|
| 34 |
+
#pipe.load_textual_inversion("./Konpeto.pt", "Konpeto")
|
| 35 |
+
#<shigure-ui-style>
|
| 36 |
+
#pipe.load_textual_inversion("sd-concepts-library/shigure-ui-style")
|
| 37 |
+
#pipe.load_textual_inversion("sd-concepts-library/ruan-jia")
|
| 38 |
+
#pipe.load_textual_inversion("sd-concepts-library/agm-style-nao")
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
pipe.compile()
|
| 42 |
+
|
| 43 |
+
prompt=""
|
| 44 |
+
negative_prompt="(worst quality, low quality, lowres, loli, kid, child), zombie, interlocked fingers, large breasts, username, watermark,"
|
| 45 |
+
|
| 46 |
+
def infer(prompt,negative_prompt):
|
| 47 |
+
|
| 48 |
+
image = pipe(
|
| 49 |
+
prompt = prompt,
|
| 50 |
+
negative_prompt = negative_prompt,
|
| 51 |
+
width = WIDTH,
|
| 52 |
+
height = HIGH,
|
| 53 |
+
guidance_scale=1.0,
|
| 54 |
+
num_inference_steps=4,
|
| 55 |
+
num_images_per_prompt=1,
|
| 56 |
+
).images[0]
|
| 57 |
+
|
| 58 |
+
return image
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
examples = [
|
| 62 |
+
"Sailor Chibi Moon, Katsura Masakazu style,Close-up of face",
|
| 63 |
+
"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",
|
| 64 |
+
"masterpiece, best quality, highres booru, 1girl, solo, depth of field, rim lighting, flowers, petals, from above, crystals, butterfly, vegetation, aura, magic, hatsune miku, blush, slight smile, close-up, against wall,",
|
| 65 |
+
"(illustration, 8k CG, extremely detailed),(whimsical),catgirl,teenage girl,playing in the snow,winter wonderland,snow-covered trees,soft pastel colors,gentle lighting,sparkling snow,joyful,magical atmosphere,highly detailed,fluffy cat ears and tail,intricate winter clothing,shallow depth of field,watercolor techniques,close-up shot,slightly tilted angle,fairy tale architecture,nostalgic,playful,winter magic,(masterpiece:2),best quality,ultra highres,original,extremely detailed,perfect lighting,",
|
| 66 |
+
]
|
| 67 |
+
|
| 68 |
+
css="""
|
| 69 |
+
#col-container {
|
| 70 |
+
margin: 0 auto;
|
| 71 |
+
max-width: 520px;
|
| 72 |
+
}
|
| 73 |
+
"""
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
power_device = "CPU"
|
| 77 |
+
|
| 78 |
+
with gr.Blocks(css=css) as demo:
|
| 79 |
+
|
| 80 |
+
with gr.Column(elem_id="col-container"):
|
| 81 |
+
gr.Markdown(f"""
|
| 82 |
+
# Disty0/LCM_SoteMix {WIDTH}x{HIGH}
|
| 83 |
+
Currently running on {power_device}.
|
| 84 |
+
""")
|
| 85 |
+
|
| 86 |
+
with gr.Row():
|
| 87 |
+
prompt = gr.Text(
|
| 88 |
+
label="Prompt",
|
| 89 |
+
show_label=False,
|
| 90 |
+
max_lines=1,
|
| 91 |
+
placeholder="Enter your prompt",
|
| 92 |
+
container=False,
|
| 93 |
+
)
|
| 94 |
+
run_button = gr.Button("Run", scale=0)
|
| 95 |
+
|
| 96 |
+
result = gr.Image(label="Result", show_label=False)
|
| 97 |
+
|
| 98 |
+
gr.Examples(
|
| 99 |
+
examples = examples,
|
| 100 |
+
fn = infer,
|
| 101 |
+
inputs = [prompt],
|
| 102 |
+
outputs = [result]
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
run_button.click(
|
| 106 |
+
fn = infer,
|
| 107 |
+
inputs = [prompt],
|
| 108 |
+
outputs = [result]
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
demo.queue().launch()
|