Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,11 +5,11 @@ import torch
|
|
| 5 |
from diffusers import DiffusionPipeline
|
| 6 |
import spaces
|
| 7 |
|
| 8 |
-
#
|
| 9 |
dtype = torch.bfloat16
|
| 10 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 11 |
|
| 12 |
-
#
|
| 13 |
pipe = DiffusionPipeline.from_pretrained(
|
| 14 |
"black-forest-labs/FLUX.1-schnell",
|
| 15 |
torch_dtype=dtype
|
|
@@ -33,8 +33,43 @@ def generate_image(prompt, seed, randomize_seed, width, height, steps, guidance_
|
|
| 33 |
).images[0]
|
| 34 |
return image, seed
|
| 35 |
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
css = """
|
|
|
|
|
|
|
|
|
|
| 38 |
body {
|
| 39 |
background: linear-gradient(135deg, #667eea, #764ba2);
|
| 40 |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
|
@@ -50,10 +85,6 @@ body {
|
|
| 50 |
margin: 40px auto;
|
| 51 |
max-width: 1200px;
|
| 52 |
}
|
| 53 |
-
.gradio-container h1 {
|
| 54 |
-
color: #333;
|
| 55 |
-
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
|
| 56 |
-
}
|
| 57 |
.sidebar {
|
| 58 |
background: rgba(255, 255, 255, 0.98);
|
| 59 |
border-radius: 10px;
|
|
@@ -75,112 +106,88 @@ button, .btn {
|
|
| 75 |
button:hover, .btn:hover {
|
| 76 |
transform: scale(1.05);
|
| 77 |
}
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
# 예제 프롬프트 (각 탭별로 다양한 예시)
|
| 81 |
-
example_prompts = {
|
| 82 |
-
"Flowchart": [
|
| 83 |
-
"A hand-drawn style flowchart depicting a software release pipeline with clear nodes for development, testing, deployment, and maintenance.",
|
| 84 |
-
"An illustrated business process flowchart for a customer service workflow, with decision points and clear labels.",
|
| 85 |
-
"A creative flowchart showing the steps of a marketing campaign from ideation to execution."
|
| 86 |
-
],
|
| 87 |
-
"Infographic": [
|
| 88 |
-
"A visually appealing infographic displaying global sales data with vibrant colors, icons, and modern design elements.",
|
| 89 |
-
"An infographic illustrating startup growth metrics with graphs, charts, and minimalist design.",
|
| 90 |
-
"A data-driven infographic showcasing key performance indicators for a corporate strategy, with clear sections and illustrations."
|
| 91 |
-
],
|
| 92 |
-
"Mockup": [
|
| 93 |
-
"A sketch-style UX mockup for a mobile banking app login flow, featuring clean lines and minimalist design.",
|
| 94 |
-
"A wireframe mockup for an e-commerce website homepage, with user-friendly navigation and modern layout.",
|
| 95 |
-
"A prototype mockup for a productivity dashboard with a focus on intuitive user interface elements."
|
| 96 |
-
],
|
| 97 |
-
"Diagram": [
|
| 98 |
-
"An educational diagram of a supply chain process, with clear labels and vibrant, friendly illustrations.",
|
| 99 |
-
"A business diagram showing the flow of information between departments in an organization, with modern icons and a clean layout.",
|
| 100 |
-
"A conceptual diagram of a data pipeline, illustrating each step with simple, engaging visuals."
|
| 101 |
-
],
|
| 102 |
-
"Design": [
|
| 103 |
-
"A sleek industrial design concept for a modern office chair, featuring ergonomic curves and minimalist aesthetics.",
|
| 104 |
-
"A futuristic design for a high-tech smart conference room, blending modern materials with interactive displays.",
|
| 105 |
-
"A creative product design for a smart coffee machine with a metallic finish and touch interface."
|
| 106 |
-
]
|
| 107 |
}
|
|
|
|
| 108 |
|
| 109 |
-
|
| 110 |
-
def set_prompt(example_text):
|
| 111 |
-
return example_text
|
| 112 |
-
|
| 113 |
-
with gr.Blocks(css=css, title="비즈니스 에이전트 이미지 생성기") as demo:
|
| 114 |
gr.Markdown(
|
| 115 |
"""
|
| 116 |
<div style="text-align:center;">
|
| 117 |
-
<h1
|
| 118 |
-
<p
|
| 119 |
-
<p><strong>
|
| 120 |
</div>
|
| 121 |
"""
|
| 122 |
)
|
| 123 |
|
| 124 |
with gr.Row():
|
| 125 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
with gr.Column(scale=8):
|
| 127 |
with gr.Tabs():
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
with gr.Tab("Flowchart"):
|
| 130 |
flow_prompt = gr.Textbox(label="Flowchart Prompt", placeholder="Enter a flowchart description...", lines=5)
|
| 131 |
flow_generate = gr.Button("Generate Flowchart")
|
| 132 |
flow_image = gr.Image(label="Generated Flowchart")
|
| 133 |
-
with gr.Accordion("Example Prompts", open=False):
|
| 134 |
for ex in example_prompts["Flowchart"]:
|
| 135 |
gr.Button(ex, variant="secondary").click(fn=lambda ex=ex: set_prompt(ex), outputs=flow_prompt)
|
| 136 |
|
| 137 |
-
|
| 138 |
with gr.Tab("Infographic"):
|
| 139 |
info_prompt = gr.Textbox(label="Infographic Prompt", placeholder="Enter an infographic description...", lines=5)
|
| 140 |
info_generate = gr.Button("Generate Infographic")
|
| 141 |
info_image = gr.Image(label="Generated Infographic")
|
| 142 |
-
with gr.Accordion("Example Prompts", open=False):
|
| 143 |
for ex in example_prompts["Infographic"]:
|
| 144 |
gr.Button(ex, variant="secondary").click(fn=lambda ex=ex: set_prompt(ex), outputs=info_prompt)
|
| 145 |
|
| 146 |
-
|
| 147 |
with gr.Tab("Mockup"):
|
| 148 |
mock_prompt = gr.Textbox(label="Mockup Prompt", placeholder="Enter a mockup description...", lines=5)
|
| 149 |
mock_generate = gr.Button("Generate Mockup")
|
| 150 |
mock_image = gr.Image(label="Generated Mockup")
|
| 151 |
-
with gr.Accordion("Example Prompts", open=False):
|
| 152 |
for ex in example_prompts["Mockup"]:
|
| 153 |
gr.Button(ex, variant="secondary").click(fn=lambda ex=ex: set_prompt(ex), outputs=mock_prompt)
|
| 154 |
|
| 155 |
-
|
| 156 |
with gr.Tab("Diagram"):
|
| 157 |
diag_prompt = gr.Textbox(label="Diagram Prompt", placeholder="Enter a diagram description...", lines=5)
|
| 158 |
diag_generate = gr.Button("Generate Diagram")
|
| 159 |
diag_image = gr.Image(label="Generated Diagram")
|
| 160 |
-
with gr.Accordion("Example Prompts", open=False):
|
| 161 |
for ex in example_prompts["Diagram"]:
|
| 162 |
gr.Button(ex, variant="secondary").click(fn=lambda ex=ex: set_prompt(ex), outputs=diag_prompt)
|
| 163 |
-
|
| 164 |
-
## Design 탭
|
| 165 |
-
with gr.Tab("Design"):
|
| 166 |
-
des_prompt = gr.Textbox(label="Design Prompt", placeholder="Enter a design concept...", lines=5)
|
| 167 |
-
des_generate = gr.Button("Generate Design")
|
| 168 |
-
des_image = gr.Image(label="Generated Design")
|
| 169 |
-
with gr.Accordion("Example Prompts", open=False):
|
| 170 |
-
for ex in example_prompts["Design"]:
|
| 171 |
-
gr.Button(ex, variant="secondary").click(fn=lambda ex=ex: set_prompt(ex), outputs=des_prompt)
|
| 172 |
-
|
| 173 |
-
# 좌측 사이드바: 공통 생성 파라미터
|
| 174 |
-
with gr.Sidebar(label="Parameters", open=True):
|
| 175 |
-
gr.Markdown("### Generation Parameters")
|
| 176 |
-
seed_slider = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=42)
|
| 177 |
-
randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
|
| 178 |
-
width_slider = gr.Slider(label="Width", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=1024)
|
| 179 |
-
height_slider = gr.Slider(label="Height", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=1024)
|
| 180 |
-
steps_slider = gr.Slider(label="Inference Steps", minimum=1, maximum=50, step=1, value=20)
|
| 181 |
-
guidance_slider = gr.Slider(label="Guidance Scale", minimum=0.0, maximum=15.0, step=0.5, value=7.5)
|
| 182 |
|
| 183 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
flow_generate.click(
|
| 185 |
fn=generate_image,
|
| 186 |
inputs=[flow_prompt, seed_slider, randomize_seed, width_slider, height_slider, steps_slider, guidance_slider],
|
|
@@ -204,12 +211,6 @@ with gr.Blocks(css=css, title="비즈니스 에이전트 이미지 생성기") a
|
|
| 204 |
inputs=[diag_prompt, seed_slider, randomize_seed, width_slider, height_slider, steps_slider, guidance_slider],
|
| 205 |
outputs=[diag_image, seed_slider]
|
| 206 |
)
|
| 207 |
-
|
| 208 |
-
des_generate.click(
|
| 209 |
-
fn=generate_image,
|
| 210 |
-
inputs=[des_prompt, seed_slider, randomize_seed, width_slider, height_slider, steps_slider, guidance_slider],
|
| 211 |
-
outputs=[des_image, seed_slider]
|
| 212 |
-
)
|
| 213 |
|
| 214 |
if __name__ == "__main__":
|
| 215 |
demo.queue()
|
|
|
|
| 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
|
|
|
|
| 33 |
).images[0]
|
| 34 |
return image, seed
|
| 35 |
|
| 36 |
+
def set_prompt(example_text):
|
| 37 |
+
return example_text
|
| 38 |
+
|
| 39 |
+
# Example prompts per tab (each with "AI Electric Bicycle", "Dog-shaped Toy Robot", "Drone")
|
| 40 |
+
example_prompts = {
|
| 41 |
+
"Product Design": [
|
| 42 |
+
"A futuristic product design of an AI electric bicycle with modern aesthetics and advanced technology.",
|
| 43 |
+
"A playful product design for a dog-shaped toy robot, cute and interactive.",
|
| 44 |
+
"An innovative product design for a drone, sleek and highly functional."
|
| 45 |
+
],
|
| 46 |
+
"Flowchart": [
|
| 47 |
+
"A flowchart outlining the design and development process for an AI electric bicycle—from concept to production.",
|
| 48 |
+
"A flowchart detailing the workflow for designing a dog-shaped toy robot, from brainstorming to testing.",
|
| 49 |
+
"A flowchart mapping out the design process for a drone, including ideation and final assembly."
|
| 50 |
+
],
|
| 51 |
+
"Infographic": [
|
| 52 |
+
"An infographic presenting key statistics and design features of an AI electric bicycle, with modern icons and graphics.",
|
| 53 |
+
"An infographic showing the design evolution of a dog-shaped toy robot, with sketches and key milestones.",
|
| 54 |
+
"An infographic summarizing the innovative features of a drone design, with visual data and timelines."
|
| 55 |
+
],
|
| 56 |
+
"Mockup": [
|
| 57 |
+
"A mockup sketch of an AI electric bicycle interface and dashboard, showcasing futuristic control panels.",
|
| 58 |
+
"A mockup wireframe for a dog-shaped toy robot's app interface, highlighting playful interactions.",
|
| 59 |
+
"A mockup of a drone's control system and layout, featuring modern UX elements."
|
| 60 |
+
],
|
| 61 |
+
"Diagram": [
|
| 62 |
+
"A diagram illustrating the structural design and workflow of an AI electric bicycle, with clear stages and connections.",
|
| 63 |
+
"A diagram outlining the components and design process of a dog-shaped toy robot, with labeled sections.",
|
| 64 |
+
"A diagram showcasing the technical design and assembly process of a drone, with step-by-step visuals."
|
| 65 |
+
]
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
# CSS style: prevent example Accordion from expanding into the sidebar
|
| 69 |
css = """
|
| 70 |
+
* {
|
| 71 |
+
box-sizing: border-box;
|
| 72 |
+
}
|
| 73 |
body {
|
| 74 |
background: linear-gradient(135deg, #667eea, #764ba2);
|
| 75 |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
|
|
|
| 85 |
margin: 40px auto;
|
| 86 |
max-width: 1200px;
|
| 87 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
.sidebar {
|
| 89 |
background: rgba(255, 255, 255, 0.98);
|
| 90 |
border-radius: 10px;
|
|
|
|
| 106 |
button:hover, .btn:hover {
|
| 107 |
transform: scale(1.05);
|
| 108 |
}
|
| 109 |
+
.example-accordion {
|
| 110 |
+
max-width: 100% !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
}
|
| 112 |
+
"""
|
| 113 |
|
| 114 |
+
with gr.Blocks(css=css, title="Business Agent") as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
gr.Markdown(
|
| 116 |
"""
|
| 117 |
<div style="text-align:center;">
|
| 118 |
+
<h1>Business Agent</h1>
|
| 119 |
+
<p>Generate design concepts and workflow diagrams for your business needs using our multi-tab interface.</p>
|
| 120 |
+
<p><strong>AI Spaces:</strong> Product Design, Flowchart, Infographic, Mockup, Diagram</p>
|
| 121 |
</div>
|
| 122 |
"""
|
| 123 |
)
|
| 124 |
|
| 125 |
with gr.Row():
|
| 126 |
+
# Left sidebar: Common generation parameters
|
| 127 |
+
with gr.Sidebar(label="Parameters", open=True):
|
| 128 |
+
gr.Markdown("### Generation Parameters")
|
| 129 |
+
seed_slider = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=42)
|
| 130 |
+
randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
|
| 131 |
+
width_slider = gr.Slider(label="Width", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=1024)
|
| 132 |
+
height_slider = gr.Slider(label="Height", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=1024)
|
| 133 |
+
steps_slider = gr.Slider(label="Inference Steps", minimum=1, maximum=50, step=1, value=20)
|
| 134 |
+
guidance_slider = gr.Slider(label="Guidance Scale", minimum=0.0, maximum=15.0, step=0.5, value=7.5)
|
| 135 |
+
|
| 136 |
+
# Main area: Tabbed interface for different design types (first tab: Product Design)
|
| 137 |
with gr.Column(scale=8):
|
| 138 |
with gr.Tabs():
|
| 139 |
+
# First tab: Product Design
|
| 140 |
+
with gr.Tab("Product Design"):
|
| 141 |
+
pd_prompt = gr.Textbox(label="Product Design Prompt", placeholder="Enter a product design concept...", lines=5)
|
| 142 |
+
pd_generate = gr.Button("Generate Product Design")
|
| 143 |
+
pd_image = gr.Image(label="Generated Product Design")
|
| 144 |
+
with gr.Accordion("Example Prompts", open=False, elem_classes="example-accordion"):
|
| 145 |
+
for ex in example_prompts["Product Design"]:
|
| 146 |
+
gr.Button(ex, variant="secondary").click(fn=lambda ex=ex: set_prompt(ex), outputs=pd_prompt)
|
| 147 |
+
|
| 148 |
+
# Second tab: Flowchart
|
| 149 |
with gr.Tab("Flowchart"):
|
| 150 |
flow_prompt = gr.Textbox(label="Flowchart Prompt", placeholder="Enter a flowchart description...", lines=5)
|
| 151 |
flow_generate = gr.Button("Generate Flowchart")
|
| 152 |
flow_image = gr.Image(label="Generated Flowchart")
|
| 153 |
+
with gr.Accordion("Example Prompts", open=False, elem_classes="example-accordion"):
|
| 154 |
for ex in example_prompts["Flowchart"]:
|
| 155 |
gr.Button(ex, variant="secondary").click(fn=lambda ex=ex: set_prompt(ex), outputs=flow_prompt)
|
| 156 |
|
| 157 |
+
# Third tab: Infographic
|
| 158 |
with gr.Tab("Infographic"):
|
| 159 |
info_prompt = gr.Textbox(label="Infographic Prompt", placeholder="Enter an infographic description...", lines=5)
|
| 160 |
info_generate = gr.Button("Generate Infographic")
|
| 161 |
info_image = gr.Image(label="Generated Infographic")
|
| 162 |
+
with gr.Accordion("Example Prompts", open=False, elem_classes="example-accordion"):
|
| 163 |
for ex in example_prompts["Infographic"]:
|
| 164 |
gr.Button(ex, variant="secondary").click(fn=lambda ex=ex: set_prompt(ex), outputs=info_prompt)
|
| 165 |
|
| 166 |
+
# Fourth tab: Mockup
|
| 167 |
with gr.Tab("Mockup"):
|
| 168 |
mock_prompt = gr.Textbox(label="Mockup Prompt", placeholder="Enter a mockup description...", lines=5)
|
| 169 |
mock_generate = gr.Button("Generate Mockup")
|
| 170 |
mock_image = gr.Image(label="Generated Mockup")
|
| 171 |
+
with gr.Accordion("Example Prompts", open=False, elem_classes="example-accordion"):
|
| 172 |
for ex in example_prompts["Mockup"]:
|
| 173 |
gr.Button(ex, variant="secondary").click(fn=lambda ex=ex: set_prompt(ex), outputs=mock_prompt)
|
| 174 |
|
| 175 |
+
# Fifth tab: Diagram
|
| 176 |
with gr.Tab("Diagram"):
|
| 177 |
diag_prompt = gr.Textbox(label="Diagram Prompt", placeholder="Enter a diagram description...", lines=5)
|
| 178 |
diag_generate = gr.Button("Generate Diagram")
|
| 179 |
diag_image = gr.Image(label="Generated Diagram")
|
| 180 |
+
with gr.Accordion("Example Prompts", open=False, elem_classes="example-accordion"):
|
| 181 |
for ex in example_prompts["Diagram"]:
|
| 182 |
gr.Button(ex, variant="secondary").click(fn=lambda ex=ex: set_prompt(ex), outputs=diag_prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
|
| 184 |
+
# Bind events for generation buttons
|
| 185 |
+
pd_generate.click(
|
| 186 |
+
fn=generate_image,
|
| 187 |
+
inputs=[pd_prompt, seed_slider, randomize_seed, width_slider, height_slider, steps_slider, guidance_slider],
|
| 188 |
+
outputs=[pd_image, seed_slider]
|
| 189 |
+
)
|
| 190 |
+
|
| 191 |
flow_generate.click(
|
| 192 |
fn=generate_image,
|
| 193 |
inputs=[flow_prompt, seed_slider, randomize_seed, width_slider, height_slider, steps_slider, guidance_slider],
|
|
|
|
| 211 |
inputs=[diag_prompt, seed_slider, randomize_seed, width_slider, height_slider, steps_slider, guidance_slider],
|
| 212 |
outputs=[diag_image, seed_slider]
|
| 213 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
|
| 215 |
if __name__ == "__main__":
|
| 216 |
demo.queue()
|