Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,12 @@
|
|
1 |
-
import cv2
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import numpy as np
|
4 |
import gradio as gr
|
5 |
import os
|
@@ -35,7 +42,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,11 +55,10 @@ def sketch_interface(image, blur_strength, brightness, contrast):
|
|
48 |
output_image = Image.fromarray(sketch)
|
49 |
|
50 |
# Save the processed image temporarily
|
51 |
-
|
52 |
-
output_image.save(output_path)
|
53 |
|
54 |
-
# Return the processed sketch image
|
55 |
-
return output_image,
|
56 |
|
57 |
# Create Gradio interface
|
58 |
interface = gr.Interface(
|
@@ -63,12 +69,9 @@ 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
|
72 |
)
|
73 |
|
74 |
# Launch the Gradio app
|
|
|
1 |
+
# Attempt to import cv2 and install opencv-python-headless if not available
|
2 |
+
try:
|
3 |
+
import cv2
|
4 |
+
except ImportError:
|
5 |
+
import subprocess
|
6 |
+
subprocess.check_call(["pip", "install", "opencv-python-headless"])
|
7 |
+
import cv2
|
8 |
+
|
9 |
+
from PIL import Image, ImageTk
|
10 |
import numpy as np
|
11 |
import gradio as gr
|
12 |
import os
|
|
|
42 |
|
43 |
# Function to adjust brightness and contrast
|
44 |
def adjust_brightness_contrast(img, brightness, contrast):
|
45 |
+
# Apply contrast adjustment
|
46 |
img = cv2.convertScaleAbs(img, alpha=contrast, beta=brightness)
|
47 |
return img
|
48 |
|
|
|
55 |
output_image = Image.fromarray(sketch)
|
56 |
|
57 |
# Save the processed image temporarily
|
58 |
+
output_image.save("sketch_output.png")
|
|
|
59 |
|
60 |
+
# Return the processed sketch image
|
61 |
+
return output_image, "sketch_output.png"
|
62 |
|
63 |
# Create Gradio interface
|
64 |
interface = gr.Interface(
|
|
|
69 |
gr.Slider(-100, 100, label="Brightness", value=0),
|
70 |
gr.Slider(1, 3, step=0.1, label="Contrast", value=1)
|
71 |
],
|
72 |
+
outputs=[gr.Image(type="pil", label="Sketch Output"), gr.File(label="Download Sketch")],
|
|
|
|
|
|
|
73 |
title="Cartoon to Sketch Converter",
|
74 |
+
description="Upload an image to convert it into a sketch, adjust the blur strength, brightness, and contrast for different effects."
|
75 |
)
|
76 |
|
77 |
# Launch the Gradio app
|