Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,25 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
from obstruction_detector import ObstructionDetector
|
| 3 |
|
| 4 |
# Crie um detector de obstrução
|
| 5 |
detector = ObstructionDetector()
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
# Crie a interface Gradio
|
| 8 |
-
iface = gr.Interface(fn=
|
| 9 |
inputs=gr.inputs.Image(type="pil", label="Carregar Imagem"),
|
| 10 |
outputs="text")
|
| 11 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import tempfile
|
| 3 |
+
from PIL import Image
|
| 4 |
from obstruction_detector import ObstructionDetector
|
| 5 |
|
| 6 |
# Crie um detector de obstrução
|
| 7 |
detector = ObstructionDetector()
|
| 8 |
|
| 9 |
+
# Função para preprocessar a imagem
|
| 10 |
+
def preprocess_image(image):
|
| 11 |
+
# Crie um arquivo temporário
|
| 12 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as temp_image:
|
| 13 |
+
# Salve a imagem PIL no arquivo temporário
|
| 14 |
+
image.save(temp_image.name, "PNG")
|
| 15 |
+
# Obtenha o caminho do arquivo temporário
|
| 16 |
+
img_path = temp_image.name
|
| 17 |
+
# Chame o detector de obstrução com o caminho do arquivo temporário
|
| 18 |
+
report = detector.detect_obstruction(img_path)
|
| 19 |
+
return report
|
| 20 |
+
|
| 21 |
# Crie a interface Gradio
|
| 22 |
+
iface = gr.Interface(fn=preprocess_image,
|
| 23 |
inputs=gr.inputs.Image(type="pil", label="Carregar Imagem"),
|
| 24 |
outputs="text")
|
| 25 |
|