Spaces:
Sleeping
Sleeping
| 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() |