text2image / app.py
Kpenciler's picture
add app filr
2068945
raw
history blame
911 Bytes
from io import BytesIO
import gradio as gr
import numpy as np
import replicate
import requests
from PIL import Image
def generate(prompt: str):
"""
γƒ—γƒ­γƒ³γƒ—γƒˆγ‹γ‚‰η”Ÿζˆη”»εƒ(PIL.Image.open)を取得
"""
output = replicate.run(
"stability-ai/sdxl:2b017d9b67edd2ee1401238df49d75da53c523f36e363881e057f5dc3ed3c5b2",
input={"prompt": prompt,
"seed": np.random.randint(1, 1001)},
)
# γƒͺンク取得
png_link = output[0]
# PNGフゑむルをγƒͺンクから取得
response = requests.get(png_link)
# むパージをパヒγƒͺδΈŠγ«ι–‹γ
img = Image.open(BytesIO(response.content))
return img
demo = gr.Interface(
generate,
inputs=[gr.Textbox(label='γƒ—γƒ­γƒ³γƒ—γƒˆ')],
outputs=["image"],
examples=["An astronaut riding a rainbow unicorn, cinematic, dramatic"],
)
if __name__ == "__main__":
demo.launch()