Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -104,97 +104,7 @@ pipe.safety_checker = safety_checker.StableDiffusionSafetyChecker.from_pretraine
|
|
| 104 |
"CompVis/stable-diffusion-safety-checker"
|
| 105 |
)
|
| 106 |
|
| 107 |
-
# CSS 스타일
|
| 108 |
-
css = """
|
| 109 |
-
footer {display: none !important}
|
| 110 |
-
.gradio-container {
|
| 111 |
-
max-width: 1200px;
|
| 112 |
-
margin: auto;
|
| 113 |
-
}
|
| 114 |
-
.contain {
|
| 115 |
-
background: rgba(255, 255, 255, 0.05);
|
| 116 |
-
border-radius: 12px;
|
| 117 |
-
padding: 20px;
|
| 118 |
-
}
|
| 119 |
-
.generate-btn {
|
| 120 |
-
background: linear-gradient(90deg, #4B79A1 0%, #283E51 100%) !important;
|
| 121 |
-
border: none !important;
|
| 122 |
-
color: white !important;
|
| 123 |
-
}
|
| 124 |
-
.generate-btn:hover {
|
| 125 |
-
transform: translateY(-2px);
|
| 126 |
-
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
|
| 127 |
-
}
|
| 128 |
-
.title {
|
| 129 |
-
text-align: center;
|
| 130 |
-
font-size: 2.5em;
|
| 131 |
-
font-weight: bold;
|
| 132 |
-
margin-bottom: 1em;
|
| 133 |
-
background: linear-gradient(90deg, #4B79A1 0%, #283E51 100%);
|
| 134 |
-
-webkit-background-clip: text;
|
| 135 |
-
-webkit-text-fill-color: transparent;
|
| 136 |
-
}
|
| 137 |
-
.tabs {
|
| 138 |
-
margin-top: 20px;
|
| 139 |
-
border-radius: 10px;
|
| 140 |
-
overflow: hidden;
|
| 141 |
-
}
|
| 142 |
-
.tab-nav {
|
| 143 |
-
background: linear-gradient(90deg, #4B79A1 0%, #283E51 100%);
|
| 144 |
-
padding: 10px;
|
| 145 |
-
}
|
| 146 |
-
.tab-nav button {
|
| 147 |
-
color: white;
|
| 148 |
-
border: none;
|
| 149 |
-
padding: 10px 20px;
|
| 150 |
-
margin: 0 5px;
|
| 151 |
-
border-radius: 5px;
|
| 152 |
-
transition: all 0.3s ease;
|
| 153 |
-
}
|
| 154 |
-
.tab-nav button.selected {
|
| 155 |
-
background: rgba(255, 255, 255, 0.2);
|
| 156 |
-
}
|
| 157 |
-
.image-upload-container {
|
| 158 |
-
border: 2px dashed #4B79A1;
|
| 159 |
-
border-radius: 10px;
|
| 160 |
-
padding: 20px;
|
| 161 |
-
text-align: center;
|
| 162 |
-
transition: all 0.3s ease;
|
| 163 |
-
}
|
| 164 |
-
.image-upload-container:hover {
|
| 165 |
-
border-color: #283E51;
|
| 166 |
-
background: rgba(75, 121, 161, 0.1);
|
| 167 |
-
}
|
| 168 |
-
"""
|
| 169 |
-
|
| 170 |
-
# CSS에 추가할 스타일
|
| 171 |
-
additional_css = """
|
| 172 |
-
.primary-btn {
|
| 173 |
-
background: linear-gradient(90deg, #4B79A1 0%, #283E51 100%) !important;
|
| 174 |
-
font-size: 1.2em !important;
|
| 175 |
-
padding: 12px 20px !important;
|
| 176 |
-
margin-top: 20px !important;
|
| 177 |
-
}
|
| 178 |
-
hr {
|
| 179 |
-
border: none;
|
| 180 |
-
border-top: 1px solid rgba(75, 121, 161, 0.2);
|
| 181 |
-
margin: 20px 0;
|
| 182 |
-
}
|
| 183 |
-
.input-section {
|
| 184 |
-
background: rgba(255, 255, 255, 0.03);
|
| 185 |
-
border-radius: 12px;
|
| 186 |
-
padding: 20px;
|
| 187 |
-
margin-bottom: 20px;
|
| 188 |
-
}
|
| 189 |
-
.output-section {
|
| 190 |
-
background: rgba(255, 255, 255, 0.03);
|
| 191 |
-
border-radius: 12px;
|
| 192 |
-
padding: 20px;
|
| 193 |
-
}
|
| 194 |
-
"""
|
| 195 |
|
| 196 |
-
# 기존 CSS에 새로운 스타일 추가
|
| 197 |
-
css = css + additional_css
|
| 198 |
|
| 199 |
def save_image(image):
|
| 200 |
"""Save the generated image and return the path"""
|
|
@@ -305,6 +215,108 @@ def get_random_seed():
|
|
| 305 |
def update_seed():
|
| 306 |
return get_random_seed()
|
| 307 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 308 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
| 309 |
gr.HTML('<div class="title">AI Image Generator & Caption</div>')
|
| 310 |
gr.HTML('<div style="text-align: center; margin-bottom: 2em;">Upload an image for caption or create from text description</div>')
|
|
@@ -319,11 +331,26 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
| 319 |
elem_classes=["image-upload-container"]
|
| 320 |
)
|
| 321 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
florence_model = gr.Dropdown(
|
| 323 |
choices=list(florence_models.keys()),
|
| 324 |
label="Caption Model",
|
| 325 |
value='gokaygokay/Florence-2-Flux-Large',
|
| 326 |
-
visible=
|
| 327 |
)
|
| 328 |
|
| 329 |
caption_button = gr.Button(
|
|
@@ -433,4 +460,4 @@ with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
|
| 433 |
)
|
| 434 |
|
| 435 |
if __name__ == "__main__":
|
| 436 |
-
demo.launch(allowed_paths=[PERSISTENT_DIR])
|
|
|
|
| 104 |
"CompVis/stable-diffusion-safety-checker"
|
| 105 |
)
|
| 106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
|
|
|
|
|
|
| 108 |
|
| 109 |
def save_image(image):
|
| 110 |
"""Save the generated image and return the path"""
|
|
|
|
| 215 |
def update_seed():
|
| 216 |
return get_random_seed()
|
| 217 |
|
| 218 |
+
# CSS 스타일
|
| 219 |
+
css = """
|
| 220 |
+
footer {display: none !important}
|
| 221 |
+
.gradio-container {
|
| 222 |
+
max-width: 1200px;
|
| 223 |
+
margin: auto;
|
| 224 |
+
}
|
| 225 |
+
.contain {
|
| 226 |
+
background: rgba(255, 255, 255, 0.05);
|
| 227 |
+
border-radius: 12px;
|
| 228 |
+
padding: 20px;
|
| 229 |
+
}
|
| 230 |
+
.generate-btn {
|
| 231 |
+
background: linear-gradient(90deg, #4B79A1 0%, #283E51 100%) !important;
|
| 232 |
+
border: none !important;
|
| 233 |
+
color: white !important;
|
| 234 |
+
}
|
| 235 |
+
.generate-btn:hover {
|
| 236 |
+
transform: translateY(-2px);
|
| 237 |
+
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
|
| 238 |
+
}
|
| 239 |
+
.title {
|
| 240 |
+
text-align: center;
|
| 241 |
+
font-size: 2.5em;
|
| 242 |
+
font-weight: bold;
|
| 243 |
+
margin-bottom: 1em;
|
| 244 |
+
background: linear-gradient(90deg, #4B79A1 0%, #283E51 100%);
|
| 245 |
+
-webkit-background-clip: text;
|
| 246 |
+
-webkit-text-fill-color: transparent;
|
| 247 |
+
}
|
| 248 |
+
.tabs {
|
| 249 |
+
margin-top: 20px;
|
| 250 |
+
border-radius: 10px;
|
| 251 |
+
overflow: hidden;
|
| 252 |
+
}
|
| 253 |
+
.tab-nav {
|
| 254 |
+
background: linear-gradient(90deg, #4B79A1 0%, #283E51 100%);
|
| 255 |
+
padding: 10px;
|
| 256 |
+
}
|
| 257 |
+
.tab-nav button {
|
| 258 |
+
color: white;
|
| 259 |
+
border: none;
|
| 260 |
+
padding: 10px 20px;
|
| 261 |
+
margin: 0 5px;
|
| 262 |
+
border-radius: 5px;
|
| 263 |
+
transition: all 0.3s ease;
|
| 264 |
+
}
|
| 265 |
+
.tab-nav button.selected {
|
| 266 |
+
background: rgba(255, 255, 255, 0.2);
|
| 267 |
+
}
|
| 268 |
+
.image-upload-container {
|
| 269 |
+
border: 2px dashed #4B79A1;
|
| 270 |
+
border-radius: 10px;
|
| 271 |
+
padding: 20px;
|
| 272 |
+
text-align: center;
|
| 273 |
+
transition: all 0.3s ease;
|
| 274 |
+
}
|
| 275 |
+
.image-upload-container:hover {
|
| 276 |
+
border-color: #283E51;
|
| 277 |
+
background: rgba(75, 121, 161, 0.1);
|
| 278 |
+
}
|
| 279 |
+
.primary-btn {
|
| 280 |
+
background: linear-gradient(90deg, #4B79A1 0%, #283E51 100%) !important;
|
| 281 |
+
font-size: 1.2em !important;
|
| 282 |
+
padding: 12px 20px !important;
|
| 283 |
+
margin-top: 20px !important;
|
| 284 |
+
}
|
| 285 |
+
hr {
|
| 286 |
+
border: none;
|
| 287 |
+
border-top: 1px solid rgba(75, 121, 161, 0.2);
|
| 288 |
+
margin: 20px 0;
|
| 289 |
+
}
|
| 290 |
+
.input-section {
|
| 291 |
+
background: rgba(255, 255, 255, 0.03);
|
| 292 |
+
border-radius: 12px;
|
| 293 |
+
padding: 20px;
|
| 294 |
+
margin-bottom: 20px;
|
| 295 |
+
}
|
| 296 |
+
.output-section {
|
| 297 |
+
background: rgba(255, 255, 255, 0.03);
|
| 298 |
+
border-radius: 12px;
|
| 299 |
+
padding: 20px;
|
| 300 |
+
}
|
| 301 |
+
.example-images {
|
| 302 |
+
display: grid;
|
| 303 |
+
grid-template-columns: repeat(4, 1fr);
|
| 304 |
+
gap: 10px;
|
| 305 |
+
margin-bottom: 20px;
|
| 306 |
+
}
|
| 307 |
+
.example-images img {
|
| 308 |
+
width: 100%;
|
| 309 |
+
height: 150px;
|
| 310 |
+
object-fit: cover;
|
| 311 |
+
border-radius: 8px;
|
| 312 |
+
cursor: pointer;
|
| 313 |
+
transition: transform 0.2s;
|
| 314 |
+
}
|
| 315 |
+
.example-images img:hover {
|
| 316 |
+
transform: scale(1.05);
|
| 317 |
+
}
|
| 318 |
+
"""
|
| 319 |
+
|
| 320 |
with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo:
|
| 321 |
gr.HTML('<div class="title">AI Image Generator & Caption</div>')
|
| 322 |
gr.HTML('<div style="text-align: center; margin-bottom: 2em;">Upload an image for caption or create from text description</div>')
|
|
|
|
| 331 |
elem_classes=["image-upload-container"]
|
| 332 |
)
|
| 333 |
|
| 334 |
+
# 예시 이미지 갤러리 추가
|
| 335 |
+
example_images = [
|
| 336 |
+
"1.jpg",
|
| 337 |
+
"2.jpg",
|
| 338 |
+
"3.jpg",
|
| 339 |
+
"4.jpg"
|
| 340 |
+
]
|
| 341 |
+
gr.Examples(
|
| 342 |
+
examples=example_images,
|
| 343 |
+
inputs=input_image,
|
| 344 |
+
label="Example Images",
|
| 345 |
+
examples_per_page=4
|
| 346 |
+
)
|
| 347 |
+
|
| 348 |
+
# Florence 모델 선택 - 숨김 처리
|
| 349 |
florence_model = gr.Dropdown(
|
| 350 |
choices=list(florence_models.keys()),
|
| 351 |
label="Caption Model",
|
| 352 |
value='gokaygokay/Florence-2-Flux-Large',
|
| 353 |
+
visible=False
|
| 354 |
)
|
| 355 |
|
| 356 |
caption_button = gr.Button(
|
|
|
|
| 460 |
)
|
| 461 |
|
| 462 |
if __name__ == "__main__":
|
| 463 |
+
demo.launch(allowed_paths=[PERSISTENT_DIR])
|