ginipick commited on
Commit
53f15f0
·
verified ·
1 Parent(s): d060e1c

Create app-backup.py

Browse files
Files changed (1) hide show
  1. app-backup.py +325 -0
app-backup.py ADDED
@@ -0,0 +1,325 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import random
4
+ import torch
5
+ from diffusers import DiffusionPipeline
6
+ import spaces
7
+
8
+ # Basic settings
9
+ dtype = torch.bfloat16
10
+ device = "cuda" if torch.cuda.is_available() else "cpu"
11
+
12
+ # Load model (FLUX.1-schnell)
13
+ pipe = DiffusionPipeline.from_pretrained(
14
+ "black-forest-labs/FLUX.1-schnell",
15
+ torch_dtype=dtype
16
+ ).to(device)
17
+
18
+ MAX_SEED = np.iinfo(np.int32).max
19
+ MAX_IMAGE_SIZE = 2048
20
+
21
+ @spaces.GPU()
22
+ def generate_image(prompt, seed, randomize_seed, width, height, steps, guidance_scale):
23
+ if randomize_seed:
24
+ seed = random.randint(0, MAX_SEED)
25
+ generator = torch.Generator(device).manual_seed(seed)
26
+ image = pipe(
27
+ prompt=prompt,
28
+ width=width,
29
+ height=height,
30
+ num_inference_steps=steps,
31
+ generator=generator,
32
+ guidance_scale=guidance_scale
33
+ ).images[0]
34
+ return image, seed
35
+
36
+ def set_prompt(example_text):
37
+ return example_text
38
+
39
+ # Updated example prompts per tab with richer details:
40
+ example_prompts = {
41
+ "Product Design": [
42
+ """A sleek industrial design concept for a coffee machine:
43
+ - Curved metallic body with minimal bezel
44
+ - Touchscreen panel for settings
45
+ - Modern matte black finish
46
+ - Hand-drawn concept sketch style"""
47
+ ],
48
+ "Mindmap": [
49
+ """A handrawn colorful mind map diagram, educational style, vibrant colors, clear hierarchy, golden ratio layout.
50
+ KNOWLEDGE
51
+ ├── ACQUISITION [Brain with Lightning ~60px]
52
+ │ ├── READING [Open Book with Glow]
53
+ │ ├── PRACTICE [Hands-on Tools]
54
+ │ └── OBSERVATION [Eye with Magnifier]
55
+ ├── PROCESSING [Gear Network ~50px]
56
+ │ ├── ANALYSIS [Graph Trending Up]
57
+ │ └── SYNTHESIS [Puzzle Pieces]
58
+ ├── RETENTION [Memory Chip ~45px]
59
+ │ ├── SHORT-TERM [Quick Flash]
60
+ │ └── LONG-TERM [Solid Archive]
61
+ └── APPLICATION
62
+ ├── CREATION [Artist Palette]
63
+ └── INNOVATION [Lightbulb Constellation]"""
64
+ ],
65
+ "Mockup": [
66
+ """A clean hand-drawn style wireframe for a mobile banking app:
67
+ - Title screen with logo
68
+ - Login screen (username, password, login button)
69
+ - Dashboard with 3 main sections (balance, transactions, quick actions)
70
+ - Bottom navigation bar (home, transfers, profile)"""
71
+ ],
72
+ "Infographic": [
73
+ """A sophisticated flat-style infographic for a multinational corporation’s annual report:
74
+ - Title: "Global Renewable Energy Trends 2025"
75
+ - Subtitle: "Market Share and Growth Analysis"
76
+ - Visual Elements:
77
+ - Multi-segmented bar charts comparing Solar, Wind, and Hydro energy production across regions
78
+ - Pie chart displaying overall energy distribution: Solar (45%), Wind (30%), Hydro (25%)
79
+ - Trend lines indicating year-over-year growth
80
+ - Icons: Sleek, minimalist representations of a sun, wind turbine, and water droplet
81
+ - Layout: Clean, grid-based design with ample white space and pastel accents for a modern corporate look
82
+ - Annotations: Brief, impactful data callouts highlighting key performance indicators and future forecasts"""
83
+ ],
84
+ "Diagram": [
85
+ """A detailed hand-drawn diagram illustrating an end-to-end business workflow:
86
+ - Title: "Integrated Business Process Diagram"
87
+ - Components:
88
+ - Market Analysis: Research phase with data charts and competitor mapping
89
+ - Strategy Development: Ideation stage with brainstorming clouds and key focus areas
90
+ - Product Design: Concept sketches with iterative feedback loops
91
+ - Implementation: Process flow with timeline markers and resource allocation icons
92
+ - Post-Launch Review: Feedback, metrics, and continuous improvement cycles
93
+ - Visual Elements:
94
+ - Clear, directional arrows connecting each phase
95
+ - Iconography for each component (e.g., magnifying glass, lightbulb, gear, checklist)
96
+ - Style: Vibrant, educational yet professional, balancing detailed annotations with visual simplicity
97
+ - Layout: Structured with a clear hierarchy and color-coded sections to differentiate process stages"""
98
+ ],
99
+ "Flowchart": [
100
+ """A hand-drawn style flowchart, vibrant colors, minimalistic icons.
101
+ BUSINESS WORKFLOW
102
+ ├── START [Green Button ~40px]
103
+ │ ├── COLLECT REQUIREMENTS [Folder Icon]
104
+ │ └── ANALYZE DATA [Chart Icon]
105
+ ├── IMPLEMENTATION [Coding Symbol ~50px]
106
+ │ ├── FRONTEND [Browser Icon]
107
+ │ └── BACKEND [Server Icon]
108
+ ├── TEST & INTEGRATION [Gear Icon ~45px]
109
+ └── DEPLOY
110
+ └── END [Checkered Flag ~40px]"""
111
+ ]
112
+ }
113
+
114
+ # CSS style: fixed container width and preventing examples from expanding the layout
115
+ css = """
116
+ * {
117
+ box-sizing: border-box;
118
+ }
119
+ body {
120
+ background: linear-gradient(135deg, #667eea, #764ba2);
121
+ font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
122
+ color: #333;
123
+ margin: 0;
124
+ padding: 0;
125
+ }
126
+ .gradio-container {
127
+ background: rgba(255, 255, 255, 0.95);
128
+ border-radius: 15px;
129
+ padding: 30px 40px;
130
+ box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
131
+ margin: 40px auto;
132
+ width: 1200px;
133
+ }
134
+ .sidebar {
135
+ background: rgba(255, 255, 255, 0.98);
136
+ border-radius: 10px;
137
+ padding: 20px;
138
+ box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
139
+ }
140
+ button, .btn {
141
+ background: linear-gradient(90deg, #ff8a00, #e52e71);
142
+ border: none;
143
+ color: #fff;
144
+ padding: 12px 24px;
145
+ text-transform: uppercase;
146
+ font-weight: bold;
147
+ letter-spacing: 1px;
148
+ border-radius: 5px;
149
+ cursor: pointer;
150
+ transition: transform 0.2s ease-in-out;
151
+ }
152
+ button:hover, .btn:hover {
153
+ transform: scale(1.05);
154
+ }
155
+ .example-accordion {
156
+ width: 100% !important;
157
+ max-width: 100% !important;
158
+ }
159
+ .example-accordion button {
160
+ width: auto !important;
161
+ white-space: normal !important;
162
+ }
163
+ """
164
+
165
+ with gr.Blocks(css=css, title="Workflow Canvas") as demo:
166
+ gr.Markdown(
167
+ """
168
+ <div style="text-align:center;">
169
+ <h1>Workflow Canvas</h1>
170
+ <p>Generate design concepts and workflow diagrams for your business needs using our multi-tab interface.</p>
171
+ <p><strong>community:</strong> <a href="https://discord.gg/openfreeai" target="_blank">https://discord.gg/openfreeai</a></p>
172
+ </div>
173
+ """
174
+ )
175
+ gr.HTML(
176
+ """<a href="https://visitorbadge.io/status?path=https%3A%2F%2Fginigen-Workflow-Canvas.hf.space">
177
+ <img src="https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Fginigen-Workflow-Canvas.hf.space&countColor=%23263759" alt="Visitor Badge"/>
178
+ </a>"""
179
+ )
180
+
181
+ with gr.Row():
182
+ # Left sidebar: Common generation parameters
183
+ with gr.Sidebar(label="Parameters", open=True):
184
+ gr.Markdown("### Generation Parameters")
185
+ seed_slider = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=42)
186
+ randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
187
+ width_slider = gr.Slider(label="Width", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=1024)
188
+ height_slider = gr.Slider(label="Height", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=1024)
189
+ steps_slider = gr.Slider(label="Inference Steps", minimum=1, maximum=50, step=1, value=20)
190
+ guidance_slider = gr.Slider(label="Guidance Scale", minimum=0.0, maximum=15.0, step=0.5, value=7.5)
191
+
192
+ # Main area: Tabbed interface with updated tab order:
193
+ # 1: Product Design, 2: Mindmap, 3: Mockup, 4: Infographic, 5: Diagram, 6: Flowchart
194
+ with gr.Column(scale=8):
195
+ with gr.Tabs():
196
+ # Tab 1: Product Design
197
+ with gr.Tab("Product Design"):
198
+ pd_prompt = gr.Textbox(
199
+ label="Product Design Prompt",
200
+ placeholder="Enter a product design concept...",
201
+ lines=5,
202
+ value=example_prompts["Product Design"][0]
203
+ )
204
+ pd_generate = gr.Button("Generate Product Design")
205
+ pd_image = gr.Image(label="Generated Product Design", value="w1.webp")
206
+ with gr.Accordion("Example Prompts", open=True, elem_classes="example-accordion"):
207
+ for ex in example_prompts["Product Design"]:
208
+ gr.Button(ex, variant="secondary").click(fn=lambda ex=ex: set_prompt(ex), outputs=pd_prompt)
209
+
210
+ # Tab 2: Mindmap
211
+ with gr.Tab("Mindmap"):
212
+ mindmap_prompt = gr.Textbox(
213
+ label="Mindmap Prompt",
214
+ placeholder="Enter a mind map description...",
215
+ lines=5,
216
+ value=example_prompts["Mindmap"][0]
217
+ )
218
+ mindmap_generate = gr.Button("Generate Mindmap")
219
+ mindmap_image = gr.Image(label="Generated Mindmap", value="w6.webp")
220
+ with gr.Accordion("Example Prompts", open=True, elem_classes="example-accordion"):
221
+ for ex in example_prompts["Mindmap"]:
222
+ gr.Button(ex, variant="secondary").click(fn=lambda ex=ex: set_prompt(ex), outputs=mindmap_prompt)
223
+
224
+ # Tab 3: Mockup
225
+ with gr.Tab("Mockup"):
226
+ mock_prompt = gr.Textbox(
227
+ label="Mockup Prompt",
228
+ placeholder="Enter a mockup description...",
229
+ lines=5,
230
+ value=example_prompts["Mockup"][0]
231
+ )
232
+ mock_generate = gr.Button("Generate Mockup")
233
+ mock_image = gr.Image(label="Generated Mockup", value="w2.webp")
234
+ with gr.Accordion("Example Prompts", open=True, elem_classes="example-accordion"):
235
+ for ex in example_prompts["Mockup"]:
236
+ gr.Button(ex, variant="secondary").click(fn=lambda ex=ex: set_prompt(ex), outputs=mock_prompt)
237
+
238
+ # Tab 4: Infographic
239
+ with gr.Tab("Infographic"):
240
+ info_prompt = gr.Textbox(
241
+ label="Infographic Prompt",
242
+ placeholder="Enter an infographic description...",
243
+ lines=5,
244
+ value=example_prompts["Infographic"][0]
245
+ )
246
+ info_generate = gr.Button("Generate Infographic")
247
+ info_image = gr.Image(label="Generated Infographic", value="w3.webp")
248
+ with gr.Accordion("Example Prompts", open=True, elem_classes="example-accordion"):
249
+ for ex in example_prompts["Infographic"]:
250
+ gr.Button(ex, variant="secondary").click(fn=lambda ex=ex: set_prompt(ex), outputs=info_prompt)
251
+
252
+ # Tab 5: Diagram
253
+ with gr.Tab("Diagram"):
254
+ diag_prompt = gr.Textbox(
255
+ label="Diagram Prompt",
256
+ placeholder="Enter a diagram description...",
257
+ lines=5,
258
+ value=example_prompts["Diagram"][0]
259
+ )
260
+ diag_generate = gr.Button("Generate Diagram")
261
+ diag_image = gr.Image(label="Generated Diagram", value="w4.webp")
262
+ with gr.Accordion("Example Prompts", open=True, elem_classes="example-accordion"):
263
+ for ex in example_prompts["Diagram"]:
264
+ gr.Button(ex, variant="secondary").click(fn=lambda ex=ex: set_prompt(ex), outputs=diag_prompt)
265
+
266
+ # Tab 6: Flowchart
267
+ with gr.Tab("Flowchart"):
268
+ flow_prompt = gr.Textbox(
269
+ label="Flowchart Prompt",
270
+ placeholder="Enter a flowchart description...",
271
+ lines=5,
272
+ value=example_prompts["Flowchart"][0]
273
+ )
274
+ flow_generate = gr.Button("Generate Flowchart")
275
+ flow_image = gr.Image(label="Generated Flowchart", value="w5.webp")
276
+ with gr.Accordion("Example Prompts", open=True, elem_classes="example-accordion"):
277
+ for ex in example_prompts["Flowchart"]:
278
+ gr.Button(ex, variant="secondary").click(fn=lambda ex=ex: set_prompt(ex), outputs=flow_prompt)
279
+
280
+ # Bind events for generation buttons
281
+ pd_generate.click(
282
+ fn=generate_image,
283
+ inputs=[pd_prompt, seed_slider, randomize_seed, width_slider, height_slider, steps_slider, guidance_slider],
284
+ outputs=[pd_image, seed_slider]
285
+ )
286
+
287
+ mindmap_generate.click(
288
+ fn=generate_image,
289
+ inputs=[mindmap_prompt, seed_slider, randomize_seed, width_slider, height_slider, steps_slider, guidance_slider],
290
+ outputs=[mindmap_image, seed_slider]
291
+ )
292
+
293
+ mock_generate.click(
294
+ fn=generate_image,
295
+ inputs=[mock_prompt, seed_slider, randomize_seed, width_slider, height_slider, steps_slider, guidance_slider],
296
+ outputs=[mock_image, seed_slider]
297
+ )
298
+
299
+ info_generate.click(
300
+ fn=generate_image,
301
+ inputs=[info_prompt, seed_slider, randomize_seed, width_slider, height_slider, steps_slider, guidance_slider],
302
+ outputs=[info_image, seed_slider]
303
+ )
304
+
305
+ diag_generate.click(
306
+ fn=generate_image,
307
+ inputs=[diag_prompt, seed_slider, randomize_seed, width_slider, height_slider, steps_slider, guidance_slider],
308
+ outputs=[diag_image, seed_slider]
309
+ )
310
+
311
+ flow_generate.click(
312
+ fn=generate_image,
313
+ inputs=[flow_prompt, seed_slider, randomize_seed, width_slider, height_slider, steps_slider, guidance_slider],
314
+ outputs=[flow_image, seed_slider]
315
+ )
316
+
317
+ if __name__ == "__main__":
318
+ demo.queue()
319
+ demo.launch(
320
+ server_name="0.0.0.0",
321
+ server_port=7860,
322
+ share=False,
323
+ show_error=True,
324
+ debug=True
325
+ )