File size: 8,464 Bytes
e6c2e33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
"""
Fashion Inpainting System - Example Implementation
Correct usage of the fashion_safety_checker API
"""

from fashion_safety_checker import create_fashion_safety_pipeline



def main():

    """

    Example usage of the Fashion Inpainting System

    """

    # Initialize the fashion safety pipeline

    pipeline = create_fashion_safety_pipeline()
    

    # Example 1: Basic transformation

    print("🎨 Basic Fashion Transformation")

    result = pipeline.safe_fashion_transformation(

        source_image_path="examples/person_in_casual_wear.jpg",

        checkpoint_path="checkpoints/realistic_vision_v2.safetensors",

        outfit_prompt="elegant red evening dress",

        output_path="outputs/red_evening_dress_result.jpg",

        face_scale=0.90  # Manual face to body ratio adjustment

    )

    

    if result['success']:

        print("βœ… Fashion transformation completed successfully")

        print(f"Output saved to: {result.get('output_path', 'outputs/red_evening_dress_result.jpg')}")

    else:

        print("❌ Transformation blocked by safety system")

        print(f"Blocking reason: {result['blocking_reason']}")

        print(f"User message: {result['user_message']}")

    

    print("-" * 50)

    

    # Example 2: Different outfit style

    print("🎨 Business Outfit Transformation")

    result = pipeline.safe_fashion_transformation(

        source_image_path="examples/person_in_casual_wear.jpg",

        checkpoint_path="checkpoints/fashion_professional_v1.safetensors",

        outfit_prompt="professional business suit, navy blue, elegant",

        output_path="outputs/business_suit_result.jpg",

        face_scale=0.85

    )

    

    if result['success']:

        print("βœ… Business transformation completed")

    else:

        print("❌ Business transformation blocked")

        print(f"Reason: {result['blocking_reason']}")

        print(f"Message: {result['user_message']}")

    

    print("-" * 50)

    

    # Example 3: Swimwear (requires appropriate safety level)

    print("🎨 Swimwear Transformation (Professional Use)")

    result = pipeline.safe_fashion_transformation(

        source_image_path="examples/person_in_casual_wear.jpg",

        checkpoint_path="checkpoints/fashion_permissive_v1.safetensors",

        outfit_prompt="elegant one-piece swimsuit, professional fashion photography",

        output_path="outputs/swimwear_result.jpg",

        face_scale=0.92

    )

    

    if result['success']:

        print("βœ… Swimwear transformation completed")

    else:

        print("❌ Swimwear transformation blocked")

        print(f"Reason: {result['blocking_reason']}")

        print(f"Message: {result['user_message']}")

    

    print("-" * 50)

    

    # Example 4: Error handling for missing files

    print("🎨 Error Handling Example")

    result = pipeline.safe_fashion_transformation(

        source_image_path="examples/nonexistent_image.jpg",  # This will fail

        checkpoint_path="checkpoints/some_checkpoint.safetensors",

        outfit_prompt="casual summer dress",

        output_path="outputs/error_test.jpg",

        face_scale=0.90

    )

    

    if result['success']:

        print("βœ… This shouldn't happen")

    else:

        print("❌ Expected error occurred")

        print(f"Reason: {result['blocking_reason']}")

        print(f"Message: {result['user_message']}")


def advanced_usage_examples():
    """

    Advanced usage examples with different parameters

    """

    pipeline = create_fashion_safety_pipeline()

    

    # Example with different face scales

    face_scales = [0.80, 0.85, 0.90, 0.95]

    

    for i, scale in enumerate(face_scales):

        print(f"🎨 Testing face_scale={scale}")

        

        result = pipeline.safe_fashion_transformation(

            source_image_path="examples/test_subject.jpg",

            checkpoint_path="checkpoints/fashion_moderate.safetensors", 

            outfit_prompt="classic white shirt and dark jeans",

            output_path=f"outputs/face_scale_test_{scale}.jpg",

            face_scale=scale

        )

        

        if result['success']:

            print(f"βœ… face_scale={scale} completed successfully")

        else:

            print(f"❌ face_scale={scale} failed: {result['blocking_reason']}")


