Spaces:
Running
Running
Bismay
commited on
Commit
·
9c5e178
1
Parent(s):
475e066
Improve output layout
Browse files- README.md +88 -14
- app.py +99 -66
- example.jpg +0 -0
README.md
CHANGED
@@ -9,30 +9,104 @@ app_file: app.py
|
|
9 |
pinned: false
|
10 |
---
|
11 |
|
|
|
|
|
12 |
# ClothQuill - AI Clothing Inpainting
|
13 |
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
## Examples
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
-
|
|
|
|
|
|
|
|
|
28 |
|
29 |
## Technical Details
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
-
|
34 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
## License
|
37 |
|
38 |
-
This project is licensed under the MIT License.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
+
<div align="center">
|
13 |
+
|
14 |
# ClothQuill - AI Clothing Inpainting
|
15 |
|
16 |
+
[](https://huggingface.co/spaces/bismay/ClothQuill)
|
17 |
+
[](https://opensource.org/licenses/MIT)
|
18 |
+
[](https://www.python.org/downloads/release/python-380/)
|
19 |
+
|
20 |
+
🎨 An AI-powered tool for seamlessly editing and modifying clothing in images using state-of-the-art deep learning models.
|
21 |
+
|
22 |
+
[Demo](#demo) • [Features](#features) • [Installation](#installation) • [Usage](#usage) • [Examples](#examples) • [Technical Details](#technical-details)
|
23 |
+
|
24 |
+
</div>
|
25 |
+
|
26 |
+
## Demo
|
27 |
+
|
28 |
+
ClothQuill is available as a Hugging Face Space! Try it out here: [ClothQuill Demo](https://huggingface.co/spaces/bismay/ClothQuill)
|
29 |
+
|
30 |
+
## Features
|
31 |
+
|
32 |
+
- 🎯 **Precise Clothing Detection**: Automatically identifies and segments different clothing items
|
33 |
+
- 🎨 **Interactive Selection**: Choose specific clothing parts to modify
|
34 |
+
- 🔄 **Multiple Variations**: Generate multiple inpainting results for each prompt
|
35 |
+
- 🎛️ **Adjustable Controls**: Fine-tune mask dilation for better blending
|
36 |
+
- 🖼️ **High-Quality Output**: Maintains image quality with advanced upscaling
|
37 |
+
- 🚀 **Real-time Preview**: See segmentation masks and selected regions in real-time
|
38 |
+
|
39 |
+
## Installation
|
40 |
+
|
41 |
+
```bash
|
42 |
+
# Clone the repository
|
43 |
+
git clone https://huggingface.co/spaces/bismay/ClothQuill
|
44 |
+
cd ClothQuill
|
45 |
+
|
46 |
+
# Install dependencies
|
47 |
+
pip install -r requirements.txt
|
48 |
|
49 |
+
# Download required models (will be downloaded automatically on first run)
|
50 |
+
python download_models.py
|
51 |
+
```
|
52 |
|
53 |
+
## Usage
|
54 |
+
|
55 |
+
1. **Start the Application**
|
56 |
+
```bash
|
57 |
+
python app.py
|
58 |
+
```
|
59 |
+
|
60 |
+
2. **Using the Interface**
|
61 |
+
- Upload an image containing a person
|
62 |
+
- The app will automatically detect clothing regions
|
63 |
+
- Select which parts of the clothing you want to modify
|
64 |
+
- Adjust the mask dilation if needed
|
65 |
+
- Enter a prompt describing the desired clothing
|
66 |
+
- Click "Generate" to create multiple variations
|
67 |
+
|
68 |
+
3. **Advanced Options**
|
69 |
+
- Use the dilation slider to control the modification area
|
70 |
+
- Select multiple clothing parts for simultaneous editing
|
71 |
+
- Preview the segmentation mask before generating
|
72 |
|
73 |
## Examples
|
74 |
|
75 |
+
Here are some example prompts and their use cases:
|
76 |
+
|
77 |
+
- 🧥 **Outerwear**: "A stylish black leather jacket with silver zippers"
|
78 |
+
- 👔 **Formal**: "A navy blue pinstripe suit with a white dress shirt"
|
79 |
+
- 👕 **Casual**: "A comfortable gray hoodie with white drawstrings"
|
80 |
+
- 👗 **Dresses**: "A flowing red summer dress with floral patterns"
|
81 |
+
- 👖 **Pants**: "Dark blue distressed jeans with a vintage wash"
|
82 |
|
83 |
## Technical Details
|
84 |
|
85 |
+
ClothQuill combines multiple state-of-the-art models:
|
86 |
+
|
87 |
+
- **Segmentation**: [SegFormer](https://huggingface.co/mattmdjaga/segformer_b2_clothes) for precise clothing detection
|
88 |
+
- **Inpainting**: [Stable Diffusion 2.0](https://huggingface.co/stabilityai/stable-diffusion-2-inpainting) for high-quality image generation
|
89 |
+
- **Upscaling**: [RealESRGAN](https://github.com/xinntao/Real-ESRGAN) for maintaining image quality
|
90 |
+
|
91 |
+
### Model Architecture
|
92 |
+
|
93 |
+
```
|
94 |
+
Input Image → SegFormer (Segmentation) → User Selection →
|
95 |
+
Mask Generation → Stable Diffusion (Inpainting) →
|
96 |
+
RealESRGAN (Upscaling) → Final Output
|
97 |
+
```
|
98 |
+
|
99 |
+
## Contributing
|
100 |
+
|
101 |
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
102 |
|
103 |
## License
|
104 |
|
105 |
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
106 |
+
|
107 |
+
## Acknowledgments
|
108 |
+
|
109 |
+
- Thanks to the Hugging Face team for hosting the demo
|
110 |
+
- Stable Diffusion by Stability AI
|
111 |
+
- SegFormer implementation by mattmdjaga
|
112 |
+
- RealESRGAN by xinntao
|
app.py
CHANGED
@@ -350,76 +350,109 @@ def update_selected_parts(image, selected_parts, dilation_iterations):
|
|
350 |
# Initialize the model
|
351 |
init()
|
352 |
|
353 |
-
|
354 |
-
with gr.Blocks(title="ClothQuill - AI Clothing Inpainting") as demo:
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
with gr.Row():
|
359 |
-
with gr.Column():
|
360 |
-
input_image = gr.Image(
|
361 |
-
type="pil",
|
362 |
-
label="Upload Image",
|
363 |
-
scale=1, # This ensures the image maintains its aspect ratio
|
364 |
-
height=None # Allow dynamic height based on content
|
365 |
-
)
|
366 |
-
dilation_slider = gr.Slider(
|
367 |
-
minimum=0,
|
368 |
-
maximum=5,
|
369 |
-
value=2,
|
370 |
-
step=1,
|
371 |
-
label="Mask Dilation",
|
372 |
-
info="Adjust the mask dilation to control the area of modification"
|
373 |
-
)
|
374 |
-
selected_parts = gr.CheckboxGroup(
|
375 |
-
choices=[],
|
376 |
-
label="Select parts to modify",
|
377 |
-
value=[]
|
378 |
-
)
|
379 |
-
prompt = gr.Textbox(
|
380 |
-
label="Describe the clothing you want to generate",
|
381 |
-
placeholder="e.g., A stylish black leather jacket"
|
382 |
-
)
|
383 |
-
generate_btn = gr.Button("Generate")
|
384 |
|
385 |
-
with gr.
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
407 |
|
408 |
-
|
409 |
-
generate_btn.click(
|
410 |
-
fn=process_image,
|
411 |
-
inputs=[prompt, input_image, selected_parts, dilation_slider],
|
412 |
-
outputs=gallery
|
413 |
-
)
|
414 |
-
|
415 |
-
# Add event handler for part selection changes
|
416 |
-
selected_parts.change(
|
417 |
-
fn=update_selected_parts,
|
418 |
-
inputs=[input_image, selected_parts, dilation_slider],
|
419 |
-
outputs=input_image
|
420 |
-
)
|
421 |
|
422 |
if __name__ == "__main__":
|
|
|
423 |
demo.launch(share=True)
|
424 |
|
425 |
|
|
|
350 |
# Initialize the model
|
351 |
init()
|
352 |
|
353 |
+
def create_interface():
|
354 |
+
with gr.Blocks(title="ClothQuill - AI Clothing Inpainting", theme=gr.themes.Soft()) as demo:
|
355 |
+
gr.Markdown("# ClothQuill - AI Clothing Inpainting")
|
356 |
+
gr.Markdown("An AI-powered tool for seamlessly editing and modifying clothing in images using state-of-the-art deep learning models.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
357 |
|
358 |
+
with gr.Row():
|
359 |
+
with gr.Column(scale=1):
|
360 |
+
# Input Section
|
361 |
+
with gr.Group():
|
362 |
+
gr.Markdown("### Input Image")
|
363 |
+
with gr.Row():
|
364 |
+
input_image = gr.Image(type="pil", label="Upload Image")
|
365 |
+
example_btn = gr.Button("Load Example Image", variant="secondary")
|
366 |
+
|
367 |
+
# Clothing Selection
|
368 |
+
gr.Markdown("### Select Clothing Parts")
|
369 |
+
clothing_parts = gr.CheckboxGroup(
|
370 |
+
choices=[
|
371 |
+
"upper-clothes", "dress", "coat", "pants", "skirt",
|
372 |
+
"hat", "glove", "sunglasses", "scarf"
|
373 |
+
],
|
374 |
+
label="Select parts to modify",
|
375 |
+
value=["upper-clothes"]
|
376 |
+
)
|
377 |
+
|
378 |
+
# Advanced Options
|
379 |
+
with gr.Accordion("Advanced Options", open=False):
|
380 |
+
dilation_slider = gr.Slider(
|
381 |
+
minimum=0,
|
382 |
+
maximum=5,
|
383 |
+
value=2,
|
384 |
+
step=1,
|
385 |
+
label="Mask Dilation (adjust for better blending)"
|
386 |
+
)
|
387 |
+
|
388 |
+
# Prompt Section
|
389 |
+
gr.Markdown("### Describe the New Clothing")
|
390 |
+
prompt = gr.Textbox(
|
391 |
+
label="Enter your prompt",
|
392 |
+
placeholder="e.g., A stylish black leather jacket with silver zippers",
|
393 |
+
lines=2
|
394 |
+
)
|
395 |
+
|
396 |
+
# Generate Button
|
397 |
+
generate_btn = gr.Button("Generate Variations", variant="primary")
|
398 |
+
|
399 |
+
with gr.Column(scale=1):
|
400 |
+
# Output Section
|
401 |
+
gr.Markdown("### Results")
|
402 |
+
with gr.Group():
|
403 |
+
output_gallery = gr.Gallery(
|
404 |
+
label="Generated Variations",
|
405 |
+
show_label=True,
|
406 |
+
elem_id="gallery",
|
407 |
+
columns=3,
|
408 |
+
height="auto"
|
409 |
+
)
|
410 |
+
output_gallery.style(grid=3, height="auto")
|
411 |
+
|
412 |
+
# Example Image Loading
|
413 |
+
def load_example():
|
414 |
+
example_path = "example.jpg"
|
415 |
+
if os.path.exists(example_path):
|
416 |
+
return Image.open(example_path)
|
417 |
+
return None
|
418 |
+
|
419 |
+
example_btn.click(
|
420 |
+
fn=load_example,
|
421 |
+
outputs=input_image
|
422 |
+
)
|
423 |
+
|
424 |
+
# Main Processing
|
425 |
+
generate_btn.click(
|
426 |
+
fn=process_segmentation,
|
427 |
+
inputs=[input_image, clothing_parts, prompt, dilation_slider],
|
428 |
+
outputs=output_gallery
|
429 |
+
)
|
430 |
+
|
431 |
+
# Input Image Change Handler
|
432 |
+
input_image.change(
|
433 |
+
fn=process_segmentation,
|
434 |
+
inputs=[input_image, clothing_parts, prompt, dilation_slider],
|
435 |
+
outputs=output_gallery
|
436 |
+
)
|
437 |
+
|
438 |
+
# Clothing Parts Change Handler
|
439 |
+
clothing_parts.change(
|
440 |
+
fn=process_segmentation,
|
441 |
+
inputs=[input_image, clothing_parts, prompt, dilation_slider],
|
442 |
+
outputs=output_gallery
|
443 |
+
)
|
444 |
+
|
445 |
+
# Dilation Slider Change Handler
|
446 |
+
dilation_slider.change(
|
447 |
+
fn=process_segmentation,
|
448 |
+
inputs=[input_image, clothing_parts, prompt, dilation_slider],
|
449 |
+
outputs=output_gallery
|
450 |
+
)
|
451 |
|
452 |
+
return demo
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
453 |
|
454 |
if __name__ == "__main__":
|
455 |
+
demo = create_interface()
|
456 |
demo.launch(share=True)
|
457 |
|
458 |
|
example.jpg
ADDED
![]() |