Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,50 +1,43 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
from PIL import Image
|
| 4 |
-
from io import BytesIO
|
| 5 |
|
| 6 |
-
|
|
|
|
| 7 |
|
|
|
|
| 8 |
|
| 9 |
-
def generate(prompt, seed):
|
| 10 |
-
response = requests.post(
|
| 11 |
-
API_URL,
|
| 12 |
-
json={
|
| 13 |
-
"data": [prompt, int(seed)]
|
| 14 |
-
}
|
| 15 |
-
)
|
| 16 |
-
|
| 17 |
-
if response.status_code != 200:
|
| 18 |
-
return f"Error: {response.status_code} - {response.text}"
|
| 19 |
-
|
| 20 |
-
data = response.json()
|
| 21 |
-
|
| 22 |
-
result = data["data"][0]
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
| 30 |
return result
|
| 31 |
|
| 32 |
-
|
|
|
|
| 33 |
|
| 34 |
|
| 35 |
with gr.Blocks() as demo:
|
| 36 |
gr.Markdown("# 🎨 AI Bedroom Generator")
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
|
| 45 |
btn = gr.Button("Generate")
|
| 46 |
-
output = gr.Image()
|
| 47 |
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from gradio_client import Client
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
# 🔴 Replace with your backend Space URL
|
| 5 |
+
BACKEND_URL = "https://florafeng-uclip-img-gen.hf.space"
|
| 6 |
|
| 7 |
+
client = Client(BACKEND_URL)
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
def generate(prompt, seed):
|
| 11 |
+
try:
|
| 12 |
+
result = client.predict(
|
| 13 |
+
prompt,
|
| 14 |
+
seed,
|
| 15 |
+
api_name="/predict" # default for gr.Interface
|
| 16 |
+
)
|
| 17 |
return result
|
| 18 |
|
| 19 |
+
except Exception as e:
|
| 20 |
+
return f"Error: {str(e)}"
|
| 21 |
|
| 22 |
|
| 23 |
with gr.Blocks() as demo:
|
| 24 |
gr.Markdown("# 🎨 AI Bedroom Generator")
|
| 25 |
|
| 26 |
+
with gr.Row():
|
| 27 |
+
prompt = gr.Textbox(
|
| 28 |
+
label="Prompt",
|
| 29 |
+
value="a unique bedroom with dolls, pillows, paintings"
|
| 30 |
+
)
|
| 31 |
+
seed = gr.Number(value=123, label="Seed")
|
| 32 |
|
| 33 |
btn = gr.Button("Generate")
|
|
|
|
| 34 |
|
| 35 |
+
output = gr.Image(label="Generated Image")
|
| 36 |
+
|
| 37 |
+
btn.click(
|
| 38 |
+
fn=generate,
|
| 39 |
+
inputs=[prompt, seed],
|
| 40 |
+
outputs=output
|
| 41 |
+
)
|
| 42 |
|
| 43 |
demo.launch()
|