Spaces:
Runtime error
Runtime error
Commit
Β·
7ca5f13
1
Parent(s):
d16b6a3
Try readding canny with imports only
Browse files
app.py
CHANGED
@@ -375,46 +375,45 @@ with gr.Blocks() as beta:
|
|
375 |
|
376 |
# ----- Canny Edge Tab -----------------------------------------------------------------
|
377 |
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
# # Define a function to process the uploaded image
|
384 |
-
# def canny_process_image(input_image, input_low_threshold, input_high_threshold, input_invert):
|
385 |
-
# # Convert the input image to a NumPy array
|
386 |
-
# np_image = np.array(input_image)
|
387 |
|
388 |
-
#
|
389 |
-
|
390 |
-
#
|
|
|
|
|
|
|
|
|
391 |
|
392 |
-
#
|
393 |
-
#
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
|
401 |
-
|
402 |
|
403 |
-
#
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
|
409 |
-
|
410 |
|
411 |
-
#
|
412 |
-
|
413 |
|
414 |
|
415 |
|
416 |
# ----- Launch Tabs -----------------------------------------------------------------
|
417 |
|
418 |
-
|
419 |
-
tabbed_interface = gr.TabbedInterface([new_welcome, advanced_tab, beta], ["Artists", "Advanced", "Beta"])
|
420 |
tabbed_interface.launch()
|
|
|
375 |
|
376 |
# ----- Canny Edge Tab -----------------------------------------------------------------
|
377 |
|
378 |
+
from PIL import Image
|
379 |
+
import gradio as gr
|
380 |
+
import numpy as np
|
381 |
+
import cv2
|
|
|
|
|
|
|
|
|
|
|
382 |
|
383 |
+
# Define a function to process the uploaded image
|
384 |
+
def canny_process_image(input_image, input_low_threshold, input_high_threshold, input_invert):
|
385 |
+
# Convert the input image to a NumPy array
|
386 |
+
np_image = np.array(input_image)
|
387 |
+
output_image = input_image # For example, just return the input image
|
388 |
+
numpy_image = np.array(output_image)
|
389 |
+
# Return the processed image
|
390 |
|
391 |
+
# low_threshold = 100
|
392 |
+
# high_threshold = 200
|
393 |
+
canny_1 = cv2.Canny(numpy_image, input_low_threshold, input_high_threshold)
|
394 |
+
canny_1 = canny_1[:, :, None]
|
395 |
+
canny_1 = np.concatenate([canny_1, canny_1, canny_1], axis=2)
|
396 |
+
if input_invert:
|
397 |
+
canny_1 = 255 - canny_1
|
398 |
+
canny_2 = Image.fromarray(canny_1)
|
399 |
|
400 |
+
return np.array(canny_2)
|
401 |
|
402 |
+
# Define the input and output interfaces
|
403 |
+
canny_input_image = gr.inputs.Image()
|
404 |
+
canny_input_low_threshold = gr.inputs.Slider(minimum=0, maximum=1000, step=1, label="Lower Threshold:", default=100)
|
405 |
+
canny_input_high_threshold = gr.inputs.Slider(minimum=0, maximum=1000, step=1, label="Upper Threshold:", default=200)
|
406 |
+
canny_input_invert = gr.inputs.Checkbox(label="Invert Image")
|
407 |
|
408 |
+
canny_outputs = gr.outputs.Image(type="numpy")
|
409 |
|
410 |
+
# Create the Gradio interface
|
411 |
+
canny_interface = gr.Interface(fn=canny_process_image, inputs=[canny_input_image, canny_input_low_threshold, canny_input_high_threshold, canny_input_invert], outputs=canny_outputs, title='Canny Edge Tracing', allow_flagging='never')
|
412 |
|
413 |
|
414 |
|
415 |
# ----- Launch Tabs -----------------------------------------------------------------
|
416 |
|
417 |
+
tabbed_interface = gr.TabbedInterface([new_welcome, advanced_tab, beta, canny_interface], ["Artists", "Advanced", "Beta", "Edges"])
|
418 |
+
# tabbed_interface = gr.TabbedInterface([new_welcome, advanced_tab, beta], ["Artists", "Advanced", "Beta"])
|
419 |
tabbed_interface.launch()
|