hsuwill000 commited on
Commit
1c3b91b
·
verified ·
1 Parent(s): 0614b80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -65
app.py CHANGED
@@ -8,77 +8,61 @@ from huggingface_hub import snapshot_download
8
  import openvino.runtime as ov
9
  from typing import Optional, Dict
10
 
11
-
12
-
13
  model_id = "Disty0/LCM_SoteMix"
14
- #model_id = "Disty0/sotediffusion-v2" #不可
15
 
16
- #1024*512 記憶體不足
17
- HIGH=768
18
- WIDTH=512
19
 
20
  batch_size = -1
21
- """
22
- class CustomOVModelVaeDecoder(OVModelVaeDecoder):
23
- def __init__(
24
- self, model: ov.Model, parent_model: OVBaseModel, ov_config: Optional[Dict[str, str]] = None, model_dir: str = None,
25
- ):
26
- super(OVModelVaeDecoder, self).__init__(model, parent_model, ov_config, "vae_decoder", model_dir)
27
- """
28
 
29
  pipe = OVStableDiffusionPipeline.from_pretrained(
30
- model_id,
31
- compile = False,
32
- ov_config = {"CACHE_DIR":""},
33
- torch_dtype=torch.int8, #快
34
- #torch_dtype=torch.bfloat16, #中
35
- #variant="fp16",
36
- #torch_dtype=torch.IntTensor, #慢
37
- use_safetensors=False,
38
- )
39
 
40
  taesd_dir = snapshot_download(repo_id="deinferno/taesd-openvino")
41
- """
42
- pipe.vae_decoder = CustomOVModelVaeDecoder(model = OVBaseModel.load_model(f"{taesd_dir}/vae_decoder/openvino_model.xml"),
43
- parent_model = pipe,
44
- model_dir = taesd_dir
45
- )
46
- """
47
  pipe.vae_decoder = OVModelVaeDecoder(
48
- model=OVBaseModel.load_model(f"{taesd_dir}/vae_decoder/openvino_model.xml"),
49
- parent_model=pipe,
50
- ov_config=None, # 假設不需要配置,或者替換為實際配置
51
- model_type="vae_decoder", # 可以保持原來的名稱,表示模型是 vae_decoder 類型
52
  model_dir=taesd_dir
53
  )
54
 
55
-
56
- pipe.reshape( batch_size=-1, height=HIGH, width=WIDTH, num_images_per_prompt=1)
57
- #pipe.load_textual_inversion("./badhandv4.pt", "badhandv4")
58
- #pipe.load_textual_inversion("./Konpeto.pt", "Konpeto")
59
- #<shigure-ui-style>
60
- #pipe.load_textual_inversion("sd-concepts-library/shigure-ui-style")
61
- #pipe.load_textual_inversion("sd-concepts-library/ruan-jia")
62
- #pipe.load_textual_inversion("sd-concepts-library/agm-style-nao")
63
-
64
 
65
  pipe.compile()
66
 
67
- prompt=""
68
- negative_prompt="(worst quality, low quality, lowres), zombie, interlocked fingers,"
69
-
70
- def infer(prompt,negative_prompt):
71
 
 
72
  image = pipe(
73
- prompt = prompt,
74
- negative_prompt = negative_prompt,
75
- width = WIDTH,
76
- height = HIGH,
77
  guidance_scale=1.0,
78
  num_inference_steps=4,
79
  num_images_per_prompt=1,
80
- ).images[0]
81
-
82
  return image
83
 
84
 
@@ -89,24 +73,23 @@ examples = [
89
  "(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,",
90
  ]
91
 
92
- css="""
93
  #col-container {
94
  margin: 0 auto;
95
  max-width: 520px;
96
  }
97
  """
98
 
99
-
100
  power_device = "CPU"
101
 
102
  with gr.Blocks(css=css) as demo:
103
-
104
  with gr.Column(elem_id="col-container"):
105
  gr.Markdown(f"""
106
  # Disty0/LCM_SoteMix {WIDTH}x{HIGH}
107
  Currently running on {power_device}.
108
  """)
109
-
110
  with gr.Row():
111
  prompt = gr.Text(
112
  label="Prompt",
@@ -114,22 +97,22 @@ with gr.Blocks(css=css) as demo:
114
  max_lines=1,
115
  placeholder="Enter your prompt",
116
  container=False,
117
- )
118
  run_button = gr.Button("Run", scale=0)
