File size: 3,066 Bytes
ac42789
 
 
 
 
ad81be2
 
ac42789
ad81be2
 
ac42789
 
ad81be2
 
 
 
 
ac42789
f17256e
 
 
 
 
ac42789
ad81be2
ac42789
 
 
 
 
 
 
 
 
f17256e
 
dcf5aed
 
 
f17256e
 
 
 
 
 
 
 
 
 
dcf5aed
f17256e
ac42789
dcf5aed
f17256e
 
 
 
 
 
 
 
ad81be2
 
ac42789
f17256e
ad81be2
 
 
ac42789
ad81be2
 
 
 
 
 
ac42789
ad81be2
ac42789
ad81be2
 
 
 
 
 
 
ac42789
 
 
 
 
 
 
 
aae057e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import os
import sys
sys.path.append(os.getcwd())

import cv2
import gradio as gr
import numpy as np

from Lib.Consts import COLOR_MAP, LABELS
from Lib.Core import CablePoleSegmentation

demoImages = [
    "data/DJI_20240905095004_0007_W.JPG",
    "data/DJI_20240905091530_0003_W.JPG",
    "data/DJI_20240905094647_0003_W.JPG",
    "data/DJI_20240905094647_0003_Z.JPG",
    "data/DJI_20240905101846_0005_W.JPG",
    "data/16_3450.png", 
    "data/16_3735.png",
    "data/16_3900.png",
    "data/19_00350.png",
    "data/25_00272.png",
    "data/67_02661.png"
]

MODEL = CablePoleSegmentation(retina_mask=False)

def Warning():
    gr.Info("DGH ARGE YAZILIM DANIŞMANLIK ENERJİ İNŞAAT SAN.TİC.LTD.ŞTİ", duration=0.5)

with gr.Blocks(css="footer{display:none !important}") as block:
    gr.Markdown("## Yüksek Gerilim Hattı Kablo ve Direk Tespit ve Segmentasyon Uygulaması - Demo")
    
    with gr.Row():
        with gr.Column():
            inputImage = gr.Image(label="Fotoğraf")

        with gr.Column():
            thresholdSlider = gr.Slider(0, 1, value=0.5, label="Model Eşik Değeri", info="0 ve 1 arası seçiniz.")
            with gr.Accordion("Demo Görsellerden Seçebilirsiniz", open=False):
                imageGallery = gr.Examples(
                    examples=[
                        os.path.join("data", img_name) for img_name in sorted(os.listdir("data"))
                    ],
                    inputs=[inputImage],
                    label="Örnekler",
                    cache_examples=False,
                    examples_per_page=5
                )
            results = gr.Textbox(label="Log")
            processButton = gr.Button("Tespit Et")


    gr.HTML("</hr>")
    processedImageGallery = gr.Gallery(
        label="Sonuçlar",
        rows=1, 
        columns=2, 
        object_fit="contain", 
        height="auto"
    )

    annotatedImage = gr.AnnotatedImage(color_map=COLOR_MAP)

    @processButton.click(outputs=[processedImageGallery, annotatedImage, results], inputs=[inputImage, thresholdSlider])
    def Process(image, model_threshold):
        if image is None:
            raise gr.Warning("Lütfen görüntü yükleyiniz veya hazır seçiniz!", duration=3)

        batches = MODEL.Process(image, model_threshold)

        if len(batches) == 0:
            raise gr.Error("Bir Hata ile Karşılaşıldı: Görüntüde Tespit Yapılamadı 💥!", duration=5)

        scores, classes, masks, boxes = batches[0] # First
        
        canvas, mask = MODEL.DrawResults(image, scores, classes, masks, boxes, class_filter=None)

        sections = []
        for m, b, c in zip(masks.cpu().numpy(), boxes.cpu().numpy(),classes.cpu().numpy()):
            sections+=[(m, LABELS[c])]
            # sections+=[(list(b.astype(np.int32)), LABELS[c])]
        
        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
        return [image, canvas], (image, sections), "Görüntü İşlendi!"
    


    
    block.load(Warning)


block.queue(max_size=10)
block.launch(server_name="0.0.0.0", server_port=1071)