Spaces:
Sleeping
Sleeping
Update app.py
Browse files5 unmodified lines67891011124 unmodified lines1718192021222327 unmodified lines515253545556573 unmodified lines61626364656667686970717273745 unmodified linessubprocess.check_call(["pip", "install", "opencv-python-headless"])import cv2from PIL import Image, ImageTkimport numpy as npimport gradio as grimport os4 unmodified linesimg = np.array(img)# Convert the image to grayscaleimg_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)# Invert the grayscale imageimg_inverted = cv2.bitwise_not(img_gray)27 unmodified lines# Convert the input image to a sketch with adjustmentssketch = convert_to_sketch(image, blur_strength, brightness, contrast)# Ensure the output is a valid image (PIL Image)output_image = Image.fromarray(sketch)# Return the processed sketch image for display3 unmodified linesinterface = gr.Interface(fn=sketch_interface,inputs=[gr.Image(type="pil", label="Upload Image"),gr.Slider(1, 51, step=2, label="Blur Strength", value=21),gr.Slider(-100, 100, label="Brightness", value=0),gr.Slider(1, 3, step=0.1, label="Contrast", value=1)],outputs=[gr.Image(type="pil", label="Sketch Output")], # Output is now just the imagetitle="Cartoon to Sketch Converter",description="Upload an image to convert it into a sketch, adjust the blur strength, brightness, and contrast for different effects.")# Launch the Gradio app5 unmodified lines67891011124 unmodified lines1718192021222327 unmodified lines515253545556573 unmodified lines61626364656667686970717273745 unmodified linessubprocess.check_call(["pip", "install", "opencv-python-headless"])import cv2from PIL import Imageimport numpy as npimport gradio as grimport os4 unmodified linesimg = np.array(img)# Convert the image to grayscaleimg_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)# Invert the grayscale imageimg_inverted = cv2.bitwise_not(img_gray)27 unmodified lines# Convert the input image to a sketch with adjustmentssketch = convert_to_sketch(image, blur_strength, brightness, contrast)# Convert numpy array to PIL Image before returningoutput_image = Image.fromarray(sketch)# Return the processed sketch image for display3 unmodified linesinterface = gr.Interface(fn=sketch_interface,inputs=[gr.Image(type="pil", label="Upload Image", image_mode="RGB", shape=(256, 256)), # Support for various formatsgr.Slider(1, 51, step=2, label="Blur Strength", value=21),gr.Slider(-100, 100, label="Brightness", value=0),gr.Slider(1, 3, step=0.1, label="Contrast", value=1)],outputs=[gr.Image(type="pil", label="Sketch Output")], # Output is now just the imagetitle="Cartoon to Sketch Converter",description="Upload an image (PNG, JPEG, or others) to convert it into a sketch. Adjust the blur strength, brightness, and contrast for different effects.")# Launch the Gradio app
app.py+5-5