None1145 commited on
Commit
40c0e85
1 Parent(s): d840e13

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -7
app.py CHANGED
@@ -4,12 +4,26 @@ import random
4
  from optimum.intel import OVStableDiffusionXLPipeline
5
  import torch
6
 
 
7
  model_id = "None1145/noobai-XL-Vpred-0.65s-openvino"
8
  pipe = OVStableDiffusionXLPipeline.from_pretrained(model_id)
9
 
 
 
 
 
10
  MAX_SEED = np.iinfo(np.int32).max
11
  MAX_IMAGE_SIZE = 2048
12
 
 
 
 
 
 
 
 
 
 
13
  def infer(
14
  prompt,
15
  negative_prompt,
@@ -21,11 +35,19 @@ def infer(
21
  num_inference_steps,
22
  progress=gr.Progress(track_tqdm=True),
23
  ):
 
 
24
  if randomize_seed:
25
  seed = random.randint(0, MAX_SEED)
26
 
27
  generator = torch.Generator().manual_seed(seed)
28
 
 
 
 
 
 
 
29
  image = pipe(
30
  prompt=prompt,
31
  negative_prompt=negative_prompt,
@@ -40,12 +62,15 @@ def infer(
40
 
41
 
42
  examples = [
43
- "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
44
- "An astronaut riding a green horse",
45
- "A delicious ceviche cheesecake slice",
 
46
  ]
47
 
48
  with gr.Blocks() as img:
 
 
49
  with gr.Column(elem_id="col-container"):
50
  with gr.Row():
51
  prompt = gr.Text(
@@ -84,7 +109,7 @@ with gr.Blocks() as img:
84
  minimum=512,
85
  maximum=MAX_IMAGE_SIZE,
86
  step=32,
87
- value=832, # Replace with defaults that work for your model
88
  )
89
 
90
  height = gr.Slider(
@@ -92,7 +117,7 @@ with gr.Blocks() as img:
92
  minimum=512,
93
  maximum=MAX_IMAGE_SIZE,
94
  step=32,
95
- value=1216, # Replace with defaults that work for your model
96
  )
97
 
98
  with gr.Row():
@@ -101,7 +126,7 @@ with gr.Blocks() as img:
101
  minimum=0.0,
102
  maximum=10.0,
103
  step=0.1,
104
- value=5.0, # Replace with defaults that work for your model
105
  )
106
 
107
  num_inference_steps = gr.Slider(
@@ -109,10 +134,23 @@ with gr.Blocks() as img:
109
  minimum=1,
110
  maximum=60,
111
  step=1,
112
- value=28, # Replace with defaults that work for your model
113
  )
114
 
115
  gr.Examples(examples=examples, inputs=[prompt])
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  gr.on(
117
  triggers=[run_button.click, prompt.submit],
118
  fn=infer,
 
4
  from optimum.intel import OVStableDiffusionXLPipeline
5
  import torch
6
 
7
+ # Default model ID
8
  model_id = "None1145/noobai-XL-Vpred-0.65s-openvino"
9
  pipe = OVStableDiffusionXLPipeline.from_pretrained(model_id)
10
 
11
+ # Initialize previous dimensions
12
+ prev_height = None
13
+ prev_width = None
14
+
15
  MAX_SEED = np.iinfo(np.int32).max
16
  MAX_IMAGE_SIZE = 2048
17
 
18
+ def reload_model(new_model_id):
19
+ global pipe, model_id
20
+ model_id = new_model_id
21
+ try:
22
+ pipe = OVStableDiffusionXLPipeline.from_pretrained(model_id)
23
+ return f"Model successfully loaded: {model_id}"
24
+ except Exception as e:
25
+ return f"Failed to load model: {str(e)}"
26
+
27
  def infer(
28
  prompt,
29
  negative_prompt,
 
35
  num_inference_steps,
36
  progress=gr.Progress(track_tqdm=True),
37
  ):
38
+ global prev_width, prev_height, pipe
39
+
40
  if randomize_seed:
41
  seed = random.randint(0, MAX_SEED)
42
 
43
  generator = torch.Generator().manual_seed(seed)
44
 
45
+ if prev_width != width or prev_height != height:
46
+ pipe.reshape(batch_size=1, height=height, width=width, num_images_per_prompt=1)
47
+ pipe.compile()
48
+ prev_width = width
49
+ prev_height = height
50
+
51
  image = pipe(
52
  prompt=prompt,
53
  negative_prompt=negative_prompt,
 
62
 
63
 
64
  examples = [
65
+ "masterpiece,best quality,newest,absurdres,highres,takarada rikka,1girl,solo,artist:koruri,artist:haoni,artist:deadnooodles,artist:mishima_kurone,artist:yd orange maru,year 2023,black hair,smile,looking at viewer,one eye closed,pov,close-up,blue eyes,medium hair,pointing at viewer,orange scrunchie,:t,white shirt,school uniform,standing,cowboy shot,classroom,bent over,head rest,head tilt,face focus,",
66
+ "masterpiece,best quality,artist:john_kafka,artist:nixeu,artist:quasarcake, ,gritty,marcille donato,1girl, abstract background, ambrosia \(dungeon meshi\), backpack, bag, belt, belt pouch, blonde hair, blue capelet, blue shirt, book, book holster, capelet, elf, food, food in mouth, green eyes, grimoire, hair ribbon, holding, holding staff, kebab, multicolored background, pants, pointy ears, ponytail, pouch, red ribbon, ribbon, shirt, sideways glance, skewer, sleeping bag, sprout, staff, v-shaped eyebrows, white pants",
67
+ "kazusa \(blue archive\), reisa \(blue archive\),sfw,very awa,highres,absurdres,incredibly absurdres,masterpiece,oil painting \(medium\),Yasuda Akira,(henriiku (ahemaru):1.3),armored core,artist:ciloranko,artist:sho sho lwlw,(as109:0.7),ink (medium),, (2girls:1.5), black neckerchief, blue hair, buttons, double-breasted, drooling, grey serafuku, halo, light blue hair, midriff peek, multicolored hair, neckerchief, nose bubble, pink hair, pink halo, pleated skirt, refraction, saliva, school uniform, serafuku,skirt, sleeping, socks, star halo, striped clothes, striped socks,",
68
+ "1girl,,camellya \(wuthering waves\),,::, (by kana616:0.8), [(by hen-tie:1.3)|(by kagami_\(galgamesion\):1.2)], (by kinokohime:1.2), (by yatsuha_\(hachiyoh\):0.8), year 2024,,parted lips, looking at animal, upper body, profile, holding, centauroid, holding bouquet,,streaked hair, hair flower, multicolored hair, breasts, hair ornament, hair between eyes, jewelry, twintails, white hair,,animal ears, deer girl, flower wreath, white bird, off-shoulder shirt, shirt, sleeves past wrists, deer ears, off shoulder, head wreath, long sleeves,,blurry background, depth of field, bokeh, planted sword, red background, planted, red theme, bird, grass, flower, very awa, masterpiece, best quality, newest, highres, absurdres",
69
  ]
70
 
71
  with gr.Blocks() as img:
72
+ gr.Markdown("OpenVINO Text to Image")
73
+
74
  with gr.Column(elem_id="col-container"):
75
  with gr.Row():
76
  prompt = gr.Text(
 
109
  minimum=512,
110
  maximum=MAX_IMAGE_SIZE,
111
  step=32,
112
+ value=832,
113
  )
114
 
115
  height = gr.Slider(
 
117
  minimum=512,
118
  maximum=MAX_IMAGE_SIZE,
119
  step=32,
120
+ value=1216,
121
  )
122
 
123
  with gr.Row():
 
126
  minimum=0.0,
127
  maximum=10.0,
128
  step=0.1,
129
+ value=5.0,
130
  )
131
 
132
  num_inference_steps = gr.Slider(
 
134
  minimum=1,
135
  maximum=60,
136
  step=1,
137
+ value=28,
138
  )
139
 
140
  gr.Examples(examples=examples, inputs=[prompt])
141
+
142
+ gr.Markdown("### Model Reload")
143
+ with gr.Row():
144
+ new_model_id = gr.Text(label="New Model ID", placeholder="Enter new model ID")
145
+ reload_button = gr.Button("Reload Model", variant="primary")
146
+ reload_status = gr.Text(label="Status", interactive=False)
147
+
148
+ reload_button.click(
149
+ fn=reload_model,
150
+ inputs=new_model_id,
151
+ outputs=reload_status,
152
+ )
153
+
154
  gr.on(
155
  triggers=[run_button.click, prompt.submit],
156
  fn=infer,