Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ import gradio as gr
|
|
| 9 |
import torch
|
| 10 |
from diffusers import FluxPipeline
|
| 11 |
|
| 12 |
-
# Setup and initialization code
|
| 13 |
cache_path = path.join(path.dirname(path.abspath(__file__)), "models")
|
| 14 |
os.environ["TRANSFORMERS_CACHE"] = cache_path
|
| 15 |
os.environ["HF_HUB_CACHE"] = cache_path
|
|
@@ -35,142 +35,101 @@ pipe.load_lora_weights(hf_hub_download("ByteDance/Hyper-SD", "Hyper-FLUX.1-dev-8
|
|
| 35 |
pipe.fuse_lora(lora_scale=0.125)
|
| 36 |
pipe.to(device="cuda", dtype=torch.bfloat16)
|
| 37 |
|
| 38 |
-
# Custom CSS
|
| 39 |
css = """
|
| 40 |
footer {display: none !important}
|
| 41 |
-
.container {max-width: 1200px; margin: auto;}
|
| 42 |
-
.
|
| 43 |
-
.
|
| 44 |
-
|
| 45 |
-
border
|
| 46 |
-
|
| 47 |
-
border: none;
|
| 48 |
-
color: white;
|
| 49 |
-
transition: transform 0.2s ease;
|
| 50 |
}
|
| 51 |
-
.
|
| 52 |
transform: translateY(-2px);
|
| 53 |
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
|
| 54 |
}
|
| 55 |
-
.
|
| 56 |
-
.gr-input:focus {border-color: #4B79A1 !important;}
|
| 57 |
-
.title-text {
|
| 58 |
text-align: center;
|
| 59 |
font-size: 2.5em;
|
| 60 |
font-weight: bold;
|
|
|
|
| 61 |
background: linear-gradient(90deg, #4B79A1 0%, #283E51 100%);
|
| 62 |
-webkit-background-clip: text;
|
| 63 |
-webkit-text-fill-color: transparent;
|
| 64 |
-
margin-bottom: 1em;
|
| 65 |
}
|
| 66 |
"""
|
| 67 |
|
| 68 |
-
# Create Gradio interface
|
| 69 |
-
with gr.Blocks(theme=gr.themes.Soft(
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
neutral_hue="slate",
|
| 73 |
-
font=gr.themes.GoogleFont("Inter")
|
| 74 |
-
), css=css) as demo:
|
| 75 |
-
|
| 76 |
-
gr.HTML("""
|
| 77 |
-
<div class="title-text">AI Image Generator</div>
|
| 78 |
-
<div style="text-align: center; margin-bottom: 2em; color: #666;">
|
| 79 |
-
Create stunning images from your descriptions using advanced AI
|
| 80 |
-
</div>
|
| 81 |
-
""")
|
| 82 |
|
| 83 |
-
with gr.Row()
|
| 84 |
with gr.Column(scale=3):
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
-
with gr.
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
minimum=256,
|
| 109 |
-
maximum=1152,
|
| 110 |
-
step=64,
|
| 111 |
-
value=1024,
|
| 112 |
-
elem_classes="gr-input"
|
| 113 |
-
)
|
| 114 |
-
|
| 115 |
-
with gr.Row():
|
| 116 |
-
with gr.Column(scale=1):
|
| 117 |
-
steps = gr.Slider(
|
| 118 |
-
label="Inference Steps",
|
| 119 |
-
minimum=6,
|
| 120 |
-
maximum=25,
|
| 121 |
-
step=1,
|
| 122 |
-
value=8,
|
| 123 |
-
elem_classes="gr-input"
|
| 124 |
-
)
|
| 125 |
-
with gr.Column(scale=1):
|
| 126 |
-
scales = gr.Slider(
|
| 127 |
-
label="Guidance Scale",
|
| 128 |
-
minimum=0.0,
|
| 129 |
-
maximum=5.0,
|
| 130 |
-
step=0.1,
|
| 131 |
-
value=3.5,
|
| 132 |
-
elem_classes="gr-input"
|
| 133 |
-
)
|
| 134 |
-
|
| 135 |
-
seed = gr.Number(
|
| 136 |
-
label="Seed (for reproducibility)",
|
| 137 |
-
value=3413,
|
| 138 |
-
precision=0,
|
| 139 |
-
elem_classes="gr-input"
|
| 140 |
-
)
|
| 141 |
|
| 142 |
-
|
| 143 |
-
"
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
elem_classes="gr-button"
|
| 147 |
)
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
<ul style="margin: 0; padding-left: 1.2em;">
|
| 153 |
-
<li>Be specific in your descriptions</li>
|
| 154 |
-
<li>Include details about style, lighting, and mood</li>
|
| 155 |
-
<li>Experiment with different guidance scales</li>
|
| 156 |
-
</ul>
|
| 157 |
-
</div>
|
| 158 |
-
""")
|
| 159 |
-
|
| 160 |
-
with gr.Column(scale=4):
|
| 161 |
-
output = gr.Image(
|
| 162 |
-
label="Generated Image",
|
| 163 |
-
elem_classes="gr-box",
|
| 164 |
-
height=512
|
| 165 |
)
|
| 166 |
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
<
|
| 170 |
-
|
| 171 |
-
<
|
| 172 |
-
|
| 173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
@spaces.GPU
|
| 176 |
def process_image(height, width, steps, scales, prompt, seed):
|
|
@@ -186,18 +145,10 @@ with gr.Blocks(theme=gr.themes.Soft(
|
|
| 186 |
max_sequence_length=256
|
| 187 |
).images[0]
|
| 188 |
|
| 189 |
-
# Add loading state
|
| 190 |
generate_btn.click(
|
| 191 |
-
fn=lambda: gr.update(visible=True),
|
| 192 |
-
outputs=[loading_info],
|
| 193 |
-
queue=False
|
| 194 |
-
).then(
|
| 195 |
process_image,
|
| 196 |
inputs=[height, width, steps, scales, prompt, seed],
|
| 197 |
outputs=output
|
| 198 |
-
).then(
|
| 199 |
-
fn=lambda: gr.update(visible=False),
|
| 200 |
-
outputs=[loading_info]
|
| 201 |
)
|
| 202 |
|
| 203 |
if __name__ == "__main__":
|
|
|
|
| 9 |
import torch
|
| 10 |
from diffusers import FluxPipeline
|
| 11 |
|
| 12 |
+
# Setup and initialization code
|
| 13 |
cache_path = path.join(path.dirname(path.abspath(__file__)), "models")
|
| 14 |
os.environ["TRANSFORMERS_CACHE"] = cache_path
|
| 15 |
os.environ["HF_HUB_CACHE"] = cache_path
|
|
|
|
| 35 |
pipe.fuse_lora(lora_scale=0.125)
|
| 36 |
pipe.to(device="cuda", dtype=torch.bfloat16)
|
| 37 |
|
| 38 |
+
# Custom CSS
|
| 39 |
css = """
|
| 40 |
footer {display: none !important}
|
| 41 |
+
.gradio-container {max-width: 1200px; margin: auto;}
|
| 42 |
+
.contain {background: rgba(255, 255, 255, 0.05); border-radius: 12px; padding: 20px;}
|
| 43 |
+
.generate-btn {
|
| 44 |
+
background: linear-gradient(90deg, #4B79A1 0%, #283E51 100%) !important;
|
| 45 |
+
border: none !important;
|
| 46 |
+
color: white !important;
|
|
|
|
|
|
|
|
|
|
| 47 |
}
|
| 48 |
+
.generate-btn:hover {
|
| 49 |
transform: translateY(-2px);
|
| 50 |
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
|
| 51 |
}
|
| 52 |
+
.title {
|
|
|
|
|
|
|
| 53 |
text-align: center;
|
| 54 |
font-size: 2.5em;
|
| 55 |
font-weight: bold;
|
| 56 |
+
margin-bottom: 1em;
|
| 57 |
background: linear-gradient(90deg, #4B79A1 0%, #283E51 100%);
|
| 58 |
-webkit-background-clip: text;
|
| 59 |
-webkit-text-fill-color: transparent;
|
|
|
|
| 60 |
}
|
| 61 |
"""
|
| 62 |
|
| 63 |
+
# Create Gradio interface
|
| 64 |
+
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
| 65 |
+
gr.HTML('<div class="title">AI Image Generator</div>')
|
| 66 |
+
gr.HTML('<div style="text-align: center; margin-bottom: 2em; color: #666;">Create stunning images from your descriptions</div>')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
+
with gr.Row():
|
| 69 |
with gr.Column(scale=3):
|
| 70 |
+
prompt = gr.Textbox(
|
| 71 |
+
label="Image Description",
|
| 72 |
+
placeholder="Describe the image you want to create...",
|
| 73 |
+
lines=3
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
with gr.Accordion("Advanced Settings", open=False):
|
| 77 |
+
with gr.Row():
|
| 78 |
+
height = gr.Slider(
|
| 79 |
+
label="Height",
|
| 80 |
+
minimum=256,
|
| 81 |
+
maximum=1152,
|
| 82 |
+
step=64,
|
| 83 |
+
value=1024
|
| 84 |
+
)
|
| 85 |
+
width = gr.Slider(
|
| 86 |
+
label="Width",
|
| 87 |
+
minimum=256,
|
| 88 |
+
maximum=1152,
|
| 89 |
+
step=64,
|
| 90 |
+
value=1024
|
| 91 |
+
)
|
| 92 |
|
| 93 |
+
with gr.Row():
|
| 94 |
+
steps = gr.Slider(
|
| 95 |
+
label="Inference Steps",
|
| 96 |
+
minimum=6,
|
| 97 |
+
maximum=25,
|
| 98 |
+
step=1,
|
| 99 |
+
value=8
|
| 100 |
+
)
|
| 101 |
+
scales = gr.Slider(
|
| 102 |
+
label="Guidance Scale",
|
| 103 |
+
minimum=0.0,
|
| 104 |
+
maximum=5.0,
|
| 105 |
+
step=0.1,
|
| 106 |
+
value=3.5
|
| 107 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
+
seed = gr.Number(
|
| 110 |
+
label="Seed (for reproducibility)",
|
| 111 |
+
value=3413,
|
| 112 |
+
precision=0
|
|
|
|
| 113 |
)
|
| 114 |
+
|
| 115 |
+
generate_btn = gr.Button(
|
| 116 |
+
"✨ Generate Image",
|
| 117 |
+
elem_classes=["generate-btn"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
)
|
| 119 |
|
| 120 |
+
gr.HTML("""
|
| 121 |
+
<div style="margin-top: 1em; padding: 1em; border-radius: 8px; background: rgba(255, 255, 255, 0.05);">
|
| 122 |
+
<h4 style="margin: 0 0 0.5em 0;">Tips for best results:</h4>
|
| 123 |
+
<ul style="margin: 0; padding-left: 1.2em;">
|
| 124 |
+
<li>Be specific in your descriptions</li>
|
| 125 |
+
<li>Include details about style, lighting, and mood</li>
|
| 126 |
+
<li>Experiment with different guidance scales</li>
|
| 127 |
+
</ul>
|
| 128 |
+
</div>
|
| 129 |
+
""")
|
| 130 |
+
|
| 131 |
+
with gr.Column(scale=4):
|
| 132 |
+
output = gr.Image(label="Generated Image")
|
| 133 |
|
| 134 |
@spaces.GPU
|
| 135 |
def process_image(height, width, steps, scales, prompt, seed):
|
|
|
|
| 145 |
max_sequence_length=256
|
| 146 |
).images[0]
|
| 147 |
|
|
|
|
| 148 |
generate_btn.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
process_image,
|
| 150 |
inputs=[height, width, steps, scales, prompt, seed],
|
| 151 |
outputs=output
|
|
|
|
|
|
|
|
|
|
| 152 |
)
|
| 153 |
|
| 154 |
if __name__ == "__main__":
|