def batch_processing_example():
    """

    Example of processing multiple transformations

    """

    pipeline = create_fashion_safety_pipeline()

    

    # Batch transformation scenarios

    transformations = [

        {

            "source": "examples/person1.jpg",

            "checkpoint": "checkpoints/casual_wear.safetensors",

            "prompt": "comfortable jeans and cozy sweater",

            "output": "outputs/person1_casual.jpg",

            "face_scale": 0.90

        },

        {

            "source": "examples/person2.jpg", 

            "checkpoint": "checkpoints/formal_wear.safetensors",

            "prompt": "elegant black evening gown",

            "output": "outputs/person2_formal.jpg",

            "face_scale": 0.88

        },

        {

            "source": "examples/person3.jpg",

            "checkpoint": "checkpoints/business_wear.safetensors", 

            "prompt": "professional gray suit with blue tie",

            "output": "outputs/person3_business.jpg",

            "face_scale": 0.85

        }

    ]

    

    successful_transformations = 0

    failed_transformations = 0

    

    for i, transform in enumerate(transformations):

        print(f"🎨 Processing transformation {i+1}/{len(transformations)}")

        

        result = pipeline.safe_fashion_transformation(

            source_image_path=transform["source"],

            checkpoint_path=transform["checkpoint"],

            outfit_prompt=transform["prompt"],

            output_path=transform["output"],

            face_scale=transform["face_scale"]

        )

        

        if result['success']:

            successful_transformations += 1

            print(f"βœ… Transformation {i+1} completed")

        else:

            failed_transformations += 1

            print(f"❌ Transformation {i+1} failed: {result['blocking_reason']}")

    

    print(f"\nπŸ“Š Batch Processing Results:")

    print(f"βœ… Successful: {successful_transformations}")

    print(f"❌ Failed: {failed_transformations}")

    print(f"πŸ“ˆ Success Rate: {successful_transformations/len(transformations)*100:.1f}%")


def safety_level_examples():
    """

    Examples demonstrating different safety behaviors

    """

    pipeline = create_fashion_safety_pipeline()

    

    # Test different prompts with safety implications

    test_cases = [

        ("conservative business outfit", "Should pass all safety levels"),

        ("summer beach dress", "Should pass moderate and permissive"),

        ("elegant swimwear", "May require permissive safety level"),

        ("inappropriate content", "Should be blocked by safety system")

    ]

    

    for prompt, expectation in test_cases:

        print(f"\nπŸ§ͺ Testing prompt: '{prompt}'")

        print(f"   Expected: {expectation}")

        

        result = pipeline.safe_fashion_transformation(

            source_image_path="examples/test_image.jpg",

            checkpoint_path="checkpoints/general_fashion.safetensors",

            outfit_prompt=prompt,

            output_path=f"outputs/safety_test_{prompt.replace(' ', '_')}.jpg",

            face_scale=0.90

        )

        

        if result['success']:

            print(f"   βœ… Result: Transformation completed")

        else:

            print(f"   ❌ Result: Blocked - {result['blocking_reason']}")

            print(f"   πŸ’¬ Message: {result['user_message']}")


if __name__ == "__main__":
    print("🎨 Fashion Inpainting System - Example Usage\n")

    

    # Run basic examples

    main()

    

    print("\n" + "="*60)

    print("Advanced Examples")

    print("="*60)

    

    # Uncomment to run advanced examples

    # advanced_usage_examples()

    # batch_processing_example() 

    # safety_level_examples()

    

    print("\n✨ Examples completed!")

    print("πŸ“– For more information, see the documentation at:")

    print("   GitHub: https://github.com/your-org/fashion-inpainting-system")

    print("   Hugging Face: https://huggingface.co/your-org/fashion-inpainting-system")