119
-
120
  result = gr.Image(label="Result", show_label=False)
121
 
122
  gr.Examples(
123
- examples = examples,
124
- fn = infer,
125
- inputs = [prompt],
126
- outputs = [result]
127
  )
128
 
129
  run_button.click(
130
- fn = infer,
131
- inputs = [prompt],
132
- outputs = [result]
133
  )
134
 
135
- demo.queue().launch()
 
8
  import openvino.runtime as ov
9
  from typing import Optional, Dict
10
 
 
 
11
  model_id = "Disty0/LCM_SoteMix"
12
+ # model_id = "Disty0/sotediffusion-v2" #不可
13
 
14
+ # 1024*512 記憶體不足
15
+ HIGH = 768
16
+ WIDTH = 512
17
 
18
  batch_size = -1
 
 
 
 
 
 
 
19
 
20
  pipe = OVStableDiffusionPipeline.from_pretrained(
21
+ model_id,
22
+ compile=False,
23
+ ov_config={"CACHE_DIR": ""},
24
+ torch_dtype=torch.int8, #
25
+ # torch_dtype=torch.bfloat16, # 中
26
+ # variant="fp16",
27
+ # torch_dtype=torch.IntTensor, # 慢
28
+ use_safetensors=False,
29
+ )
30
 
31
  taesd_dir = snapshot_download(repo_id="deinferno/taesd-openvino")
32
+
33
+ # 這裡直接使用 OVModelVaeDecoder,而不是自訂的 CustomOVModelVaeDecoder
 
 
 
 
34
  pipe.vae_decoder = OVModelVaeDecoder(
35
+ model=OVBaseModel.load_model(f"{taesd_dir}/vae_decoder/openvino_model.xml"),
36
+ parent_model=pipe,
37
+ ov_config=None, # 如果沒有配置,傳入 None
38
+ model_type="vae_decoder", # 保持與原本類型一致
39
  model_dir=taesd_dir
40
  )
41
 
42
+ pipe.reshape(batch_size=-1, height=HIGH, width=WIDTH, num_images_per_prompt=1)
43
+ # pipe.load_textual_inversion("./badhandv4.pt", "badhandv4")
44
+ # pipe.load_textual_inversion("./Konpeto.pt", "Konpeto")
45
+ # <shigure-ui-style>
46
+ # pipe.load_textual_inversion("sd-concepts-library/shigure-ui-style")
47
+ # pipe.load_textual_inversion("sd-concepts-library/ruan-jia")
48
+ # pipe.load_textual_inversion("sd-concepts-library/agm-style-nao")
 
 
49
 
50
  pipe.compile()
51
 
52
+ prompt = ""
53
+ negative_prompt = "(worst quality, low quality, lowres), zombie, interlocked fingers,"
 
 
54
 
55
+ def infer(prompt, negative_prompt):
56
  image = pipe(
57
+ prompt=prompt,
58
+ negative_prompt=negative_prompt,
59
+ width=WIDTH,
60
+ height=HIGH,
61
  guidance_scale=1.0,
62
  num_inference_steps=4,
63
  num_images_per_prompt=1,
64
+ ).images[0]
65
+
66
  return image
67
 
68
 
 
73
  "(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,",
74
  ]
75
 
76
+ css = """
77
  #col-container {
78
  margin: 0 auto;
79
  max-width: 520px;
80
  }
81
  """
82
 
 
83
  power_device = "CPU"
84
 
85
  with gr.Blocks(css=css) as demo:
86
+
87
  with gr.Column(elem_id="col-container"):
88
  gr.Markdown(f"""
89
  # Disty0/LCM_SoteMix {WIDTH}x{HIGH}
90
  Currently running on {power_device}.
91
  """)
92
+
93
  with gr.Row():
94
  prompt = gr.Text(
95
  label="Prompt",
 
97
  max_lines=1,
98
  placeholder="Enter your prompt",
99
  container=False,
100
+ )
101
  run_button = gr.Button("Run", scale=0)
102
+
103
  result = gr.Image(label="Result", show_label=False)
104
 
105
  gr.Examples(
106
+ examples=examples,
107
+ fn=infer,
108
+ inputs=[prompt],
109
+ outputs=[result]
110
  )
111
 
112
  run_button.click(
113
+ fn=infer,
114
+ inputs=[prompt],
115
+ outputs=[result]
116
  )
117
 
118
+ demo.queue().launch()