Kpenciler commited on
Commit
b19f447
β€’
1 Parent(s): 4d1d4c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -24
app.py CHANGED
@@ -1,6 +1,3 @@
1
- import numpy as np
2
- import gradio as gr
3
-
4
  import os
5
  from io import BytesIO
6
 
@@ -10,17 +7,20 @@ import replicate
10
  import requests
11
  from PIL import Image
12
 
13
-
14
- def generate(prompt: str, secret_key: str, steps: int = 25, seed: int = -1):
 
15
  """
16
  γƒ—γƒ­γƒ³γƒ—γƒˆγ‹γ‚‰η”Ÿζˆη”»εƒ(PIL.Image.open)を取得
17
  """
18
  if secret_key == os.environ["SECRET_KEY"]:
19
  output = replicate.run(
20
- "stability-ai/sdxl:2b017d9b67edd2ee1401238df49d75da53c523f36e363881e057f5dc3ed3c5b2",
21
- input={"prompt": prompt,
22
- "seed": seed if seed != -1 else np.random.randint(1, 1001),
23
- "num_inference_steps": steps},
 
 
24
  )
25
  # γƒͺンク取得
26
  png_link = output[0]
@@ -31,32 +31,42 @@ def generate(prompt: str, secret_key: str, steps: int = 25, seed: int = -1):
31
  return img
32
 
33
 
34
-
35
- default_steps = 25
36
  examples = [
 
 
 
 
37
  # ["An astronaut riding a rainbow unicorn, cinematic, dramatic", ""],
38
  # ["A robot painted as graffiti on a brick wall. a sidewalk is in front of the wall, and grass is growing out of cracks in the concrete.", ""],
39
  # ["Panda mad scientist mixing sparkling chemicals, artstation.", ""],
40
- ["An astronaut riding a rainbow unicorn, cinematic, dramatic"],
41
- ["photo of a rhino dressed suit and tie sitting at a table in a bar with a bar stools, award winning photography."],
42
- ["a giant monster hybrid of dragon and spider, in dark dense foggy forest"],
43
- ["a man in a space suit playing a piano, highly detailed illustration, full color illustration, very detailed illustration"],
44
- ]
 
 
 
 
45
 
46
  with gr.Blocks(title="Stable Diffusion XL (SDXL 1.0)") as demo:
47
  with gr.Row():
48
  with gr.Column(scale=1, min_width=600):
49
- gr_prompt = gr.Textbox(label='γƒ—γƒ­γƒ³γƒ—γƒˆ')
50
- gr_password = gr.Textbox(label='パスワード')
51
  gr_generate_button = gr.Button("η”Ÿζˆ")
52
- with gr.Accordion("advanced settings", open=False):
53
- gr_steps = gr.Number(label='steps', value=default_steps)
54
- gr_seed = gr.Number(label='seed', value=-1)
55
  with gr.Column(scale=1, min_width=600):
56
  gr_image = gr.Image()
57
  # examples=examples
58
- gr_generate_button.click(generate, inputs=[gr_prompt, gr_password, gr_steps, gr_seed], outputs=[gr_image])
 
 
 
 
59
  with gr.Row():
60
- gr.Examples(examples, inputs=[gr_prompt])
61
 
62
- demo.launch()
 
 
 
 
1
  import os
2
  from io import BytesIO
3
 
 
7
  import requests
8
  from PIL import Image
9
 
10
+ model_id = "stability-ai/sdxl:2b017d9b67edd2ee1401238df49d75da53c523f36e363881e057f5dc3ed3c5b2"
11
+ default_steps = 25
12
+ def generate(prompt: str, secret_key: str):
13
  """
14
  γƒ—γƒ­γƒ³γƒ—γƒˆγ‹γ‚‰η”Ÿζˆη”»εƒ(PIL.Image.open)を取得
15
  """
16
  if secret_key == os.environ["SECRET_KEY"]:
17
  output = replicate.run(
18
+ model_id,
19
+ input={
20
+ "prompt": prompt,
21
+ "seed": -1,
22
+ "num_inference_steps": default_steps,
23
+ },
24
  )
25
  # γƒͺンク取得
26
  png_link = output[0]
 
31
  return img
32
 
33
 
 
 
34
  examples = [
35
+ ["station"],
36
+ ["station, ghibli style"],
37
+ ["Elon Musk"],
38
+ ["Elon Musk playing Shogi"],
39
  # ["An astronaut riding a rainbow unicorn, cinematic, dramatic", ""],
40
  # ["A robot painted as graffiti on a brick wall. a sidewalk is in front of the wall, and grass is growing out of cracks in the concrete.", ""],
41
  # ["Panda mad scientist mixing sparkling chemicals, artstation.", ""],
42
+ # ["An astronaut riding a rainbow unicorn, cinematic, dramatic"],
43
+ # [
44
+ # "photo of a rhino dressed suit and tie sitting at a table in a bar with a bar stools, award winning photography."
45
+ # ],
46
+ # ["a giant monster hybrid of dragon and spider, in dark dense foggy forest"],
47
+ # [
48
+ # "a man in a space suit playing a piano, highly detailed illustration, full color illustration, very detailed illustration"
49
+ # ],
50
+ ]
51
 
52
  with gr.Blocks(title="Stable Diffusion XL (SDXL 1.0)") as demo:
53
  with gr.Row():
54
  with gr.Column(scale=1, min_width=600):
55
+ gr_prompt = gr.Textbox(label="γƒ—γƒ­γƒ³γƒ—γƒˆ")
56
+ gr_password = gr.Textbox(label="パスワード")
57
  gr_generate_button = gr.Button("η”Ÿζˆ")
58
+ # with gr.Accordion("advanced settings", open=False):
59
+ # gr_steps = gr.Number(label="steps", value=default_steps)
60
+ # gr_seed = gr.Number(label="seed", value=-1)
61
  with gr.Column(scale=1, min_width=600):
62
  gr_image = gr.Image()
63
  # examples=examples
64
+ gr_generate_button.click(
65
+ generate,
66
+ inputs=[gr_prompt, gr_password],
67
+ outputs=[gr_image],
68
+ )
69
  with gr.Row():
70
+ gr.Examples(examples, inputs=[gr_prompt], label="γƒ—γƒ­γƒ³γƒ—γƒˆδΎ‹")
71
 
72
+ demo.launch()