Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,48 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import tempfile
|
| 3 |
from PIL import Image
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
import cv2 as cv # Add this import
|
| 7 |
from obstruction_detector import ObstructionDetector
|
| 8 |
|
| 9 |
-
#
|
| 10 |
detector = ObstructionDetector()
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
smoothed_histogram = detector.plot_histogram(preprocessed_img)
|
| 30 |
-
|
| 31 |
-
# Convert the preprocessed image to a PIL image for display
|
| 32 |
-
preprocessed_img_pil = Image.fromarray(cv.cvtColor(preprocessed_img, cv.COLOR_BGR2RGB))
|
| 33 |
-
|
| 34 |
-
# Convert the histogram to a grayscale image and scale it to [0, 255]
|
| 35 |
-
histogram_min = smoothed_histogram.min()
|
| 36 |
-
histogram_max = smoothed_histogram.max()
|
| 37 |
-
scaled_histogram = ((smoothed_histogram - histogram_min) / (histogram_max - histogram_min) * 255).astype(np.uint8)
|
| 38 |
-
histogram_img_pil = Image.fromarray(scaled_histogram)
|
| 39 |
-
|
| 40 |
-
return report, preprocessed_img_pil, histogram_img_pil # Return the histogram as an image
|
| 41 |
-
|
| 42 |
-
# Create the Gradio interface
|
| 43 |
-
iface = gr.Interface(fn=preprocess_image,
|
| 44 |
-
inputs=gr.inputs.Image(type="pil", label="Carregar Imagem"),
|
| 45 |
-
outputs=["text", "image", "image"]) # Output the histogram as an image
|
| 46 |
-
|
| 47 |
-
# Launch the interface
|
| 48 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from PIL import Image
|
| 3 |
+
|
| 4 |
+
# Import the ObstructionDetector class from your module
|
|
|
|
| 5 |
from obstruction_detector import ObstructionDetector
|
| 6 |
|
| 7 |
+
# Create an instance of ObstructionDetector
|
| 8 |
detector = ObstructionDetector()
|
| 9 |
|
| 10 |
+
# Define a Gradio function to process the image and return the report
|
| 11 |
+
def process_image(image):
|
| 12 |
+
# Convert Gradio image data to a PIL image
|
| 13 |
+
pil_image = Image.fromarray(image.astype('uint8'), 'RGB')
|
| 14 |
+
|
| 15 |
+
# Call the detect_obstruction method of the ObstructionDetector
|
| 16 |
+
report = detector.detect_obstruction_from_pil_image(pil_image)
|
| 17 |
+
|
| 18 |
+
return report
|
| 19 |
+
|
| 20 |
+
# Define the Gradio interface
|
| 21 |
+
iface = gr.Interface(fn=process_image,
|
| 22 |
+
inputs=gr.inputs.Image(shape=(224, 224)), # Adjust shape as needed
|
| 23 |
+
outputs="text")
|
| 24 |
+
|
| 25 |
+
# Launch the Gradio interface
|
| 26 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|