Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,10 @@
|
|
1 |
import gradio as gr
|
2 |
-
from PIL import Image, ImageOps, ImageEnhance
|
|
|
3 |
|
4 |
-
def edit_image(image, grayscale, flip, rotate, brightness, contrast, color):
|
5 |
img = Image.open(image)
|
|
|
6 |
if grayscale:
|
7 |
img = ImageOps.grayscale(img)
|
8 |
if flip:
|
@@ -21,9 +23,33 @@ def edit_image(image, grayscale, flip, rotate, brightness, contrast, color):
|
|
21 |
# Apply color
|
22 |
enhancer = ImageEnhance.Color(img)
|
23 |
img = enhancer.enhance(color)
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
return img
|
26 |
|
|
|
|
|
|
|
27 |
interface = gr.Interface(
|
28 |
fn=edit_image,
|
29 |
inputs=[
|
@@ -33,12 +59,20 @@ interface = gr.Interface(
|
|
33 |
gr.Slider(minimum=0, maximum=360, step=1, value=0, label="Rotate Angle"),
|
34 |
gr.Slider(minimum=0.1, maximum=2, step=0.1, value=1, label="Brightness"),
|
35 |
gr.Slider(minimum=0.1, maximum=2, step=0.1, value=1, label="Contrast"),
|
36 |
-
gr.Slider(minimum=0.1, maximum=2, step=0.1, value=1, label="Color")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
],
|
38 |
outputs=gr.Image(),
|
39 |
live=True,
|
40 |
title="Advanced Image Editor",
|
41 |
-
description="Upload an image and apply various transformations including brightness, contrast, and
|
42 |
)
|
43 |
|
44 |
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from PIL import Image, ImageOps, ImageEnhance, ImageFilter, ImageDraw
|
3 |
+
import numpy as np
|
4 |
|
5 |
+
def edit_image(image, grayscale, flip, rotate, brightness, contrast, color, crop, resize, blur, sharpness, draw_text, text_position, text_color, text_size):
|
6 |
img = Image.open(image)
|
7 |
+
|
8 |
if grayscale:
|
9 |
img = ImageOps.grayscale(img)
|
10 |
if flip:
|
|
|
23 |
# Apply color
|
24 |
enhancer = ImageEnhance.Color(img)
|
25 |
img = enhancer.enhance(color)
|
26 |
+
|
27 |
+
# Apply crop
|
28 |
+
if crop:
|
29 |
+
img = img.crop(crop)
|
30 |
+
|
31 |
+
# Apply resize
|
32 |
+
if resize:
|
33 |
+
img = img.resize(resize)
|
34 |
+
|
35 |
+
# Apply blur
|
36 |
+
if blur > 0:
|
37 |
+
img = img.filter(ImageFilter.GaussianBlur(blur))
|
38 |
+
|
39 |
+
# Apply sharpness
|
40 |
+
enhancer = ImageEnhance.Sharpness(img)
|
41 |
+
img = enhancer.enhance(sharpness)
|
42 |
+
|
43 |
+
# Draw text
|
44 |
+
if draw_text:
|
45 |
+
draw = ImageDraw.Draw(img)
|
46 |
+
draw.text(text_position, draw_text, fill=text_color, font=None, anchor=None, spacing=4, align="left")
|
47 |
+
|
48 |
return img
|
49 |
|
50 |
+
def get_crop_coordinates(crop_start, crop_end):
|
51 |
+
return (crop_start[0], crop_start[1], crop_end[0], crop_end[1])
|
52 |
+
|
53 |
interface = gr.Interface(
|
54 |
fn=edit_image,
|
55 |
inputs=[
|
|
|
59 |
gr.Slider(minimum=0, maximum=360, step=1, value=0, label="Rotate Angle"),
|
60 |
gr.Slider(minimum=0.1, maximum=2, step=0.1, value=1, label="Brightness"),
|
61 |
gr.Slider(minimum=0.1, maximum=2, step=0.1, value=1, label="Contrast"),
|
62 |
+
gr.Slider(minimum=0.1, maximum=2, step=0.1, value=1, label="Color"),
|
63 |
+
gr.Textbox(label="Crop (left, upper, right, lower)", placeholder="e.g., 100,100,400,400"),
|
64 |
+
gr.Textbox(label="Resize (width, height)", placeholder="e.g., 800,600"),
|
65 |
+
gr.Slider(minimum=0, maximum=10, step=0.1, value=0, label="Blur"),
|
66 |
+
gr.Slider(minimum=0.1, maximum=2, step=0.1, value=1, label="Sharpness"),
|
67 |
+
gr.Textbox(label="Draw Text", placeholder="e.g., Hello World"),
|
68 |
+
gr.Textbox(label="Text Position (x, y)", placeholder="e.g., 100,100"),
|
69 |
+
gr.ColorPicker(label="Text Color"),
|
70 |
+
gr.Slider(minimum=10, maximum=100, step=1, value=30, label="Text Size")
|
71 |
],
|
72 |
outputs=gr.Image(),
|
73 |
live=True,
|
74 |
title="Advanced Image Editor",
|
75 |
+
description="Upload an image and apply various transformations including brightness, contrast, color adjustments, cropping, resizing, blurring, and adding text."
|
76 |
)
|
77 |
|
78 |
interface.launch()
|