Update app.py
Browse files
app.py
CHANGED
|
@@ -151,63 +151,247 @@ def remove_objects(image, object_name, guidance_scale, steps):
|
|
| 151 |
except Exception as e:
|
| 152 |
return image, f"❌ Error: {str(e)}"
|
| 153 |
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
|
| 178 |
-
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
with gr.Row():
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
with gr.Row():
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
|
| 199 |
-
|
|
|
|
| 200 |
process_btn.click(
|
| 201 |
-
fn=
|
| 202 |
-
inputs=[input_image, object_name,
|
| 203 |
-
outputs=[
|
| 204 |
)
|
| 205 |
-
|
| 206 |
-
#
|
| 207 |
object_name.submit(
|
| 208 |
-
fn=
|
| 209 |
-
inputs=[input_image, object_name,
|
| 210 |
-
outputs=[
|
| 211 |
)
|
| 212 |
|
| 213 |
if __name__ == "__main__":
|
|
|
|
| 151 |
except Exception as e:
|
| 152 |
return image, f"❌ Error: {str(e)}"
|
| 153 |
|
| 154 |
+
# Custom CSS for modern chat-like interface
|
| 155 |
+
custom_css = """
|
| 156 |
+
/* Global Styles */
|
| 157 |
+
.gradio-container {
|
| 158 |
+
background: linear-gradient(135deg, #0a0a0a 0%, #1a1a2e 50%, #16213e 100%) !important;
|
| 159 |
+
color: white !important;
|
| 160 |
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
|
| 161 |
+
}
|
| 162 |
+
/* Header Styling */
|
| 163 |
+
.header-text h1 {
|
| 164 |
+
background: linear-gradient(45deg, #00ff88, #00ccff) !important;
|
| 165 |
+
-webkit-background-clip: text !important;
|
| 166 |
+
-webkit-text-fill-color: transparent !important;
|
| 167 |
+
font-size: 2.5rem !important;
|
| 168 |
+
text-align: center !important;
|
| 169 |
+
margin-bottom: 1rem !important;
|
| 170 |
+
}
|
| 171 |
+
.header-text p {
|
| 172 |
+
text-align: center !important;
|
| 173 |
+
color: rgba(255, 255, 255, 0.8) !important;
|
| 174 |
+
font-size: 1.1rem !important;
|
| 175 |
+
margin-bottom: 2rem !important;
|
| 176 |
+
}
|
| 177 |
+
/* Chat Panel Styling */
|
| 178 |
+
.chat-panel {
|
| 179 |
+
background: rgba(20, 20, 30, 0.8) !important;
|
| 180 |
+
backdrop-filter: blur(20px) !important;
|
| 181 |
+
border-radius: 16px !important;
|
| 182 |
+
border: 1px solid rgba(255, 255, 255, 0.1) !important;
|
| 183 |
+
padding: 1.5rem !important;
|
| 184 |
+
margin-bottom: 1rem !important;
|
| 185 |
+
}
|
| 186 |
+
.chat-panel .gr-form {
|
| 187 |
+
background: transparent !important;
|
| 188 |
+
}
|
| 189 |
+
/* Input Styling */
|
| 190 |
+
.gr-textbox input, .gr-slider input {
|
| 191 |
+
background: rgba(255, 255, 255, 0.1) !important;
|
| 192 |
+
border: 1px solid rgba(255, 255, 255, 0.3) !important;
|
| 193 |
+
border-radius: 25px !important;
|
| 194 |
+
color: white !important;
|
| 195 |
+
padding: 12px 16px !important;
|
| 196 |
+
}
|
| 197 |
+
.gr-textbox input:focus, .gr-slider input:focus {
|
| 198 |
+
border-color: #00ff88 !important;
|
| 199 |
+
box-shadow: 0 0 0 2px rgba(0, 255, 136, 0.2) !important;
|
| 200 |
+
}
|
| 201 |
+
.gr-textbox input::placeholder {
|
| 202 |
+
color: rgba(255, 255, 255, 0.5) !important;
|
| 203 |
+
}
|
| 204 |
+
/* Button Styling */
|
| 205 |
+
.gr-button {
|
| 206 |
+
background: linear-gradient(135deg, #00ff88, #00ccff) !important;
|
| 207 |
+
border: none !important;
|
| 208 |
+
border-radius: 25px !important;
|
| 209 |
+
color: #000 !important;
|
| 210 |
+
font-weight: 600 !important;
|
| 211 |
+
padding: 12px 24px !important;
|
| 212 |
+
transition: all 0.3s ease !important;
|
| 213 |
+
}
|
| 214 |
+
.gr-button:hover {
|
| 215 |
+
transform: translateY(-2px) !important;
|
| 216 |
+
box-shadow: 0 8px 25px rgba(0, 255, 136, 0.3) !important;
|
| 217 |
+
}
|
| 218 |
+
/* Output Panel Styling */
|
| 219 |
+
.output-panel {
|
| 220 |
+
background: rgba(10, 10, 20, 0.8) !important;
|
| 221 |
+
backdrop-filter: blur(20px) !important;
|
| 222 |
+
border-radius: 16px !important;
|
| 223 |
+
border: 1px solid rgba(255, 255, 255, 0.1) !important;
|
| 224 |
+
padding: 1.5rem !important;
|
| 225 |
+
text-align: center !important;
|
| 226 |
+
}
|
| 227 |
+
.gr-image {
|
| 228 |
+
border-radius: 16px !important;
|
| 229 |
+
border: 2px solid rgba(255, 255, 255, 0.1) !important;
|
| 230 |
+
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4) !important;
|
| 231 |
+
}
|
| 232 |
+
/* Status Text Styling */
|
| 233 |
+
.gr-textbox textarea {
|
| 234 |
+
background: rgba(255, 193, 7, 0.1) !important;
|
| 235 |
+
border: 1px solid rgba(255, 193, 7, 0.3) !important;
|
| 236 |
+
color: #ffc107 !important;
|
| 237 |
+
border-radius: 12px !important;
|
| 238 |
+
}
|
| 239 |
+
/* File Upload Styling */
|
| 240 |
+
.gr-file-upload {
|
| 241 |
+
background: rgba(255, 255, 255, 0.1) !important;
|
| 242 |
+
border: 2px dashed rgba(255, 255, 255, 0.3) !important;
|
| 243 |
+
border-radius: 16px !important;
|
| 244 |
+
color: white !important;
|
| 245 |
+
}
|
| 246 |
+
/* Examples Styling */
|
| 247 |
+
.gr-examples {
|
| 248 |
+
background: rgba(255, 255, 255, 0.05) !important;
|
| 249 |
+
border-radius: 12px !important;
|
| 250 |
+
padding: 1rem !important;
|
| 251 |
+
}
|
| 252 |
+
.gr-examples .gr-button {
|
| 253 |
+
background: rgba(255, 255, 255, 0.1) !important;
|
| 254 |
+
color: white !important;
|
| 255 |
+
border: 1px solid rgba(255, 255, 255, 0.3) !important;
|
| 256 |
+
font-size: 0.9rem !important;
|
| 257 |
+
}
|
| 258 |
+
/* Accordion Styling */
|
| 259 |
+
.gr-accordion {
|
| 260 |
+
background: rgba(255, 255, 255, 0.05) !important;
|
| 261 |
+
border: 1px solid rgba(255, 255, 255, 0.1) !important;
|
| 262 |
+
border-radius: 12px !important;
|
| 263 |
+
}
|
| 264 |
+
.gr-accordion summary {
|
| 265 |
+
color: white !important;
|
| 266 |
+
font-weight: 500 !important;
|
| 267 |
+
}
|
| 268 |
+
/* Responsive adjustments */
|
| 269 |
+
@media (max-width: 768px) {
|
| 270 |
+
.gr-row {
|
| 271 |
+
flex-direction: column !important;
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
.header-text h1 {
|
| 275 |
+
font-size: 2rem !important;
|
| 276 |
+
}
|
| 277 |
+
}
|
| 278 |
+
"""
|
| 279 |
|
| 280 |
+
# Create the Gradio interface with modern styling
|
| 281 |
+
with gr.Blocks(
|
| 282 |
+
title="🚀 AI Object Removal Chat",
|
| 283 |
+
theme=gr.themes.Base(
|
| 284 |
+
primary_hue="emerald",
|
| 285 |
+
secondary_hue="blue",
|
| 286 |
+
neutral_hue="slate",
|
| 287 |
+
font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui", "sans-serif"]
|
| 288 |
+
),
|
| 289 |
+
css=custom_css,
|
| 290 |
+
fill_height=True
|
| 291 |
+
) as demo:
|
| 292 |
+
|
| 293 |
+
# Header Section
|
| 294 |
with gr.Row():
|
| 295 |
+
with gr.Column():
|
| 296 |
+
gr.HTML("""
|
| 297 |
+
<div class="header-text">
|
| 298 |
+
<h1>🚀 AI Object Removal Chat</h1>
|
| 299 |
+
<p>Upload an image and tell me what object you want to remove with professional results!</p>
|
| 300 |
+
</div>
|
| 301 |
+
""")
|
| 302 |
+
|
| 303 |
+
# Main Content Layout
|
| 304 |
+
with gr.Row(equal_height=True):
|
| 305 |
+
# Left Panel - Chat-like Interface
|
| 306 |
+
with gr.Column(scale=2, elem_classes=["chat-panel"]):
|
| 307 |
+
gr.Markdown("### 💬 Chat Interface")
|
| 308 |
+
|
| 309 |
+
# Image Upload
|
| 310 |
+
input_image = gr.Image(
|
| 311 |
+
label="📷 Upload Your Image",
|
| 312 |
+
type="pil",
|
| 313 |
+
height=250,
|
| 314 |
+
container=True
|
| 315 |
+
)
|
| 316 |
+
|
| 317 |
+
# Object Input
|
| 318 |
+
object_name = gr.Textbox(
|
| 319 |
+
label="🎯 What should I remove?",
|
| 320 |
+
placeholder="Type any object name (e.g., person, car, dog, bottle, tree, sign...)",
|
| 321 |
+
value="person",
|
| 322 |
+
container=True,
|
| 323 |
+
info="💡 I understand synonyms and variations!"
|
| 324 |
+
)
|
| 325 |
+
|
| 326 |
+
# Quick Examples
|
| 327 |
with gr.Row():
|
| 328 |
+
example_buttons = []
|
| 329 |
+
examples = ["person", "car", "dog", "cat", "bottle", "chair", "tree", "sign"]
|
| 330 |
+
for example in examples:
|
| 331 |
+
btn = gr.Button(example, size="sm", variant="secondary")
|
| 332 |
+
btn.click(lambda x=example: x, outputs=object_name)
|
| 333 |
+
example_buttons.append(btn)
|
| 334 |
+
|
| 335 |
+
# Advanced Settings
|
| 336 |
+
with gr.Accordion("⚙️ Advanced Settings", open=False):
|
| 337 |
+
guidance_scale = gr.Slider(
|
| 338 |
+
minimum=1.0,
|
| 339 |
+
maximum=10.0,
|
| 340 |
+
value=2.5,
|
| 341 |
+
step=0.1,
|
| 342 |
+
label="🎯 Guidance Scale",
|
| 343 |
+
info="Higher = more faithful to prompt, lower = more creative"
|
| 344 |
+
)
|
| 345 |
+
|
| 346 |
+
steps = gr.Slider(
|
| 347 |
+
minimum=10,
|
| 348 |
+
maximum=50,
|
| 349 |
+
value=28,
|
| 350 |
+
step=2,
|
| 351 |
+
label="🔄 Processing Steps",
|
| 352 |
+
info="More steps = higher quality but slower processing"
|
| 353 |
+
)
|
| 354 |
+
|
| 355 |
+
# Process Button
|
| 356 |
+
process_btn = gr.Button(
|
| 357 |
+
"🚀 Remove Object",
|
| 358 |
+
variant="primary",
|
| 359 |
+
size="lg",
|
| 360 |
+
elem_id="process-btn"
|
| 361 |
+
)
|
| 362 |
+
|
| 363 |
+
# Right Panel - Output
|
| 364 |
+
with gr.Column(scale=3, elem_classes=["output-panel"]):
|
| 365 |
+
gr.Markdown("### 🖼️ Result")
|
| 366 |
+
|
| 367 |
+
output_image = gr.Image(
|
| 368 |
+
label="Processed Image",
|
| 369 |
+
type="pil",
|
| 370 |
+
height=400,
|
| 371 |
+
container=True,
|
| 372 |
+
interactive=False
|
| 373 |
+
)
|
| 374 |
+
|
| 375 |
+
status_text = gr.Textbox(
|
| 376 |
+
label="📊 Status & Information",
|
| 377 |
+
max_lines=4,
|
| 378 |
+
interactive=False,
|
| 379 |
+
container=True
|
| 380 |
+
)
|
| 381 |
|
| 382 |
+
|
| 383 |
+
# Event Handlers
|
| 384 |
process_btn.click(
|
| 385 |
+
fn=remove_objects,
|
| 386 |
+
inputs=[input_image, object_name, guidance_scale, steps],
|
| 387 |
+
outputs=[output_image, status_text]
|
| 388 |
)
|
| 389 |
+
|
| 390 |
+
# Auto-process on Enter key
|
| 391 |
object_name.submit(
|
| 392 |
+
fn=remove_objects,
|
| 393 |
+
inputs=[input_image, object_name, guidance_scale, steps],
|
| 394 |
+
outputs=[output_image, status_text]
|
| 395 |
)
|
| 396 |
|
| 397 |
if __name__ == "__main__":
|