hsuwill000 commited on
Commit
05c60c3
·
verified ·
1 Parent(s): e6565c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -64
app.py CHANGED
@@ -1,78 +1,44 @@
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
- #from diffusers import EulerAncestralDiscreteScheduler, LCMScheduler
11
-
12
- #LCMScheduler 產生垃圾
13
- #EulerDiscreteScheduler 尚可
14
- #EulerAncestralDiscreteScheduler 很不錯chatgpt推薦
15
-
16
 
17
  model_id = "hsuwill000/Fluently-v4-LCM-openvino"
18
 
19
- #model_id = "spamsoms/LCM-anything-v5-openvino2"
20
- #adapter_id = "latent-consistency/lcm-lora-sdv1-5"
21
-
22
- #512*512 好 太大會變形
23
- HIGH=1024
24
- WIDTH=512
25
 
26
  batch_size = -1
27
 
28
  pipe = OVStableDiffusionPipeline.from_pretrained(
29
- model_id,
30
- compile = False,
31
- ov_config = {"CACHE_DIR":""},
32
- torch_dtype=torch.int8, #快
33
- #torch_dtype=torch.bfloat16, #中
34
- #variant="fp16",
35
- #torch_dtype=torch.IntTensor, #慢,
36
- safety_checker=None,
37
- use_safetensors=False,
38
- )
39
  print(pipe.scheduler.compatibles)
40
- #pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
41
- #pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
42
-
43
- #pipe.load_lora_weights(adapter_id)
44
- #pipe.fuse_lora()
45
-
46
-
47
- pipe.reshape( batch_size=-1, height=HIGH, width=WIDTH, num_images_per_prompt=1)
48
- #pipe.load_textual_inversion("./badhandv4.pt", "badhandv4")
49
- #pipe.load_textual_inversion("./Konpeto.pt", "Konpeto")
50
- #<shigure-ui-style>
51
- #pipe.load_textual_inversion("sd-concepts-library/shigure-ui-style")
52
- #pipe.load_textual_inversion("sd-concepts-library/ruan-jia")
53
- #pipe.load_textual_inversion("sd-concepts-library/agm-style-nao")
54
 
 
55
 
56
  pipe.compile()
57
 
58
- prompt=""
59
- negative_prompt="EasyNegative, "
60
-
61
- def infer(prompt,negative_prompt):
62
 
 
63
  image = pipe(
64
- prompt = prompt,
65
- negative_prompt = negative_prompt,
66
- width = WIDTH,
67
- height = HIGH,
68
  guidance_scale=1.0,
69
- num_inference_steps=8,
70
  num_images_per_prompt=1,
71
- ).images[0]
72
 
73
  return image
74
 
75
-
76
  examples = [
77
  "(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,",
78
  "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",
@@ -80,14 +46,13 @@ examples = [
80
  "((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))),",
81
  ]
82
 
83
- css="""
84
  #col-container {
85
  margin: 0 auto;
86
  max-width: 520px;
87
  }
88
  """
89
 
90
-
91
  power_device = "CPU"
92
 
93
  with gr.Blocks(css=css) as demo:
@@ -108,19 +73,28 @@ with gr.Blocks(css=css) as demo:
108
  )
109
  run_button = gr.Button("Run", scale=0)
110
 
 
 
 
 
 
 
 
 
 
111
  result = gr.Image(label="Result", show_label=False)
112
 
113
  gr.Examples(
114
- examples = examples,
115
- fn = infer,
116
- inputs = [prompt],
117
- outputs = [result]
118
  )
119
 
120
  run_button.click(
121
- fn = infer,
122
- inputs = [prompt],
123
- outputs = [result]
124
  )
125
 
126
- 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, num_inference_steps):
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=num_inference_steps,
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:
 
73
  )
74
  run_button = gr.Button("Run", scale=0)
75
 
76
+ # Slider for num_inference_steps
77
+ num_inference_steps_slider = gr.Slider(
78
+ minimum=1,
79
+ maximum=30,
80
+ step=1,
81
+ value=4,
82
+ label="Number of Inference Steps"
83
+ )
84
+
85
  result = gr.Image(label="Result", show_label=False)
86
 
87
  gr.Examples(
88
+ examples=examples,
89
+ fn=infer,
90
+ inputs=[prompt, num_inference_steps_slider],
91
+ outputs=[result]
92
  )
93
 
94
  run_button.click(
95
+ fn=infer,
96
+ inputs=[prompt, num_inference_steps_slider],
97
+ outputs=[result]
98
  )
99
 
100
+ demo.queue().launch()