File size: 1,398 Bytes
408242e
81f27f3
ba0a843
81f27f3
ba0a843
 
 
 
 
 
 
d65a8bc
 
 
 
 
 
 
 
 
 
 
 
 
ba0a843
 
 
 
 
602b640
545d6f0
 
d65a8bc
 
 
81f27f3
ba0a843
545d6f0
ba0a843
d65a8bc
81f27f3
ba0a843
 
81f27f3
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
import gradio as gr
from PIL import Image, ImageOps, ImageEnhance

def edit_image(image, grayscale, flip, rotate, brightness, contrast, color):
    img = Image.open(image)
    if grayscale:
        img = ImageOps.grayscale(img)
    if flip:
        img = ImageOps.flip(img)
    if rotate:
        img = img.rotate(rotate)
    
    # Apply brightness
    enhancer = ImageEnhance.Brightness(img)
    img = enhancer.enhance(brightness)
    
    # Apply contrast
    enhancer = ImageEnhance.Contrast(img)
    img = enhancer.enhance(contrast)
    
    # Apply color
    enhancer = ImageEnhance.Color(img)
    img = enhancer.enhance(color)

    return img

interface = gr.Interface(
    fn=edit_image,
    inputs=[
        gr.Image(type="filepath", label="Upload Image"),
        gr.Checkbox(label="Grayscale"),
        gr.Checkbox(label="Flip Vertically"),
        gr.Slider(minimum=0, maximum=360, step=1, value=0, label="Rotate Angle"),
        gr.Slider(minimum=0.1, maximum=2, step=0.1, value=1, label="Brightness"),
        gr.Slider(minimum=0.1, maximum=2, step=0.1, value=1, label="Contrast"),
        gr.Slider(minimum=0.1, maximum=2, step=0.1, value=1, label="Color")
    ],
    outputs=gr.Image(),
    live=True,
    title="Advanced Image Editor",
    description="Upload an image and apply various transformations including brightness, contrast, and color adjustments."
)

interface.launch()