HelloAI1 commited on
Commit
145b6e0
1 Parent(s): 99797c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -81
app.py CHANGED
@@ -154,88 +154,78 @@ body {
154
 
155
  # --- Gradio Interface ---
156
 
157
- # Define demo OUTSIDE the blocks
158
- demo = gr.Blocks(css=css)
159
-
160
- # Initial Welcome Screen
161
- with gr.Blocks() as welcome_screen:
162
- with gr.Row():
163
- logo = gr.Image(
164
- value="http://disneypixaraigenerator.com/wp-content/uploads/2023/12/cropped-android-chrome-512x512-1.png",
165
- elem_id="logo",
166
- height=200,
167
- width=300
168
- )
169
-
170
- with gr.Row():
171
- title = gr.Markdown("<h1 style='text-align: center;'>Disney Pixar AI Generator</h1>", elem_id="title")
172
-
173
- with gr.Row():
174
- start_button = gr.Button("Get Started", variant='primary', elem_id="start-button")
175
-
176
- # Main Generation Screen (Now use the defined 'demo')
177
- with demo:
178
- with gr.Row():
179
- gr.Markdown("<h1 style='text-align: center;'>Create Your Disney Pixar AI Poster</h1>", elem_id="title")
180
-
181
- with gr.Row(elem_id="image-output-container"):
182
- image_output = gr.Image(
183
- value="https://cdn-uploads.huggingface.co/production/uploads/noauth/XWJyh9DhMGXrzyRJk7SfP.png",
184
- label="Generated Image",
185
- elem_id="image-output"
186
- )
187
-
188
- with gr.Row(elem_id="settings"):
189
- with gr.Column(scale=1, min_width=300, elem_classes="setting-group"):
190
- prompt = gr.Textbox(
191
- "space warrior, beautiful, female, ultrarealistic, soft lighting, 8k",
192
- placeholder="Enter your prompt here...",
193
- show_label=False,
194
- lines=3,
195
- elem_id="prompt-input"
196
- )
197
- negative_prompt = gr.Textbox(
198
- placeholder="Enter negative prompts (optional)...",
199
- show_label=False,
200
- lines=3,
201
- value="3d, cartoon, anime, (deformed eyes, nose, ears, nose), bad anatomy, ugly"
202
- )
203
- text_button = gr.Button("Generate", variant='primary', elem_id="generate")
204
-
205
- with gr.Column(scale=1, min_width=300, elem_classes="setting-group"):
206
- model = gr.Dropdown(
207
- interactive=True,
208
- value="sd_xl_base_1.0.safetensors [be9edd61]",
209
- show_label=True,
210
- label="Model",
211
- choices=prodia_client.list_models()
212
- )
213
- sampler = gr.Dropdown(
214
- value="DPM++ 2M Karras",
215
- show_label=True,
216
- label="Sampling Method",
217
- choices=prodia_client.list_samplers()
218
- )
219
- steps = gr.Slider(label="Sampling Steps", minimum=1, maximum=25, value=20, step=1)
220
-
221
- with gr.Column(scale=1, min_width=300, elem_classes="setting-group"):
222
- width = gr.Slider(label="Width", minimum=512, maximum=1536, value=1024, step=8)
223
- height = gr.Slider(label="Height", minimum=512, maximum=1536, value=1024, step=8)
224
- cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7, step=1)
225
- seed = gr.Number(label="Seed", value=-1)
226
 
227
  text_button.click(flip_text, inputs=[prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed], outputs=image_output)
228
-
229
- # Tabs to switch between screens
230
- tabs = gr.Tabs()
231
- with tabs:
232
- with gr.TabItem("Welcome Screen"):
233
- welcome_screen
234
- with gr.TabItem("Main Generation Screen"):
235
- demo
236
-
237
- # Connect Welcome Screen to Generation Screen
238
- start_button.click(fn=lambda: tabs.set_selected("Main Generation Screen"))
239
 
