Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,11 @@
|
|
1 |
import gradio as gr
|
2 |
from rembg import remove
|
3 |
-
from PIL import Image as PILImage, ImageFilter
|
4 |
from io import BytesIO
|
5 |
import requests
|
6 |
import cv2
|
7 |
import numpy as np
|
|
|
8 |
|
9 |
def remove_and_replace_background(subject, background, blur_radius, replace_background, use_color_picker, color):
|
10 |
with open(subject, 'rb') as subject_img_file:
|
@@ -111,6 +112,27 @@ def rotate_image(img_input, degrees):
|
|
111 |
def generate_iopaint_link():
|
112 |
return "https://huggingface.co/spaces/Pontarids/IOPaint_Runner"
|
113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
with gr.Blocks() as demo:
|
115 |
|
116 |
with gr.Tab("Remove and Replace Background"):
|
@@ -147,13 +169,21 @@ with gr.Blocks() as demo:
|
|
147 |
img_button_contrast.click(adjust_brightness_and_darkness, inputs=[img_input_contrast, brightness_checkbox, brightness_slider, darkness_checkbox, darkness_slider], outputs=img_output_contrast)
|
148 |
|
149 |
with gr.Tab("Rotate Image"):
|
150 |
-
temp_slider = gr.Slider(minimum=0, maximum=360,
|
151 |
img_input_rotate = gr.Image()
|
152 |
img_output_rotate = gr.Image()
|
153 |
img_button_rotate = gr.Button("Submit")
|
154 |
img_button_rotate.click(rotate_image, inputs=[img_input_rotate, temp_slider], outputs=img_output_rotate)
|
155 |
|
156 |
-
with gr.Tab("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
link_output = gr.Markdown()
|
158 |
link_button = gr.Button("Generate IOPaint Link")
|
159 |
link_button.click(generate_iopaint_link, outputs=link_output)
|
|
|
1 |
import gradio as gr
|
2 |
from rembg import remove
|
3 |
+
from PIL import Image as PILImage, ImageFilter, Image
|
4 |
from io import BytesIO
|
5 |
import requests
|
6 |
import cv2
|
7 |
import numpy as np
|
8 |
+
import webbrowser
|
9 |
|
10 |
def remove_and_replace_background(subject, background, blur_radius, replace_background, use_color_picker, color):
|
11 |
with open(subject, 'rb') as subject_img_file:
|
|
|
112 |
def generate_iopaint_link():
|
113 |
return "https://huggingface.co/spaces/Pontarids/IOPaint_Runner"
|
114 |
|
115 |
+
def skew_image(image, horizontal_skew, vertical_skew):
|
116 |
+
image_np = np.array(image)
|
117 |
+
rows, cols, ch = image_np.shape
|
118 |
+
|
119 |
+
horizontal_factor = horizontal_skew / 100.0
|
120 |
+
vertical_factor = vertical_skew / 100.0
|
121 |
+
|
122 |
+
M_horizontal = np.float32([[1, horizontal_factor, 0],
|
123 |
+
[0, 1, 0],
|
124 |
+
[0, 0, 1]])
|
125 |
+
|
126 |
+
M_vertical = np.float32([[1, 0, 0],
|
127 |
+
[vertical_factor, 1, 0],
|
128 |
+
[0, 0, 1]])
|
129 |
+
|
130 |
+
skewed_image_horizontal = cv2.warpPerspective(image_np, M_horizontal, (cols, rows))
|
131 |
+
skewed_image_vertical = cv2.warpPerspective(skewed_image_horizontal, M_vertical, (cols, rows))
|
132 |
+
|
133 |
+
skewed_image = Image.fromarray(skewed_image_vertical)
|
134 |
+
return skewed_image
|
135 |
+
|
136 |
with gr.Blocks() as demo:
|
137 |
|
138 |
with gr.Tab("Remove and Replace Background"):
|
|
|
169 |
img_button_contrast.click(adjust_brightness_and_darkness, inputs=[img_input_contrast, brightness_checkbox, brightness_slider, darkness_checkbox, darkness_slider], outputs=img_output_contrast)
|
170 |
|
171 |
with gr.Tab("Rotate Image"):
|
172 |
+
temp_slider = gr.Slider(minimum=0, maximum=360, interactive=True, label="Slide me")
|
173 |
img_input_rotate = gr.Image()
|
174 |
img_output_rotate = gr.Image()
|
175 |
img_button_rotate = gr.Button("Submit")
|
176 |
img_button_rotate.click(rotate_image, inputs=[img_input_rotate, temp_slider], outputs=img_output_rotate)
|
177 |
|
178 |
+
with gr.Tab("Skew Tool"):
|
179 |
+
image_input = gr.Image(type="pil", label="Upload an image")
|
180 |
+
horizontal_slider = gr.Slider(minimum=-100, maximum=100, value=0, label="Horizontal Skew")
|
181 |
+
vertical_slider = gr.Slider(minimum=-100, maximum=100, value=0, label="Vertical Skew")
|
182 |
+
output_image = gr.Image(type="pil", label="Skewed Image")
|
183 |
+
submit_button_skew = gr.Button("Submit")
|
184 |
+
submit_button_skew.click(skew_image, inputs=[image_input, horizontal_slider, vertical_slider], outputs=output_image)
|
185 |
+
|
186 |
+
with gr.Tab("Object Remover π"):
|
187 |
link_output = gr.Markdown()
|
188 |
link_button = gr.Button("Generate IOPaint Link")
|
189 |
link_button.click(generate_iopaint_link, outputs=link_output)
|