mobenta commited on
Commit
0d77952
·
verified ·
1 Parent(s): 6d9db15

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +63 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from PIL import Image, ImageEnhance, ImageFilter
4
+ import numpy as np
5
+
6
+ def edit_image(image, crop, resize_width, resize_height, rotate, flip, brightness, contrast, blur):
7
+ img = Image.fromarray(image)
8
+
9
+ # Cropping (crop box should be in left, top, right, bottom format)
10
+ if crop != (0, 0, img.width, img.height):
11
+ crop_values = [int(x) for x in crop.split(",")]
12
+ img = img.crop(crop_values)
13
+
14
+ # Resizing
15
+ if resize_width and resize_height:
16
+ img = img.resize((resize_width, resize_height))
17
+
18
+ # Rotation
19
+ if rotate:
20
+ img = img.rotate(rotate)
21
+
22
+ # Flipping
23
+ if flip == "Horizontal":
24
+ img = img.transpose(Image.FLIP_LEFT_RIGHT)
25
+ elif flip == "Vertical":
26
+ img = img.transpose(Image.FLIP_TOP_BOTTOM)
27
+
28
+ # Brightness Adjustment
29
+ if brightness != 1:
30
+ enhancer = ImageEnhance.Brightness(img)
31
+ img = enhancer.enhance(brightness)
32
+
33
+ # Contrast Adjustment
34
+ if contrast != 1:
35
+ enhancer = ImageEnhance.Contrast(img)
36
+ img = enhancer.enhance(contrast)
37
+
38
+ # Blurring
39
+ if blur > 0:
40
+ img = img.filter(ImageFilter.GaussianBlur(blur))
41
+
42
+ return np.array(img)
43
+
44
+ # Define the interface
45
+ iface = gr.Interface(
46
+ fn=edit_image,
47
+ inputs=[
48
+ gr.Image(type="numpy"), # Input image without the tool argument
49
+ gr.Textbox(label="Crop (left, top, right, bottom)", value="0, 0, 500, 500"),
50
+ gr.Slider(minimum=10, maximum=1000, label="Resize Width", value=500),
51
+ gr.Slider(minimum=10, maximum=1000, label="Resize Height", value=500),
52
+ gr.Slider(minimum=-360, maximum=360, label="Rotate (degrees)", value=0),
53
+ gr.Radio(choices=["None", "Horizontal", "Vertical"], label="Flip", value="None"),
54
+ gr.Slider(minimum=0.1, maximum=2.0, step=0.1, label="Brightness", value=1),
55
+ gr.Slider(minimum=0.1, maximum=2.0, step=0.1, label="Contrast", value=1),
56
+ gr.Slider(minimum=0, maximum=10, step=1, label="Blur", value=0)
57
+ ],
58
+ outputs="image",
59
+ title="Image Editor with Cropping, Resizing, Rotation, Brightness, and More",
60
+ description="Upload an image and apply various editing features such as cropping, resizing, rotation, flipping, brightness/contrast adjustments, and blurring."
61
+ )
62
+
63
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ opencv-python
3
+ svgwrite
4
+ numpy