Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import base64
|
| 4 |
+
from PIL import Image
|
| 5 |
+
from io import BytesIO
|
| 6 |
+
|
| 7 |
+
API_URL = "https://huggingface.co/spaces/florafeng/UCLIP-IMG-GEN/"
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def generate(prompt, seed):
|
| 11 |
+
response = requests.post(
|
| 12 |
+
API_URL,
|
| 13 |
+
json={"prompt": prompt, "seed": int(seed)}
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
data = response.json()
|
| 17 |
+
|
| 18 |
+
img_bytes = base64.b64decode(data["image"])
|
| 19 |
+
image = Image.open(BytesIO(img_bytes))
|
| 20 |
+
|
| 21 |
+
return image
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
with gr.Blocks() as demo:
|
| 25 |
+
gr.Markdown("# 🎨 AI Bedroom Generator")
|
| 26 |
+
|
| 27 |
+
prompt = gr.Textbox(
|
| 28 |
+
label="Prompt",
|
| 29 |
+
value="a unique bedroom with dolls, pillows, paintings"
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
seed = gr.Number(value=123, label="Seed")
|
| 33 |
+
|
| 34 |
+
btn = gr.Button("Generate")
|
| 35 |
+
|
| 36 |
+
output = gr.Image()
|
| 37 |
+
|
| 38 |
+
btn.click(generate, inputs=[prompt, seed], outputs=output)
|
| 39 |
+
|
| 40 |
+
demo.launch()
|