Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -62,11 +62,16 @@ class Prodia:
|
|
62 |
|
63 |
|
64 |
def image_to_base64(image_path):
|
|
|
65 |
with Image.open(image_path) as image:
|
|
|
66 |
buffered = BytesIO()
|
67 |
-
image.save(buffered, format="PNG")
|
|
|
|
|
68 |
img_str = base64.b64encode(buffered.getvalue())
|
69 |
-
|
|
|
70 |
|
71 |
|
72 |
prodia_client = Prodia(api_key=os.getenv("PRODIA_API_KEY"))
|
@@ -89,41 +94,114 @@ def flip_text(prompt, negative_prompt, model, steps, sampler, cfg_scale, width,
|
|
89 |
return job["imageUrl"]
|
90 |
|
91 |
css = """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
#generate {
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
94 |
}
|
95 |
-
"""
|
96 |
|
97 |
-
#
|
98 |
-
|
99 |
-
|
100 |
-
with gr.Column():
|
101 |
-
gr.Markdown("# Disney Pixar AI Poster Generator")
|
102 |
-
gr.Markdown("Enter your prompt and adjust the settings to generate a Disney Pixar style AI poster.")
|
103 |
-
|
104 |
-
with gr.Row():
|
105 |
-
with gr.Column(scale=2):
|
106 |
-
prompt = gr.Textbox("space warrior, beautiful, female, ultrarealistic, soft lighting, 8k", placeholder="Prompt", show_label=False, lines=3)
|
107 |
-
negative_prompt = gr.Textbox(placeholder="Negative Prompt", show_label=False, lines=3, value="3d, cartoon, anime, (deformed eyes, nose, ears, nose), bad anatomy, ugly")
|
108 |
-
text_button = gr.Button("Generate", variant='primary', style={"min-width": "100%"})
|
109 |
|
110 |
-
|
111 |
-
|
|
|
|
|
|
|
|
|
|
|
112 |
|
|
|
113 |
with gr.Row():
|
114 |
-
|
115 |
-
|
116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
steps = gr.Slider(label="Sampling Steps", minimum=1, maximum=25, value=20, step=1)
|
118 |
-
cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7, step=1)
|
119 |
-
seed = gr.Number(label="Seed", value=-1)
|
120 |
|
121 |
-
with gr.Column(scale=
|
122 |
width = gr.Slider(label="Width", minimum=512, maximum=1536, value=1024, step=8)
|
123 |
height = gr.Slider(label="Height", minimum=512, maximum=1536, value=1024, step=8)
|
124 |
-
|
125 |
-
|
126 |
-
|
|
|
127 |
|
128 |
-
|
129 |
-
demo.launch()
|
|
|
62 |
|
63 |
|
64 |
def image_to_base64(image_path):
|
65 |
+
# Open the image with PIL
|
66 |
with Image.open(image_path) as image:
|
67 |
+
# Convert the image to bytes
|
68 |
buffered = BytesIO()
|
69 |
+
image.save(buffered, format="PNG") # You can change format to PNG if needed
|
70 |
+
|
71 |
+
# Encode the bytes to base64
|
72 |
img_str = base64.b64encode(buffered.getvalue())
|
73 |
+
|
74 |
+
return img_str.decode('utf-8') # Convert bytes to string
|
75 |
|
76 |
|
77 |
prodia_client = Prodia(api_key=os.getenv("PRODIA_API_KEY"))
|
|
|
94 |
return job["imageUrl"]
|
95 |
|
96 |
css = """
|
97 |
+
/* Overall Styling */
|
98 |
+
body {
|
99 |
+
font-family: 'Arial', sans-serif;
|
100 |
+
}
|
101 |
+
|
102 |
+
.container {
|
103 |
+
display: flex;
|
104 |
+
flex-direction: column;
|
105 |
+
gap: 20px;
|
106 |
+
}
|
107 |
+
|
108 |
+
/* Image Output Area */
|
109 |
+
#image-output-container {
|
110 |
+
border: 2px solid #ccc;
|
111 |
+
border-radius: 8px;
|
112 |
+
overflow: hidden;
|
113 |
+
}
|
114 |
+
|
115 |
+
#image-output {
|
116 |
+
max-width: 100%;
|
117 |
+
height: auto;
|
118 |
+
}
|
119 |
+
|
120 |
+
/* Settings Section */
|
121 |
+
#settings {
|
122 |
+
display: grid;
|
123 |
+
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
124 |
+
gap: 20px;
|
125 |
+
}
|
126 |
+
|
127 |
+
.setting-group {
|
128 |
+
border: 1px solid #ccc;
|
129 |
+
padding: 20px;
|
130 |
+
border-radius: 8px;
|
131 |
+
}
|
132 |
+
|
133 |
+
/* Button Styling */
|
134 |
#generate {
|
135 |
+
background-color: #007bff; /* Example - use your preferred color */
|
136 |
+
color: white;
|
137 |
+
padding: 15px 25px;
|
138 |
+
border: none;
|
139 |
+
border-radius: 5px;
|
140 |
+
cursor: pointer;
|
141 |
}
|
|
|
142 |
|
143 |
+
#generate:hover {
|
144 |
+
background-color: #0056b3; /* Darker shade on hover */
|
145 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
|
147 |
+
/* Responsive Design - Adjust breakpoints as needed */
|
148 |
+
@media screen and (max-width: 768px) {
|
149 |
+
#settings {
|
150 |
+
grid-template-columns: 1fr;
|
151 |
+
}
|
152 |
+
}
|
153 |
+
"""
|
154 |
|
155 |
+
with gr.Blocks(css=css) as demo:
|
156 |
with gr.Row():
|
157 |
+
gr.Markdown("<h1 style='text-align: center;'>Create Your Disney Pixar AI Poster</h1>", elem_id="title")
|
158 |
+
|
159 |
+
with gr.Row(elem_id="image-output-container"):
|
160 |
+
image_output = gr.Image(
|
161 |
+
value="https://cdn-uploads.huggingface.co/production/uploads/noauth/XWJyh9DhMGXrzyRJk7SfP.png",
|
162 |
+
label="Generated Image",
|
163 |
+
elem_id="image-output"
|
164 |
+
)
|
165 |
+
|
166 |
+
with gr.Row(elem_id="settings"):
|
167 |
+
with gr.Column(scale=1, min_width=300, elem_classes="setting-group"):
|
168 |
+
prompt = gr.Textbox(
|
169 |
+
"space warrior, beautiful, female, ultrarealistic, soft lighting, 8k",
|
170 |
+
placeholder="Enter your prompt here...",
|
171 |
+
show_label=False,
|
172 |
+
lines=3,
|
173 |
+
elem_id="prompt-input"
|
174 |
+
)
|
175 |
+
negative_prompt = gr.Textbox(
|
176 |
+
placeholder="Enter negative prompts (optional)...",
|
177 |
+
show_label=False,
|
178 |
+
lines=3,
|
179 |
+
value="3d, cartoon, anime, (deformed eyes, nose, ears, nose), bad anatomy, ugly"
|
180 |
+
)
|
181 |
+
text_button = gr.Button("Generate", variant='primary', elem_id="generate")
|
182 |
+
|
183 |
+
with gr.Column(scale=1, min_width=300, elem_classes="setting-group"):
|
184 |
+
model = gr.Dropdown(
|
185 |
+
interactive=True,
|
186 |
+
value="sd_xl_base_1.0.safetensors [be9edd61]",
|
187 |
+
show_label=True,
|
188 |
+
label="Model",
|
189 |
+
choices=prodia_client.list_models()
|
190 |
+
)
|
191 |
+
sampler = gr.Dropdown(
|
192 |
+
value="DPM++ 2M Karras",
|
193 |
+
show_label=True,
|
194 |
+
label="Sampling Method",
|
195 |
+
choices=prodia_client.list_samplers()
|
196 |
+
)
|
197 |
steps = gr.Slider(label="Sampling Steps", minimum=1, maximum=25, value=20, step=1)
|
|
|
|
|
198 |
|
199 |
+
with gr.Column(scale=1, min_width=300, elem_classes="setting-group"):
|
200 |
width = gr.Slider(label="Width", minimum=512, maximum=1536, value=1024, step=8)
|
201 |
height = gr.Slider(label="Height", minimum=512, maximum=1536, value=1024, step=8)
|
202 |
+
cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7, step=1)
|
203 |
+
seed = gr.Number(label="Seed", value=-1)
|
204 |
+
|
205 |
+
text_button.click(flip_text, inputs=[prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed], outputs=image_output)
|
206 |
|
207 |
+
demo.queue(concurrency_count=24, max_size=32, api_open=False).launch(max_threads=128)
|
|