Spaces:
Sleeping
Sleeping
Update app.py
Browse files1234529 unmodified lines353637383940416 unmodified lines48495051525354555657584 unmodified lines636465666768697071727374import cv2from PIL import Imageimport numpy as npimport gradio as grimport os29 unmodified lines# Function to adjust brightness and contrastdef adjust_brightness_contrast(img, brightness, contrast):# Apply contrast adjustment (alpha for contrast, beta for brightness)img = cv2.convertScaleAbs(img, alpha=contrast, beta=brightness)return img6 unmodified linesoutput_image = Image.fromarray(sketch)# Save the processed image temporarilyoutput_path = "sketch_output.png"output_image.save(output_path)# Return the processed sketch image and a downloadable file pathreturn output_image, output_path# Create Gradio interfaceinterface = gr.Interface(4 unmodified linesgr.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"),gr.File(label="Download Sketch")],title="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 app12345678910111229 unmodified lines424344454647486 unmodified lines555657585960616263644 unmodified lines697071727374757677# Attempt to import cv2 and install opencv-python-headless if not availabletry:import cv2except ImportError:import subprocesssubprocess.check_call(["pip", "install", "opencv-python-headless"])import cv2from PIL import Image, ImageTkimport numpy as npimport gradio as grimport os29 unmodified lines# Function to adjust brightness and contrastdef adjust_brightness_contrast(img, brightness, contrast):# Apply contrast adjustmentimg = cv2.convertScaleAbs(img, alpha=contrast, beta=brightness)return img6 unmodified linesoutput_image = Image.fromarray(sketch)# Save the processed image temporarilyoutput_image.save("sketch_output.png")# Return the processed sketch imagereturn output_image, "sketch_output.png"# Create Gradio interfaceinterface = gr.Interface(4 unmodified linesgr.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"), gr.File(label="Download Sketch")],title="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 app
app.py+15-12