File size: 4,856 Bytes
2ff9250
55365d8
c469f55
 
 
55365d8
2ff9250
 
 
 
 
 
 
 
 
 
f90d9e1
2ff9250
f90d9e1
03f9175
2ff9250
 
 
 
 
 
 
 
52f8e1a
2ff9250
52f8e1a
2ff9250
 
55365d8
 
 
 
 
 
 
 
 
2ff9250
 
3781385
949eb01
3781385
 
 
 
 
 
 
2ff9250
03f9175
 
2ff9250
3781385
 
 
 
 
 
 
2ff9250
 
 
 
3781385
2ff9250
55365d8
3781385
 
 
2ff9250
3781385
 
 
 
 
55365d8
 
 
 
3781385
55365d8
 
 
 
3781385
 
55365d8
 
 
 
 
 
3781385
 
55365d8
 
 
 
 
 
2ff9250
 
 
 
55365d8
2ff9250
 
55365d8
 
2ff9250
3781385
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import gradio as gr
import tensorflow as tf
from modules.binary_classification import binary_classification as binary
from modules.image_classification import image_classification as image
from modules.multilabel_classification import multi_classification as multi
from modules.retina import predict_diabetic_retinopathy as retina_detector
import cv2

def binary_classification(text):
    if(text != ''):
        return binary(text)
    else:
        raise gr.Error('Il testo è obbligatorio!')

def multi_classification(text):
    if(text != ''):
        try:
            return multi(text)
        except:
            raise gr.Error('La lingua del testo non corrisponde alla lingua del modello!')
    else:
        raise gr.Error('Il testo è obbligatorio!')  
    
def file_change(file):
    image = cv2.imread(file)
    return image

def image_classification(img):
    try:
        return image(img)
    except:
        raise gr.Error('L\'immagine è obbligatoria!')

def file_change_dr(file):
    return file

def retina_classification(retina):
    try:
        return retina_detector(retina)
    except:
        raise gr.Error('L\'immagine è obbligatoria!')
        
with gr.Blocks() as demo:
    gr.Markdown("# NGT AI Platform")
    with gr.Tab("Sentiment Analysis"):
        gr.Markdown("Inviato il testo di una recensione, il servizio classifica lo stesso come Positivo o Negativo")
        with gr.Row(equal_height=True):
            with gr.Column():
                binary_classification_input = gr.Textbox()
            with gr.Column(scale=1):
                binary_classification_output = gr.Label()
                binary_classification_button = gr.Button("Analizza")
    with gr.Tab("Review Classification"):
        gr.Markdown("""
                    Inviato un testo, il servizio classifica lo stesso come:\n
                    'Economia', 'Politica', 'Scienza_e_tecnica', 'Sport', 'Storia'
                    """)
        with gr.Row(equal_height=True):
            with gr.Column():
                multi_classification_input = gr.Textbox()
            with gr.Column():
                multi_classification_output = gr.Label(num_top_classes=8)
                multi_classification_button = gr.Button("Analizza")
    with gr.Tab("Pneumonia/Tuberculosis Detection"):
        gr.Markdown("""
                    Inviata una radiografia del petto, il servizio classifica la stessa come:\n 
                    'Tubercolosi', 'No_Tubercolosi',  'Pneumonia', 'No_Pneumonia'
                     """)
        with gr.Row(equal_height=True):
            file_selected = gr.FileExplorer(
                root_dir="data/gallery/xray",
                file_count='single',
                label='Esplora',
                height=400
            )
            image_input = gr.Image(show_download_button=False,
                        show_share_button=False, sources=["upload"], height=400)
            with gr.Column():
                image_output = [gr.Label(label="Diagnosi", scale=1)]
                image_button = gr.Button("Analizza")
    with gr.Tab("Diabetic Retinopathy Detection"):
        gr.Markdown("""
                    Questa interfaccia utilizza un modello di deep learning basato su rete neurale convoluzionale, in modo da predirre la presenza o meno di retinopatia diabetica a partire da un'immagine retinica
                     """)
        with gr.Row(equal_height=True):
            with gr.Column(scale=1):
                file_selected_dr = gr.FileExplorer(
                    root_dir="data/gallery/retinopaty",
                    file_count='single',
                    label='Esplora',
                    height=400
                )
            with gr.Column(scale=2):
                with gr.Row():
                    image_i = gr.Image(
                        show_download_button=False,
                        show_share_button=False,
                        sources=["upload"],
                        height=400
                    )
                    with gr.Column():
                        image_o = [gr.Label(label="Diagnosi"), gr.Label(label="Probabilità di patologia")]
                        image_button_dr = gr.Button("Analizza")
                    


    binary_classification_button.click(binary_classification, inputs=binary_classification_input, outputs=binary_classification_output)
    multi_classification_button.click(multi_classification, inputs=multi_classification_input, outputs=multi_classification_output)
    image_button.click(image_classification, inputs=image_input, outputs=image_output)
    image_button_dr.click(retina_classification, inputs=image_i, outputs=image_o)

    file_selected.change(file_change, inputs=file_selected, outputs=image_input)
    file_selected_dr.change(file_change_dr, inputs=file_selected_dr, outputs=image_i)
        

demo.launch()