Niketjain2002 commited on
Commit
757d92c
·
verified ·
1 Parent(s): 8a55723

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +55 -7
  2. app.py +388 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,13 +1,61 @@
1
  ---
2
- title: AI Editing Proto
3
- emoji: 🌍
4
- colorFrom: green
5
- colorTo: red
6
  sdk: gradio
7
- sdk_version: 6.5.1
8
  app_file: app.py
9
  pinned: false
10
- short_description: Demo
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: AI Photo Edit
3
+ emoji: 🎨
4
+ colorFrom: blue
5
+ colorTo: purple
6
  sdk: gradio
7
+ sdk_version: 4.44.0
8
  app_file: app.py
9
  pinned: false
10
+ license: mit
11
  ---
12
 
13
+ # AI Photo Edit
14
+
15
+ Transform your photos with AI-powered styles, enhancements, and fixes.
16
+
17
+ ## Features
18
+
19
+ ### Restyle
20
+ - **Anime** - Transform into anime style with vibrant colors
21
+ - **Chibi Sticker** - Cute chibi style with big head and small body
22
+ - **Superhero** - Comic book style with dramatic lighting
23
+ - **Graffiti** - Urban street art style
24
+ - **Watercolour** - Soft watercolor painting effect
25
+ - **Comic** - Bold lines and halftone dots
26
+
27
+ ### Seasons
28
+ - **Summer** - Warm golden sunlight and vibrant colors
29
+ - **Winter** - Frost, cold blue tones
30
+ - **Monsoon** - Rainy mood with wet surfaces
31
+
32
+ ### Enhance
33
+ - **Auto Enhance** - Improve colors, contrast, and sharpness
34
+ - **HDR Effect** - Expand dynamic range
35
+ - **Sharpen** - Increase clarity
36
+ - **Reduce Noise** - Remove grain
37
+
38
+ ### Fix
39
+ - **Blur Background** - Portrait-style depth effect
40
+ - **Relight** - Adjust lighting and shadows
41
+ - **Fix Colors** - Correct white balance
42
+
43
+ ## Usage
44
+
45
+ 1. Upload an image
46
+ 2. Select a style, season, enhancement, or fix
47
+ 3. Adjust intensity with the slider
48
+ 4. Download your transformed image
49
+
50
+ ## Custom Prompts
51
+
52
+ You can also describe your own style in the custom prompt box. Try keywords like:
53
+ - "vintage sepia photograph"
54
+ - "black and white"
55
+ - "anime cartoon style"
56
+ - "winter snow scene"
57
+
58
+ ## Built With
59
+
60
+ - [Gradio](https://gradio.app/) - Web UI framework
61
+ - [Pillow](https://pillow.readthedocs.io/) - Image processing
app.py ADDED
@@ -0,0 +1,388 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ AI Photo Edit - Hugging Face Spaces App
3
+ A web-based AI photo editing tool with Restyle, Enhance, and Fix capabilities
4
+ """
5
+
6
+ import gradio as gr
7
+ import numpy as np
8
+ from PIL import Image, ImageEnhance, ImageFilter
9
+ from io import BytesIO
10
+ import base64
11
+
12
+ # Style configurations
13
+ RESTYLE_OPTIONS = {
14
+ "Anime": "Transform into anime style with vibrant colors and expressive features",
15
+ "Chibi Sticker": "Transform into cute chibi style with big head and small body",
16
+ "Superhero": "Transform into superhero comic book style with dramatic lighting",
17
+ "Graffiti": "Transform into urban graffiti street art style",
18
+ "Watercolour": "Transform into watercolor painting with soft edges",
19
+ "Comic": "Transform into comic book style with bold lines and halftone dots",
20
+ }
21
+
22
+ SEASON_OPTIONS = {
23
+ "Summer": "Bright summer with warm golden sunlight and vibrant colors",
24
+ "Winter": "Snowy winter with frost, cold blue tones",
25
+ "Monsoon": "Rainy monsoon with wet surfaces and moody lighting",
26
+ }
27
+
28
+ ENHANCE_OPTIONS = {
29
+ "Auto Enhance": "Improve colors, contrast, and sharpness",
30
+ "HDR Effect": "Expand dynamic range for vivid details",
31
+ "Sharpen": "Increase clarity and edge definition",
32
+ "Reduce Noise": "Remove grain while preserving details",
33
+ }
34
+
35
+ FIX_OPTIONS = {
36
+ "Blur Background": "Add portrait-style depth effect",
37
+ "Relight": "Adjust lighting and shadows",
38
+ "Fix Colors": "Correct white balance and color cast",
39
+ }
40
+
41
+
42
+ def apply_style(image, style_name, intensity=1.0):
43
+ """Apply visual style filters to image"""
44
+ if image is None:
45
+ return None
46
+
47
+ img = Image.fromarray(image)
48
+
49
+ # Convert to RGB if needed
50
+ if img.mode != 'RGB':
51
+ img = img.convert('RGB')
52
+
53
+ style_filters = {
54
+ "Anime": lambda i: apply_anime(i, intensity),
55
+ "Chibi Sticker": lambda i: apply_anime(i, intensity * 0.8),
56
+ "Superhero": lambda i: apply_dramatic(i, intensity),
57
+ "Graffiti": lambda i: apply_vibrant(i, intensity * 1.2),
58
+ "Watercolour": lambda i: apply_watercolor(i, intensity),
59
+ "Comic": lambda i: apply_comic(i, intensity),
60
+ "Summer": lambda i: apply_summer(i, intensity),
61
+ "Winter": lambda i: apply_winter(i, intensity),
62
+ "Monsoon": lambda i: apply_monsoon(i, intensity),
63
+ "Auto Enhance": lambda i: apply_enhance(i, intensity),
64
+ "HDR Effect": lambda i: apply_hdr(i, intensity),
65
+ "Sharpen": lambda i: apply_sharpen(i, intensity),
66
+ "Reduce Noise": lambda i: apply_denoise(i, intensity),
67
+ "Blur Background": lambda i: apply_blur_bg(i, intensity),
68
+ "Relight": lambda i: apply_relight(i, intensity),
69
+ "Fix Colors": lambda i: apply_fix_colors(i, intensity),
70
+ }
71
+
72
+ if style_name in style_filters:
73
+ img = style_filters[style_name](img)
74
+
75
+ return np.array(img)
76
+
77
+
78
+ def apply_anime(img, intensity):
79
+ """Anime style: high saturation, contrast"""
80
+ enhancer = ImageEnhance.Color(img)
81
+ img = enhancer.enhance(1.0 + 0.5 * intensity)
82
+ enhancer = ImageEnhance.Contrast(img)
83
+ img = enhancer.enhance(1.0 + 0.25 * intensity)
84
+ enhancer = ImageEnhance.Brightness(img)
85
+ img = enhancer.enhance(1.0 + 0.05 * intensity)
86
+ return img
87
+
88
+
89
+ def apply_dramatic(img, intensity):
90
+ """Dramatic superhero style"""
91
+ enhancer = ImageEnhance.Contrast(img)
92
+ img = enhancer.enhance(1.0 + 0.5 * intensity)
93
+ enhancer = ImageEnhance.Color(img)
94
+ img = enhancer.enhance(1.0 + 0.3 * intensity)
95
+ enhancer = ImageEnhance.Brightness(img)
96
+ img = enhancer.enhance(1.0 - 0.05 * intensity)
97
+ return img
98
+
99
+
100
+ def apply_vibrant(img, intensity):
101
+ """Vibrant graffiti style"""
102
+ enhancer = ImageEnhance.Color(img)
103
+ img = enhancer.enhance(1.0 + 1.0 * intensity)
104
+ enhancer = ImageEnhance.Contrast(img)
105
+ img = enhancer.enhance(1.0 + 0.4 * intensity)
106
+ return img
107
+
108
+
109
+ def apply_watercolor(img, intensity):
110
+ """Watercolor painting effect"""
111
+ img = img.filter(ImageFilter.GaussianBlur(radius=0.5 * intensity))
112
+ enhancer = ImageEnhance.Color(img)
113
+ img = enhancer.enhance(1.0 + 0.2 * intensity)
114
+ return img
115
+
116
+
117
+ def apply_comic(img, intensity):
118
+ """Comic book style"""
119
+ enhancer = ImageEnhance.Contrast(img)
120
+ img = enhancer.enhance(1.0 + 0.5 * intensity)
121
+ enhancer = ImageEnhance.Color(img)
122
+ img = enhancer.enhance(1.0 + 0.3 * intensity)
123
+ return img
124
+
125
+
126
+ def apply_summer(img, intensity):
127
+ """Warm summer tones"""
128
+ enhancer = ImageEnhance.Color(img)
129
+ img = enhancer.enhance(1.0 + 0.35 * intensity)
130
+ enhancer = ImageEnhance.Brightness(img)
131
+ img = enhancer.enhance(1.0 + 0.08 * intensity)
132
+ # Add warm tint
133
+ r, g, b = img.split()
134
+ r = r.point(lambda x: min(255, x + int(10 * intensity)))
135
+ img = Image.merge('RGB', (r, g, b))
136
+ return img
137
+
138
+
139
+ def apply_winter(img, intensity):
140
+ """Cool winter tones"""
141
+ enhancer = ImageEnhance.Color(img)
142
+ img = enhancer.enhance(1.0 - 0.25 * intensity)
143
+ enhancer = ImageEnhance.Brightness(img)
144
+ img = enhancer.enhance(1.0 + 0.12 * intensity)
145
+ # Add cool tint
146
+ r, g, b = img.split()
147
+ b = b.point(lambda x: min(255, x + int(15 * intensity)))
148
+ img = Image.merge('RGB', (r, g, b))
149
+ return img
150
+
151
+
152
+ def apply_monsoon(img, intensity):
153
+ """Moody monsoon effect"""
154
+ enhancer = ImageEnhance.Color(img)
155
+ img = enhancer.enhance(1.0 - 0.15 * intensity)
156
+ enhancer = ImageEnhance.Brightness(img)
157
+ img = enhancer.enhance(1.0 - 0.12 * intensity)
158
+ enhancer = ImageEnhance.Contrast(img)
159
+ img = enhancer.enhance(1.0 + 0.15 * intensity)
160
+ return img
161
+
162
+
163
+ def apply_enhance(img, intensity):
164
+ """Auto enhance"""
165
+ enhancer = ImageEnhance.Contrast(img)
166
+ img = enhancer.enhance(1.0 + 0.2 * intensity)
167
+ enhancer = ImageEnhance.Color(img)
168
+ img = enhancer.enhance(1.0 + 0.2 * intensity)
169
+ enhancer = ImageEnhance.Sharpness(img)
170
+ img = enhancer.enhance(1.0 + 0.1 * intensity)
171
+ return img
172
+
173
+
174
+ def apply_hdr(img, intensity):
175
+ """HDR effect"""
176
+ enhancer = ImageEnhance.Contrast(img)
177
+ img = enhancer.enhance(1.0 + 0.35 * intensity)
178
+ enhancer = ImageEnhance.Color(img)
179
+ img = enhancer.enhance(1.0 + 0.25 * intensity)
180
+ return img
181
+
182
+
183
+ def apply_sharpen(img, intensity):
184
+ """Sharpen image"""
185
+ enhancer = ImageEnhance.Sharpness(img)
186
+ img = enhancer.enhance(1.0 + 1.0 * intensity)
187
+ return img
188
+
189
+
190
+ def apply_denoise(img, intensity):
191
+ """Reduce noise (slight blur)"""
192
+ img = img.filter(ImageFilter.GaussianBlur(radius=0.3 * intensity))
193
+ enhancer = ImageEnhance.Sharpness(img)
194
+ img = enhancer.enhance(1.0 + 0.2 * intensity)
195
+ return img
196
+
197
+
198
+ def apply_blur_bg(img, intensity):
199
+ """Blur background effect (simplified)"""
200
+ img = img.filter(ImageFilter.GaussianBlur(radius=2 * intensity))
201
+ return img
202
+
203
+
204
+ def apply_relight(img, intensity):
205
+ """Adjust lighting"""
206
+ enhancer = ImageEnhance.Brightness(img)
207
+ img = enhancer.enhance(1.0 + 0.1 * intensity)
208
+ enhancer = ImageEnhance.Contrast(img)
209
+ img = enhancer.enhance(1.0 + 0.1 * intensity)
210
+ return img
211
+
212
+
213
+ def apply_fix_colors(img, intensity):
214
+ """Fix color cast"""
215
+ enhancer = ImageEnhance.Color(img)
216
+ img = enhancer.enhance(1.0 + 0.1 * intensity)
217
+ enhancer = ImageEnhance.Contrast(img)
218
+ img = enhancer.enhance(1.0 + 0.05 * intensity)
219
+ return img
220
+
221
+
222
+ def apply_custom_prompt(image, prompt, intensity=1.0):
223
+ """Apply style based on custom prompt keywords"""
224
+ if image is None:
225
+ return None
226
+
227
+ prompt_lower = prompt.lower()
228
+
229
+ # Detect style from prompt
230
+ if any(word in prompt_lower for word in ['anime', 'cartoon', 'animated']):
231
+ return apply_style(image, "Anime", intensity)
232
+ elif any(word in prompt_lower for word in ['winter', 'snow', 'cold', 'frost']):
233
+ return apply_style(image, "Winter", intensity)
234
+ elif any(word in prompt_lower for word in ['summer', 'warm', 'sunny', 'bright']):
235
+ return apply_style(image, "Summer", intensity)
236
+ elif any(word in prompt_lower for word in ['vintage', 'sepia', 'old', 'retro']):
237
+ img = Image.fromarray(image)
238
+ if img.mode != 'RGB':
239
+ img = img.convert('RGB')
240
+ # Sepia effect
241
+ enhancer = ImageEnhance.Color(img)
242
+ img = enhancer.enhance(0.3)
243
+ r, g, b = img.split()
244
+ r = r.point(lambda x: min(255, x + 30))
245
+ g = g.point(lambda x: min(255, x + 15))
246
+ img = Image.merge('RGB', (r, g, b))
247
+ return np.array(img)
248
+ elif any(word in prompt_lower for word in ['black and white', 'grayscale', 'monochrome']):
249
+ img = Image.fromarray(image)
250
+ img = img.convert('L').convert('RGB')
251
+ enhancer = ImageEnhance.Contrast(img)
252
+ img = enhancer.enhance(1.1)
253
+ return np.array(img)
254
+ elif any(word in prompt_lower for word in ['comic', 'pop art']):
255
+ return apply_style(image, "Comic", intensity)
256
+ elif any(word in prompt_lower for word in ['watercolor', 'painting', 'artistic']):
257
+ return apply_style(image, "Watercolour", intensity)
258
+ elif any(word in prompt_lower for word in ['enhance', 'improve', 'better']):
259
+ return apply_style(image, "Auto Enhance", intensity)
260
+ else:
261
+ # Default: subtle enhancement
262
+ return apply_style(image, "Auto Enhance", intensity * 0.5)
263
+
264
+
265
+ # Create Gradio Interface
266
+ with gr.Blocks(
267
+ title="AI Photo Edit",
268
+ theme=gr.themes.Soft(
269
+ primary_hue="blue",
270
+ secondary_hue="slate",
271
+ ),
272
+ css="""
273
+ .container { max-width: 1200px; margin: auto; }
274
+ .title { text-align: center; margin-bottom: 1rem; }
275
+ """
276
+ ) as demo:
277
+
278
+ gr.Markdown(
279
+ """
280
+ # AI Photo Edit
281
+ Transform your photos with AI-powered styles, enhancements, and fixes.
282
+
283
+ Upload an image and choose a style to apply!
284
+ """
285
+ )
286
+
287
+ with gr.Row():
288
+ with gr.Column(scale=2):
289
+ input_image = gr.Image(label="Upload Image", type="numpy")
290
+ output_image = gr.Image(label="Result", type="numpy")
291
+
292
+ with gr.Column(scale=1):
293
+ with gr.Tabs():
294
+ with gr.TabItem("Restyle"):
295
+ gr.Markdown("### Artistic Styles")
296
+ restyle_dropdown = gr.Dropdown(
297
+ choices=list(RESTYLE_OPTIONS.keys()),
298
+ label="Choose Style",
299
+ value="Anime"
300
+ )
301
+ restyle_btn = gr.Button("Apply Restyle", variant="primary")
302
+
303
+ gr.Markdown("### Seasons")
304
+ season_dropdown = gr.Dropdown(
305
+ choices=list(SEASON_OPTIONS.keys()),
306
+ label="Choose Season",
307
+ value="Summer"
308
+ )
309
+ season_btn = gr.Button("Apply Season", variant="primary")
310
+
311
+ gr.Markdown("### Custom Prompt")
312
+ custom_prompt = gr.Textbox(
313
+ label="Describe your style",
314
+ placeholder="e.g., vintage sepia photograph from the 1920s"
315
+ )
316
+ custom_btn = gr.Button("Apply Custom", variant="primary")
317
+
318
+ with gr.TabItem("Enhance"):
319
+ enhance_dropdown = gr.Dropdown(
320
+ choices=list(ENHANCE_OPTIONS.keys()),
321
+ label="Enhancement Type",
322
+ value="Auto Enhance"
323
+ )
324
+ enhance_btn = gr.Button("Apply Enhancement", variant="primary")
325
+
326
+ with gr.TabItem("Fix"):
327
+ fix_dropdown = gr.Dropdown(
328
+ choices=list(FIX_OPTIONS.keys()),
329
+ label="Fix Type",
330
+ value="Relight"
331
+ )
332
+ fix_btn = gr.Button("Apply Fix", variant="primary")
333
+
334
+ gr.Markdown("### Intensity")
335
+ intensity_slider = gr.Slider(
336
+ minimum=0.1,
337
+ maximum=2.0,
338
+ value=1.0,
339
+ step=0.1,
340
+ label="Effect Intensity"
341
+ )
342
+
343
+ # Event handlers
344
+ restyle_btn.click(
345
+ fn=apply_style,
346
+ inputs=[input_image, restyle_dropdown, intensity_slider],
347
+ outputs=output_image
348
+ )
349
+
350
+ season_btn.click(
351
+ fn=apply_style,
352
+ inputs=[input_image, season_dropdown, intensity_slider],
353
+ outputs=output_image
354
+ )
355
+
356
+ custom_btn.click(
357
+ fn=apply_custom_prompt,
358
+ inputs=[input_image, custom_prompt, intensity_slider],
359
+ outputs=output_image
360
+ )
361
+
362
+ enhance_btn.click(
363
+ fn=apply_style,
364
+ inputs=[input_image, enhance_dropdown, intensity_slider],
365
+ outputs=output_image
366
+ )
367
+
368
+ fix_btn.click(
369
+ fn=apply_style,
370
+ inputs=[input_image, fix_dropdown, intensity_slider],
371
+ outputs=output_image
372
+ )
373
+
374
+ gr.Markdown(
375
+ """
376
+ ---
377
+ **Features:**
378
+ - **Restyle**: Anime, Chibi, Superhero, Graffiti, Watercolour, Comic
379
+ - **Seasons**: Summer, Winter, Monsoon
380
+ - **Enhance**: Auto Enhance, HDR, Sharpen, Reduce Noise
381
+ - **Fix**: Blur Background, Relight, Fix Colors
382
+
383
+ Built with Gradio
384
+ """
385
+ )
386
+
387
+ if __name__ == "__main__":
388
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio>=4.0.0
2
+ Pillow>=9.0.0
3
+ numpy>=1.21.0