Spaces:
Runtime error
Runtime error
adding the gradio-template style UI
Browse files
app.py
CHANGED
@@ -5,6 +5,19 @@ import requests
|
|
5 |
from PIL import Image
|
6 |
from io import BytesIO
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
def generate_image(prompt, api_key):
|
9 |
# Set the API key for the current session
|
10 |
os.environ["REPLICATE_API_TOKEN"] = api_key
|
@@ -28,26 +41,46 @@ def generate_image(prompt, api_key):
|
|
28 |
# Return the image
|
29 |
return image
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
gr.
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
)
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
)
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
51 |
|
52 |
-
|
53 |
-
iface.launch()
|
|
|
5 |
from PIL import Image
|
6 |
from io import BytesIO
|
7 |
|
8 |
+
examples = [
|
9 |
+
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
|
10 |
+
"An astronaut riding a green horse",
|
11 |
+
"A delicious ceviche cheesecake slice",
|
12 |
+
]
|
13 |
+
|
14 |
+
css="""
|
15 |
+
#col-container {
|
16 |
+
margin: 0 auto;
|
17 |
+
max-width: 640px;
|
18 |
+
}
|
19 |
+
"""
|
20 |
+
|
21 |
def generate_image(prompt, api_key):
|
22 |
# Set the API key for the current session
|
23 |
os.environ["REPLICATE_API_TOKEN"] = api_key
|
|
|
41 |
# Return the image
|
42 |
return image
|
43 |
|
44 |
+
|
45 |
+
with gr.Blocks(css=css) as demo:
|
46 |
+
|
47 |
+
with gr.Column(elem_id="col-container"):
|
48 |
+
gr.Markdown(f"""
|
49 |
+
# FLUX 1.1 Pro Text-to-Image Generator
|
50 |
+
""")
|
51 |
+
|
52 |
+
with gr.Row():
|
53 |
+
with gr.Column():
|
54 |
+
api_key = gr.Text(
|
55 |
+
label="Replicate API Key",
|
56 |
+
show_label=False,
|
57 |
+
max_lines=1,
|
58 |
+
placeholder="Enter your Replicate API key...",
|
59 |
+
container=False,
|
60 |
+
type="password",
|
61 |
+
)
|
62 |
+
prompt = gr.Text(
|
63 |
+
label="Prompt",
|
64 |
+
show_label=False,
|
65 |
+
max_lines=1,
|
66 |
+
placeholder="Enter your prompt",
|
67 |
+
container=False,
|
68 |
+
)
|
69 |
+
|
70 |
+
run_button = gr.Button("Run", scale=0)
|
71 |
+
|
72 |
+
result = gr.Image(label="Result", show_label=False)
|
73 |
+
|
74 |
+
|
75 |
+
gr.Examples(
|
76 |
+
examples = examples,
|
77 |
+
inputs = [prompt]
|
78 |
)
|
79 |
+
gr.on(
|
80 |
+
triggers=[run_button.click, prompt.submit],
|
81 |
+
fn = generate_image,
|
82 |
+
inputs = [prompt, api_key],
|
83 |
+
outputs = [result,]
|
84 |
+
)
|
85 |
|
86 |
+
demo.queue().launch()
|
|