Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,9 @@ import numpy as np
|
|
| 3 |
from PIL import Image
|
| 4 |
Image.MAX_IMAGE_PIXELS = None
|
| 5 |
import gradio as gr
|
| 6 |
-
|
|
|
|
|
|
|
| 7 |
def freemium_watermark(img, sb_logo):
|
| 8 |
width_px, height_px = img.size
|
| 9 |
# Convert the logo to "RGBA" mode and resize it to 80% of the image width
|
|
@@ -22,8 +24,38 @@ def freemium_watermark(img, sb_logo):
|
|
| 22 |
# Save the image
|
| 23 |
return img
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
with gr.Blocks(analytics_enabled=False, theme=gr.themes.Soft()) as demo:
|
| 28 |
with gr.Row():
|
| 29 |
with gr.Column():
|
|
@@ -32,21 +64,26 @@ with gr.Blocks(analytics_enabled=False, theme=gr.themes.Soft()) as demo:
|
|
| 32 |
gr.Examples(examples=["hotel.jpg", "road_small.jpg", "crash_small.jpg", "trailer.jpg"], inputs=input)
|
| 33 |
with gr.Column():
|
| 34 |
output = gr.Image(type = "filepath", label="Sketch Drawing", show_share_button=False)
|
|
|
|
|
|
|
|
|
|
| 35 |
gr.Markdown("<p style='text-align: center; font-size: 20px;'>Want to remove the watermark?</p>\n")
|
| 36 |
gr.Markdown("<p style='text-align: center; font-size: 20px;'>Subscribe or <a href='https://skyebrowse.com/pricing'>purchase a model</a> starting at $3.<p>")
|
|
|
|
|
|
|
| 37 |
|
| 38 |
@gr.on(inputs=[input], outputs=[output], show_progress="minimal")
|
| 39 |
-
def sketch(input_path):
|
| 40 |
if input_path is None:
|
| 41 |
return None
|
| 42 |
img_array = np.array(input_path)
|
| 43 |
# Line processing
|
| 44 |
blurred = cv2.GaussianBlur(img_array, (7, 7), 0)
|
| 45 |
edges = cv2.Canny(blurred, 100, 180)
|
| 46 |
-
structuring_element = cv2.getStructuringElement(cv2.MORPH_RECT, (
|
| 47 |
-
dilated_edges = cv2.dilate(edges, structuring_element, iterations=
|
| 48 |
line_drawing = 255 - dilated_edges
|
| 49 |
line_img = Image.fromarray(line_drawing)
|
| 50 |
return freemium_watermark(line_img, sb_logo)
|
| 51 |
|
| 52 |
-
demo.queue(default_concurrency_limit=10).launch()
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
Image.MAX_IMAGE_PIXELS = None
|
| 5 |
import gradio as gr
|
| 6 |
+
|
| 7 |
+
sb_logo = Image.open("./SB_logo_horizontal.png")
|
| 8 |
+
|
| 9 |
def freemium_watermark(img, sb_logo):
|
| 10 |
width_px, height_px = img.size
|
| 11 |
# Convert the logo to "RGBA" mode and resize it to 80% of the image width
|
|
|
|
| 24 |
# Save the image
|
| 25 |
return img
|
| 26 |
|
| 27 |
+
def lighter(input_path):
|
| 28 |
+
print('lighter')
|
| 29 |
+
if input_path is None:
|
| 30 |
+
return None
|
| 31 |
+
img_array = np.array(input_path)
|
| 32 |
+
# Line processing
|
| 33 |
+
blurred = cv2.GaussianBlur(img_array, (7, 7), 0)
|
| 34 |
+
#lighter
|
| 35 |
+
edges = cv2.Canny(blurred, 100, 180)
|
| 36 |
+
structuring_element = cv2.getStructuringElement(cv2.MORPH_RECT, (2,2))
|
| 37 |
+
dilated_edges = cv2.dilate(edges, structuring_element, iterations=1)
|
| 38 |
+
line_drawing = 255 - dilated_edges
|
| 39 |
+
line_img = Image.fromarray(line_drawing)
|
| 40 |
+
return freemium_watermark(line_img, sb_logo)
|
| 41 |
|
| 42 |
+
def darker(input_path):
|
| 43 |
+
print('darker')
|
| 44 |
+
if input_path is None:
|
| 45 |
+
return None
|
| 46 |
+
img_array = np.array(input_path)
|
| 47 |
+
# Line processing
|
| 48 |
+
blurred = cv2.GaussianBlur(img_array, (5, 5), 0)
|
| 49 |
+
#darker
|
| 50 |
+
edges = cv2.Canny(blurred, 60, 90) #darker
|
| 51 |
+
#lighter
|
| 52 |
+
# edges = cv2.Canny(blurred, 100, 180)
|
| 53 |
+
structuring_element = cv2.getStructuringElement(cv2.MORPH_RECT, (2,2))
|
| 54 |
+
dilated_edges = cv2.dilate(edges, structuring_element, iterations=2)
|
| 55 |
+
line_drawing = 255 - dilated_edges
|
| 56 |
+
line_img = Image.fromarray(line_drawing)
|
| 57 |
+
return freemium_watermark(line_img, sb_logo)
|
| 58 |
+
|
| 59 |
with gr.Blocks(analytics_enabled=False, theme=gr.themes.Soft()) as demo:
|
| 60 |
with gr.Row():
|
| 61 |
with gr.Column():
|
|
|
|
| 64 |
gr.Examples(examples=["hotel.jpg", "road_small.jpg", "crash_small.jpg", "trailer.jpg"], inputs=input)
|
| 65 |
with gr.Column():
|
| 66 |
output = gr.Image(type = "filepath", label="Sketch Drawing", show_share_button=False)
|
| 67 |
+
with gr.Row():
|
| 68 |
+
lighter_btn=gr.Button("Lighter")
|
| 69 |
+
darker_btn=gr.Button("Darker")
|
| 70 |
gr.Markdown("<p style='text-align: center; font-size: 20px;'>Want to remove the watermark?</p>\n")
|
| 71 |
gr.Markdown("<p style='text-align: center; font-size: 20px;'>Subscribe or <a href='https://skyebrowse.com/pricing'>purchase a model</a> starting at $3.<p>")
|
| 72 |
+
lighter_btn.click(lighter, inputs=[input], outputs=[output], show_progress="minimal")
|
| 73 |
+
darker_btn.click(darker, inputs=[input], outputs=[output], show_progress="minimal")
|
| 74 |
|
| 75 |
@gr.on(inputs=[input], outputs=[output], show_progress="minimal")
|
| 76 |
+
def sketch(input_path):
|
| 77 |
if input_path is None:
|
| 78 |
return None
|
| 79 |
img_array = np.array(input_path)
|
| 80 |
# Line processing
|
| 81 |
blurred = cv2.GaussianBlur(img_array, (7, 7), 0)
|
| 82 |
edges = cv2.Canny(blurred, 100, 180)
|
| 83 |
+
structuring_element = cv2.getStructuringElement(cv2.MORPH_RECT, (2,2))
|
| 84 |
+
dilated_edges = cv2.dilate(edges, structuring_element, iterations=2)
|
| 85 |
line_drawing = 255 - dilated_edges
|
| 86 |
line_img = Image.fromarray(line_drawing)
|
| 87 |
return freemium_watermark(line_img, sb_logo)
|
| 88 |
|
| 89 |
+
demo.queue(default_concurrency_limit=10, api_open=False).launch(show_api=False)
|