Spaces:
Sleeping
Sleeping
File size: 2,599 Bytes
4d1d4c3 b19f447 4d1d4c3 b19f447 4d1d4c3 b19f447 4d1d4c3 b19f447 4d1d4c3 b19f447 4d1d4c3 b19f447 4d1d4c3 b19f447 4d1d4c3 b19f447 4d1d4c3 b19f447 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
import os
from io import BytesIO
import gradio as gr
import numpy as np
import replicate
import requests
from PIL import Image
model_id = "stability-ai/sdxl:2b017d9b67edd2ee1401238df49d75da53c523f36e363881e057f5dc3ed3c5b2"
default_steps = 25
def generate(prompt: str, secret_key: str):
"""
γγγ³γγγγηζη»ε(PIL.Image.open)γεεΎ
"""
if secret_key == os.environ["SECRET_KEY"]:
output = replicate.run(
model_id,
input={
"prompt": prompt,
"num_inference_steps": default_steps,
},
)
# γͺγ³γ―εεΎ
png_link = output[0]
# PNGγγ‘γ€γ«γγͺγ³γ―γγεεΎ
response = requests.get(png_link)
# γ€γ‘γΌγΈγγ‘γ’γͺδΈγ«ιγ
img = Image.open(BytesIO(response.content))
return img
examples = [
["station"],
["station, ghibli style"],
["Elon Musk"],
["Elon Musk playing Shogi"],
# ["An astronaut riding a rainbow unicorn, cinematic, dramatic", ""],
# ["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.", ""],
# ["Panda mad scientist mixing sparkling chemicals, artstation.", ""],
# ["An astronaut riding a rainbow unicorn, cinematic, dramatic"],
# [
# "photo of a rhino dressed suit and tie sitting at a table in a bar with a bar stools, award winning photography."
# ],
# ["a giant monster hybrid of dragon and spider, in dark dense foggy forest"],
# [
# "a man in a space suit playing a piano, highly detailed illustration, full color illustration, very detailed illustration"
# ],
]
with gr.Blocks(title="Stable Diffusion XL (SDXL 1.0)") as demo:
with gr.Row():
with gr.Column(scale=1, min_width=600):
gr_prompt = gr.Textbox(label="γγγ³γγ")
gr_password = gr.Textbox(label="γγΉγ―γΌγ")
gr_generate_button = gr.Button("ηζ")
# with gr.Accordion("advanced settings", open=False):
# gr_steps = gr.Number(label="steps", value=default_steps)
# gr_seed = gr.Number(label="seed", value=-1)
with gr.Column(scale=1, min_width=600):
gr_image = gr.Image()
# examples=examples
gr_generate_button.click(
generate,
inputs=[gr_prompt, gr_password],
outputs=[gr_image],
)
with gr.Row():
gr.Examples(examples, inputs=[gr_prompt], label="γγγ³γγδΎ")
demo.launch()
|