Spaces:
Runtime error
Runtime error
add secret key
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
from io import BytesIO
|
| 2 |
|
| 3 |
import gradio as gr
|
|
@@ -7,29 +8,33 @@ import requests
|
|
| 7 |
from PIL import Image
|
| 8 |
|
| 9 |
|
| 10 |
-
def generate(prompt: str):
|
| 11 |
"""
|
| 12 |
γγγ³γγγγηζη»ε(PIL.Image.open)γεεΎ
|
| 13 |
"""
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
|
| 27 |
|
| 28 |
demo = gr.Interface(
|
| 29 |
generate,
|
| 30 |
-
inputs=[gr.Textbox(label='γγγ³γγ')],
|
| 31 |
outputs=["image"],
|
| 32 |
-
examples=["An astronaut riding a rainbow unicorn, cinematic, dramatic"],
|
|
|
|
|
|
|
| 33 |
)
|
| 34 |
|
| 35 |
if __name__ == "__main__":
|
|
|
|
| 1 |
+
import os
|
| 2 |
from io import BytesIO
|
| 3 |
|
| 4 |
import gradio as gr
|
|
|
|
| 8 |
from PIL import Image
|
| 9 |
|
| 10 |
|
| 11 |
+
def generate(prompt: str, secret_key: str):
|
| 12 |
"""
|
| 13 |
γγγ³γγγγηζη»ε(PIL.Image.open)γεεΎ
|
| 14 |
"""
|
| 15 |
+
if secret_key == os.environ["SECRET_KEY"]:
|
| 16 |
+
output = replicate.run(
|
| 17 |
+
"stability-ai/sdxl:2b017d9b67edd2ee1401238df49d75da53c523f36e363881e057f5dc3ed3c5b2",
|
| 18 |
+
input={"prompt": prompt,
|
| 19 |
+
"seed": np.random.randint(1, 1001)},
|
| 20 |
+
)
|
| 21 |
+
# γͺγ³γ―εεΎ
|
| 22 |
+
png_link = output[0]
|
| 23 |
+
# PNGγγ‘γ€γ«γγͺγ³γ―γγεεΎ
|
| 24 |
+
response = requests.get(png_link)
|
| 25 |
+
# γ€γ‘γΌγΈγγ‘γ’γͺδΈγ«ιγ
|
| 26 |
+
img = Image.open(BytesIO(response.content))
|
| 27 |
+
return img
|
| 28 |
+
|
| 29 |
|
| 30 |
|
| 31 |
demo = gr.Interface(
|
| 32 |
generate,
|
| 33 |
+
inputs=[gr.Textbox(label='γγγ³γγ'), gr.Textbox(label='secret key')],
|
| 34 |
outputs=["image"],
|
| 35 |
+
examples=[["An astronaut riding a rainbow unicorn, cinematic, dramatic", ""]],
|
| 36 |
+
allow_flagging=None,
|
| 37 |
+
title="Stable Diffusion XL (SDXL 1.0)"
|
| 38 |
)
|
| 39 |
|
| 40 |
if __name__ == "__main__":
|