240
  # Launch the Gradio app
241
- tabs.launch(max_threads=128)
 
154
 
155
  # --- Gradio Interface ---
156
 
157
+ with gr.Blocks(css=css) as demo:
158
+ state = gr.State(value="Welcome Screen") # To control the visibility of tabs
159
+
160
+ with gr.Tabs() as tabs:
161
+ with gr.TabItem("Welcome Screen"):
162
+ with gr.Row():
163
+ logo = gr.Image(
164
+ value="http://disneypixaraigenerator.com/wp-content/uploads/2023/12/cropped-android-chrome-512x512-1.png",
165
+ elem_id="logo",
166
+ height=200,
167
+ width=300
168
+ )
169
+
170
+ with gr.Row():
171
+ title = gr.Markdown("<h1 style='text-align: center;'>Disney Pixar AI Generator</h1>", elem_id="title")
172
+
173
+ with gr.Row():
174
+ start_button = gr.Button("Get Started", variant='primary', elem_id="start-button")
175
+
176
+ with gr.TabItem("Main Generation Screen"):
177
+ with gr.Row():
178
+ gr.Markdown("<h1 style='text-align: center;'>Create Your Disney Pixar AI Poster</h1>", elem_id="title")
179
+
180
+ with gr.Row(elem_id="image-output-container"):
181
+ image_output = gr.Image(
182
+ value="https://cdn-uploads.huggingface.co/production/uploads/noauth/XWJyh9DhMGXrzyRJk7SfP.png",
183
+ label="Generated Image",
184
+ elem_id="image-output"
185
+ )
186
+
187
+ with gr.Row(elem_id="settings"):
188
+ with gr.Column(scale=1, min_width=300, elem_classes="setting-group"):
189
+ prompt = gr.Textbox(
190
+ "space warrior, beautiful, female, ultrarealistic, soft lighting, 8k",
191
+ placeholder="Enter your prompt here...",
192
+ show_label=False,
193
+ lines=3,
194
+ elem_id="prompt-input"
195
+ )
196
+ negative_prompt = gr.Textbox(
197
+ placeholder="Enter negative prompts (optional)...",
198
+ show_label=False,
199
+ lines=3,
200
+ value="3d, cartoon, anime, (deformed eyes, nose, ears, nose), bad anatomy, ugly"
201
+ )
202
+ text_button = gr.Button("Generate", variant='primary', elem_id="generate")
203
+
204
+ with gr.Column(scale=1, min_width=300, elem_classes="setting-group"):
205
+ model = gr.Dropdown(
206
+ interactive=True,
207
+ value="sd_xl_base_1.0.safetensors [be9edd61]",
208
+ show_label=True,
209
+ label="Model",
210
+ choices=prodia_client.list_models()
211
+ )
212
+ sampler = gr.Dropdown(
213
+ value="DPM++ 2M Karras",
214
+ show_label=True,
215
+ label="Sampling Method",
216
+ choices=prodia_client.list_samplers()
217
+ )
218
+ steps = gr.Slider(label="Sampling Steps", minimum=1, maximum=25, value=20, step=1)
219
+
220
+ with gr.Column(scale=1, min_width=300, elem_classes="setting-group"):
221
+ width = gr.Slider(label="Width", minimum=512, maximum=1536, value=1024, step=8)
222
+ height = gr.Slider(label="Height", minimum=512, maximum=1536, value=1024, step=8)
223
+ cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7, step=1)
224
+ seed = gr.Number(label="Seed", value=-1)
 
225
 
226
  text_button.click(flip_text, inputs=[prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed], outputs=image_output)
227
+ start_button.click(fn=lambda: "Main Generation Screen", inputs=None, outputs=state)
228
+ state.change(fn=lambda x: gr.update(visible=(x == "Main Generation Screen")), inputs=state, outputs=tabs)
 
 
 
 
 
 
 
 
 
229
 
230
  # Launch the Gradio app
231
+ demo.launch(max_threads=128)