Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import cv2
|
2 |
-
from PIL import Image
|
3 |
import numpy as np
|
4 |
import gradio as gr
|
5 |
import os
|
@@ -35,7 +35,7 @@ def convert_to_sketch(img, blur_strength, brightness, contrast):
|
|
35 |
|
36 |
# Function to adjust brightness and contrast
|
37 |
def adjust_brightness_contrast(img, brightness, contrast):
|
38 |
-
# Apply contrast adjustment
|
39 |
img = cv2.convertScaleAbs(img, alpha=contrast, beta=brightness)
|
40 |
return img
|
41 |
|
@@ -48,10 +48,11 @@ def sketch_interface(image, blur_strength, brightness, contrast):
|
|
48 |
output_image = Image.fromarray(sketch)
|
49 |
|
50 |
# Save the processed image temporarily
|
51 |
-
|
|
|
52 |
|
53 |
-
# Return the processed sketch image and
|
54 |
-
return output_image,
|
55 |
|
56 |
# Create Gradio interface
|
57 |
interface = gr.Interface(
|
@@ -62,9 +63,12 @@ interface = gr.Interface(
|
|
62 |
gr.Slider(-100, 100, label="Brightness", value=0),
|
63 |
gr.Slider(1, 3, step=0.1, label="Contrast", value=1)
|
64 |
],
|
65 |
-
outputs=[
|
|
|
|
|
|
|
66 |
title="Cartoon to Sketch Converter",
|
67 |
-
description="Upload an image to convert it into a sketch
|
68 |
)
|
69 |
|
70 |
# Launch the Gradio app
|
|
|
1 |
import cv2
|
2 |
+
from PIL import Image
|
3 |
import numpy as np
|
4 |
import gradio as gr
|
5 |
import os
|
|
|
35 |
|
36 |
# Function to adjust brightness and contrast
|
37 |
def adjust_brightness_contrast(img, brightness, contrast):
|
38 |
+
# Apply contrast adjustment (alpha for contrast, beta for brightness)
|
39 |
img = cv2.convertScaleAbs(img, alpha=contrast, beta=brightness)
|
40 |
return img
|
41 |
|
|
|
48 |
output_image = Image.fromarray(sketch)
|
49 |
|
50 |
# Save the processed image temporarily
|
51 |
+
output_path = "sketch_output.png"
|
52 |
+
output_image.save(output_path)
|
53 |
|
54 |
+
# Return the processed sketch image and a downloadable file path
|
55 |
+
return output_image, output_path
|
56 |
|
57 |
# Create Gradio interface
|
58 |
interface = gr.Interface(
|
|
|
63 |
gr.Slider(-100, 100, label="Brightness", value=0),
|
64 |
gr.Slider(1, 3, step=0.1, label="Contrast", value=1)
|
65 |
],
|
66 |
+
outputs=[
|
67 |
+
gr.Image(type="pil", label="Sketch Output"),
|
68 |
+
gr.File(label="Download Sketch")
|
69 |
+
],
|
70 |
title="Cartoon to Sketch Converter",
|
71 |
+
description="Upload an image to convert it into a sketch. Adjust the blur strength, brightness, and contrast for different effects."
|
72 |
)
|
73 |
|
74 |
# Launch the Gradio app
|