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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -38
app.py CHANGED
@@ -1,44 +1,80 @@
 
 
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,13 +82,14 @@ examples = [
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,28 +110,19 @@ 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()
 
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 huggingface_hub import snapshot_download
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
+ #model_id = "spamsoms/LCM-anything-v5-openvino2"
22
+ #adapter_id = "latent-consistency/lcm-lora-sdv1-5"
23
+
24
+ #512*512 好 太大會變形
25
+ HIGH=1024
26
+ WIDTH=512
27
 
28
  batch_size = -1
29
 
30
  pipe = OVStableDiffusionPipeline.from_pretrained(
31
+ model_id,
32
+ compile = False,
33
+ ov_config = {"CACHE_DIR":""},
34
+ torch_dtype=torch.int8, #快
35
+ #torch_dtype=torch.bfloat16, #中
36
+ #variant="fp16",
37
+ #torch_dtype=torch.IntTensor, #慢,
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 = prompt,
67
+ negative_prompt = negative_prompt,
68
+ width = WIDTH,
69
+ height = HIGH,
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
  "((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:
 
110
  )
111
  run_button = gr.Button("Run", scale=0)
112
 
 
 
 
 
 
 
 
 
 
113
  result = gr.Image(label="Result", show_label=False)
114
 
115
  gr.Examples(
116
+ examples = examples,
117
+ fn = infer,
118
+ inputs = [prompt],
119
+ outputs = [result]
120
  )
121
 
122
  run_button.click(
123
+ fn = infer,
124
+ inputs = [prompt],
125
+ outputs = [result]
126
  )
127
 
128
+ demo.queue().launch()