mlworks90 commited on
Commit
e6c2e33
Β·
verified Β·
1 Parent(s): bb78aca

Upload 2 files

Browse files
Files changed (2) hide show
  1. basic_usage.py +222 -0
  2. quickstart.md +222 -0
basic_usage.py ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Fashion Inpainting System - Example Implementation
3
+ Correct usage of the fashion_safety_checker API
4
+ """
5
+
6
+ from fashion_safety_checker import create_fashion_safety_pipeline
7
+
8
+ def main():
9
+ """
10
+ Example usage of the Fashion Inpainting System
11
+ """
12
+ # Initialize the fashion safety pipeline
13
+ pipeline = create_fashion_safety_pipeline()
14
+
15
+ # Example 1: Basic transformation
16
+ print("🎨 Basic Fashion Transformation")
17
+ result = pipeline.safe_fashion_transformation(
18
+ source_image_path="examples/person_in_casual_wear.jpg",
19
+ checkpoint_path="checkpoints/realistic_vision_v2.safetensors",
20
+ outfit_prompt="elegant red evening dress",
21
+ output_path="outputs/red_evening_dress_result.jpg",
22
+ face_scale=0.90 # Manual face to body ratio adjustment
23
+ )
24
+
25
+ if result['success']:
26
+ print("βœ… Fashion transformation completed successfully")
27
+ print(f"Output saved to: {result.get('output_path', 'outputs/red_evening_dress_result.jpg')}")
28
+ else:
29
+ print("❌ Transformation blocked by safety system")
30
+ print(f"Blocking reason: {result['blocking_reason']}")
31
+ print(f"User message: {result['user_message']}")
32
+
33
+ print("-" * 50)
34
+
35
+ # Example 2: Different outfit style
36
+ print("🎨 Business Outfit Transformation")
37
+ result = pipeline.safe_fashion_transformation(
38
+ source_image_path="examples/person_in_casual_wear.jpg",
39
+ checkpoint_path="checkpoints/fashion_professional_v1.safetensors",
40
+ outfit_prompt="professional business suit, navy blue, elegant",
41
+ output_path="outputs/business_suit_result.jpg",
42
+ face_scale=0.85
43
+ )
44
+
45
+ if result['success']:
46
+ print("βœ… Business transformation completed")
47
+ else:
48
+ print("❌ Business transformation blocked")
49
+ print(f"Reason: {result['blocking_reason']}")
50
+ print(f"Message: {result['user_message']}")
51
+
52
+ print("-" * 50)
53
+
54
+ # Example 3: Swimwear (requires appropriate safety level)
55
+ print("🎨 Swimwear Transformation (Professional Use)")
56
+ result = pipeline.safe_fashion_transformation(
57
+ source_image_path="examples/person_in_casual_wear.jpg",
58
+ checkpoint_path="checkpoints/fashion_permissive_v1.safetensors",
59
+ outfit_prompt="elegant one-piece swimsuit, professional fashion photography",
60
+ output_path="outputs/swimwear_result.jpg",
61
+ face_scale=0.92
62
+ )
63
+
64
+ if result['success']:
65
+ print("βœ… Swimwear transformation completed")
66
+ else:
67
+ print("❌ Swimwear transformation blocked")
68
+ print(f"Reason: {result['blocking_reason']}")
69
+ print(f"Message: {result['user_message']}")
70
+
71
+ print("-" * 50)
72
+
73
+ # Example 4: Error handling for missing files
74
+ print("🎨 Error Handling Example")
75
+ result = pipeline.safe_fashion_transformation(
76
+ source_image_path="examples/nonexistent_image.jpg", # This will fail
77
+ checkpoint_path="checkpoints/some_checkpoint.safetensors",
78
+ outfit_prompt="casual summer dress",
79
+ output_path="outputs/error_test.jpg",
80
+ face_scale=0.90
81
+ )
82
+
83
+ if result['success']:
84
+ print("βœ… This shouldn't happen")
85
+ else:
86
+ print("❌ Expected error occurred")
87
+ print(f"Reason: {result['blocking_reason']}")
88
+ print(f"Message: {result['user_message']}")
89
+
90
+ def advanced_usage_examples():
91
+ """
92
+ Advanced usage examples with different parameters
93
+ """
94
+ pipeline = create_fashion_safety_pipeline()
95
+
96
+ # Example with different face scales
97
+ face_scales = [0.80, 0.85, 0.90, 0.95]
98
+
99
+ for i, scale in enumerate(face_scales):
100
+ print(f"🎨 Testing face_scale={scale}")
101
+
102
+ result = pipeline.safe_fashion_transformation(
103
+ source_image_path="examples/test_subject.jpg",
104
+ checkpoint_path="checkpoints/fashion_moderate.safetensors",
105
+ outfit_prompt="classic white shirt and dark jeans",
106
+ output_path=f"outputs/face_scale_test_{scale}.jpg",
107
+ face_scale=scale
108
+ )
109
+
110
+ if result['success']:
111
+ print(f"βœ… face_scale={scale} completed successfully")
112
+ else:
113
+ print(f"❌ face_scale={scale} failed: {result['blocking_reason']}")
114
+
115
+ def batch_processing_example():
116
+ """
117
+ Example of processing multiple transformations
118
+ """
119
+ pipeline = create_fashion_safety_pipeline()
120
+
121
+ # Batch transformation scenarios
122
+ transformations = [
123
+ {
124
+ "source": "examples/person1.jpg",
125
+ "checkpoint": "checkpoints/casual_wear.safetensors",
126
+ "prompt": "comfortable jeans and cozy sweater",
127
+ "output": "outputs/person1_casual.jpg",
128
+ "face_scale": 0.90
129
+ },
130
+ {
131
+ "source": "examples/person2.jpg",
132
+ "checkpoint": "checkpoints/formal_wear.safetensors",
133
+ "prompt": "elegant black evening gown",
134
+ "output": "outputs/person2_formal.jpg",
135
+ "face_scale": 0.88
136
+ },
137
+ {
138
+ "source": "examples/person3.jpg",
139
+ "checkpoint": "checkpoints/business_wear.safetensors",
140
+ "prompt": "professional gray suit with blue tie",
141
+ "output": "outputs/person3_business.jpg",
142
+ "face_scale": 0.85
143
+ }
144
+ ]
145
+
146
+ successful_transformations = 0
147
+ failed_transformations = 0
148
+
149
+ for i, transform in enumerate(transformations):
150
+ print(f"🎨 Processing transformation {i+1}/{len(transformations)}")
151
+
152
+ result = pipeline.safe_fashion_transformation(
153
+ source_image_path=transform["source"],
154
+ checkpoint_path=transform["checkpoint"],
155
+ outfit_prompt=transform["prompt"],
156
+ output_path=transform["output"],
157
+ face_scale=transform["face_scale"]
158
+ )
159
+
160
+ if result['success']:
161
+ successful_transformations += 1
162
+ print(f"βœ… Transformation {i+1} completed")
163
+ else:
164
+ failed_transformations += 1
165
+ print(f"❌ Transformation {i+1} failed: {result['blocking_reason']}")
166
+
167
+ print(f"\nπŸ“Š Batch Processing Results:")
168
+ print(f"βœ… Successful: {successful_transformations}")
169
+ print(f"❌ Failed: {failed_transformations}")
170
+ print(f"πŸ“ˆ Success Rate: {successful_transformations/len(transformations)*100:.1f}%")
171
+
172
+ def safety_level_examples():
173
+ """
174
+ Examples demonstrating different safety behaviors
175
+ """
176
+ pipeline = create_fashion_safety_pipeline()
177
+
178
+ # Test different prompts with safety implications
179
+ test_cases = [
180
+ ("conservative business outfit", "Should pass all safety levels"),
181
+ ("summer beach dress", "Should pass moderate and permissive"),
182
+ ("elegant swimwear", "May require permissive safety level"),
183
+ ("inappropriate content", "Should be blocked by safety system")
184
+ ]
185
+
186
+ for prompt, expectation in test_cases:
187
+ print(f"\nπŸ§ͺ Testing prompt: '{prompt}'")
188
+ print(f" Expected: {expectation}")
189
+
190
+ result = pipeline.safe_fashion_transformation(
191
+ source_image_path="examples/test_image.jpg",
192
+ checkpoint_path="checkpoints/general_fashion.safetensors",
193
+ outfit_prompt=prompt,
194
+ output_path=f"outputs/safety_test_{prompt.replace(' ', '_')}.jpg",
195
+ face_scale=0.90
196
+ )
197
+
198
+ if result['success']:
199
+ print(f" βœ… Result: Transformation completed")
200
+ else:
201
+ print(f" ❌ Result: Blocked - {result['blocking_reason']}")
202
+ print(f" πŸ’¬ Message: {result['user_message']}")
203
+
204
+ if __name__ == "__main__":
205
+ print("🎨 Fashion Inpainting System - Example Usage\n")
206
+
207
+ # Run basic examples
208
+ main()
209
+
210
+ print("\n" + "="*60)
211
+ print("Advanced Examples")
212
+ print("="*60)
213
+
214
+ # Uncomment to run advanced examples
215
+ # advanced_usage_examples()
216
+ # batch_processing_example()
217
+ # safety_level_examples()
218
+
219
+ print("\n✨ Examples completed!")
220
+ print("πŸ“– For more information, see the documentation at:")
221
+ print(" GitHub: https://github.com/your-org/fashion-inpainting-system")
222
+ print(" Hugging Face: https://huggingface.co/your-org/fashion-inpainting-system")
quickstart.md ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Fashion Inpainting System - Example Implementation
3
+ Correct usage of the fashion_safety_checker API
4
+ """
5
+
6
+ from fashion_safety_checker import create_fashion_safety_pipeline
7
+
8
+ def main():
9
+ """
10
+ Example usage of the Fashion Inpainting System
11
+ """
12
+ # Initialize the fashion safety pipeline
13
+ pipeline = create_fashion_safety_pipeline()
14
+
15
+ # Example 1: Basic transformation
16
+ print("🎨 Basic Fashion Transformation")
17
+ result = pipeline.safe_fashion_transformation(
18
+ source_image_path="examples/person_in_casual_wear.jpg",
19
+ checkpoint_path="checkpoints/realistic_vision_v2.safetensors",
20
+ outfit_prompt="elegant red evening dress",
21
+ output_path="outputs/red_evening_dress_result.jpg",
22
+ face_scale=0.90 # Manual face to body ratio adjustment
23
+ )
24
+
25
+ if result['success']:
26
+ print("βœ… Fashion transformation completed successfully")
27
+ print(f"Output saved to: {result.get('output_path', 'outputs/red_evening_dress_result.jpg')}")
28
+ else:
29
+ print("❌ Transformation blocked by safety system")
30
+ print(f"Blocking reason: {result['blocking_reason']}")
31
+ print(f"User message: {result['user_message']}")
32
+
33
+ print("-" * 50)
34
+
35
+ # Example 2: Different outfit style
36
+ print("🎨 Business Outfit Transformation")
37
+ result = pipeline.safe_fashion_transformation(
38
+ source_image_path="examples/person_in_casual_wear.jpg",
39
+ checkpoint_path="checkpoints/fashion_professional_v1.safetensors",
40
+ outfit_prompt="professional business suit, navy blue, elegant",
41
+ output_path="outputs/business_suit_result.jpg",
42
+ face_scale=0.85
43
+ )
44
+
45
+ if result['success']:
46
+ print("βœ… Business transformation completed")
47
+ else:
48
+ print("❌ Business transformation blocked")
49
+ print(f"Reason: {result['blocking_reason']}")
50
+ print(f"Message: {result['user_message']}")
51
+
52
+ print("-" * 50)
53
+
54
+ # Example 3: Swimwear (requires appropriate safety level)
55
+ print("🎨 Swimwear Transformation (Professional Use)")
56
+ result = pipeline.safe_fashion_transformation(
57
+ source_image_path="examples/person_in_casual_wear.jpg",
58
+ checkpoint_path="checkpoints/fashion_permissive_v1.safetensors",
59
+ outfit_prompt="elegant one-piece swimsuit, professional fashion photography",
60
+ output_path="outputs/swimwear_result.jpg",
61
+ face_scale=0.92
62
+ )
63
+
64
+ if result['success']:
65
+ print("βœ… Swimwear transformation completed")
66
+ else:
67
+ print("❌ Swimwear transformation blocked")
68
+ print(f"Reason: {result['blocking_reason']}")
69
+ print(f"Message: {result['user_message']}")
70
+
71
+ print("-" * 50)
72
+
73
+ # Example 4: Error handling for missing files
74
+ print("🎨 Error Handling Example")
75
+ result = pipeline.safe_fashion_transformation(
76
+ source_image_path="examples/nonexistent_image.jpg", # This will fail
77
+ checkpoint_path="checkpoints/some_checkpoint.safetensors",
78
+ outfit_prompt="casual summer dress",
79
+ output_path="outputs/error_test.jpg",
80
+ face_scale=0.90
81
+ )
82
+
83
+ if result['success']:
84
+ print("βœ… This shouldn't happen")
85
+ else:
86
+ print("❌ Expected error occurred")
87
+ print(f"Reason: {result['blocking_reason']}")
88
+ print(f"Message: {result['user_message']}")
89
+
90
+ def advanced_usage_examples():
91
+ """
92
+ Advanced usage examples with different parameters
93
+ """
94
+ pipeline = create_fashion_safety_pipeline()
95
+
96
+ # Example with different face scales
97
+ face_scales = [0.80, 0.85, 0.90, 0.95]
98
+
99
+ for i, scale in enumerate(face_scales):
100
+ print(f"🎨 Testing face_scale={scale}")
101
+
102
+ result = pipeline.safe_fashion_transformation(
103
+ source_image_path="examples/test_subject.jpg",
104
+ checkpoint_path="checkpoints/fashion_moderate.safetensors",
105
+ outfit_prompt="classic white shirt and dark jeans",
106
+ output_path=f"outputs/face_scale_test_{scale}.jpg",
107
+ face_scale=scale
108
+ )
109
+
110
+ if result['success']:
111
+ print(f"βœ… face_scale={scale} completed successfully")
112
+ else:
113
+ print(f"❌ face_scale={scale} failed: {result['blocking_reason']}")
114
+
115
+ def batch_processing_example():
116
+ """
117
+ Example of processing multiple transformations
118
+ """
119
+ pipeline = create_fashion_safety_pipeline()
120
+
121
+ # Batch transformation scenarios
122
+ transformations = [
123
+ {
124
+ "source": "examples/person1.jpg",
125
+ "checkpoint": "checkpoints/casual_wear.safetensors",
126
+ "prompt": "comfortable jeans and cozy sweater",
127
+ "output": "outputs/person1_casual.jpg",
128
+ "face_scale": 0.90
129
+ },
130
+ {
131
+ "source": "examples/person2.jpg",
132
+ "checkpoint": "checkpoints/formal_wear.safetensors",
133
+ "prompt": "elegant black evening gown",
134
+ "output": "outputs/person2_formal.jpg",
135
+ "face_scale": 0.88
136
+ },
137
+ {
138
+ "source": "examples/person3.jpg",
139
+ "checkpoint": "checkpoints/business_wear.safetensors",
140
+ "prompt": "professional gray suit with blue tie",
141
+ "output": "outputs/person3_business.jpg",
142
+ "face_scale": 0.85
143
+ }
144
+ ]
145
+
146
+ successful_transformations = 0
147
+ failed_transformations = 0
148
+
149
+ for i, transform in enumerate(transformations):
150
+ print(f"🎨 Processing transformation {i+1}/{len(transformations)}")
151
+
152
+ result = pipeline.safe_fashion_transformation(
153
+ source_image_path=transform["source"],
154
+ checkpoint_path=transform["checkpoint"],
155
+ outfit_prompt=transform["prompt"],
156
+ output_path=transform["output"],
157
+ face_scale=transform["face_scale"]
158
+ )
159
+
160
+ if result['success']:
161
+ successful_transformations += 1
162
+ print(f"βœ… Transformation {i+1} completed")
163
+ else:
164
+ failed_transformations += 1
165
+ print(f"❌ Transformation {i+1} failed: {result['blocking_reason']}")
166
+
167
+ print(f"\nπŸ“Š Batch Processing Results:")
168
+ print(f"βœ… Successful: {successful_transformations}")
169
+ print(f"❌ Failed: {failed_transformations}")
170
+ print(f"πŸ“ˆ Success Rate: {successful_transformations/len(transformations)*100:.1f}%")
171
+
172
+ def safety_level_examples():
173
+ """
174
+ Examples demonstrating different safety behaviors
175
+ """
176
+ pipeline = create_fashion_safety_pipeline()
177
+
178
+ # Test different prompts with safety implications
179
+ test_cases = [
180
+ ("conservative business outfit", "Should pass all safety levels"),
181
+ ("summer beach dress", "Should pass moderate and permissive"),
182
+ ("elegant swimwear", "May require permissive safety level"),
183
+ ("inappropriate content", "Should be blocked by safety system")
184
+ ]
185
+
186
+ for prompt, expectation in test_cases:
187
+ print(f"\nπŸ§ͺ Testing prompt: '{prompt}'")
188
+ print(f" Expected: {expectation}")
189
+
190
+ result = pipeline.safe_fashion_transformation(
191
+ source_image_path="examples/test_image.jpg",
192
+ checkpoint_path="checkpoints/general_fashion.safetensors",
193
+ outfit_prompt=prompt,
194
+ output_path=f"outputs/safety_test_{prompt.replace(' ', '_')}.jpg",
195
+ face_scale=0.90
196
+ )
197
+
198
+ if result['success']:
199
+ print(f" βœ… Result: Transformation completed")
200
+ else:
201
+ print(f" ❌ Result: Blocked - {result['blocking_reason']}")
202
+ print(f" πŸ’¬ Message: {result['user_message']}")
203
+
204
+ if __name__ == "__main__":
205
+ print("🎨 Fashion Inpainting System - Example Usage\n")
206
+
207
+ # Run basic examples
208
+ main()
209
+
210
+ print("\n" + "="*60)
211
+ print("Advanced Examples")
212
+ print("="*60)
213
+
214
+ # Uncomment to run advanced examples
215
+ # advanced_usage_examples()
216
+ # batch_processing_example()
217
+ # safety_level_examples()
218
+
219
+ print("\n✨ Examples completed!")
220
+ print("πŸ“– For more information, see the documentation at:")
221
+ print(" GitHub: https://github.com/your-org/fashion-inpainting-system")
222
+ print(" Hugging Face: https://huggingface.co/your-org/fashion-inpainting-system")