File size: 3,314 Bytes
8f6d05a
 
 
 
 
 
 
 
 
ec9f73e
8f6d05a
254a8b9
8f6d05a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f0adec7
8c9c6f3
8f6d05a
 
 
 
41d3a9f
8f6d05a
 
 
 
 
 
 
41d3a9f
 
8f6d05a
 
41d3a9f
 
8f6d05a
 
41d3a9f
 
8f6d05a
 
41d3a9f
 
8f6d05a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import warnings
import src.utils as utils
from src.predict import prediction
from src.logger import get_logger

logger = get_logger(__name__)
warnings.filterwarnings("ignore")

# utils.copy_builder()


def show_processing_text():
    return gr.update(visible=True), gr.update(visible=False)

def prediction_with_loading(image, longitude, latitude, cloud_cover, evapotranspiration, precipitation, min_temp, mean_temp, max_temp, vapour_pressure, wet_day_freq):
    try:
        logger.info("Starting prediction process...")
        response = prediction(
            image, longitude, latitude, cloud_cover, evapotranspiration,
            precipitation, min_temp, mean_temp, max_temp, vapour_pressure, wet_day_freq
        )
        logger.info("Prediction completed successfully.")
        return gr.update(value=response, visible=True), gr.update(visible=False)
    except Exception as e:
        logger.error(f"Error in prediction: {str(e)}")
        return "An error occurred during prediction. Please try again.", gr.update(visible=False)

with gr.Blocks(css=utils.css, js=utils.js, theme=gr.themes.Ocean(font=gr.themes.GoogleFont("Poppins"), primary_hue=gr.themes.colors.red, secondary_hue=gr.themes.colors.pink)) as demo:
    gr.Markdown("## LUMPY SKIN DISEASE PREDICTION", elem_classes="title")
    
    with gr.Row():
        with gr.Column(scale=5):
            # Image upload
            image_input = gr.Image(type="pil", label="Upload Image", height=177, elem_classes="image-input")
        
        with gr.Column(scale=5):
            longitude = gr.Number(label="Longitude")
            latitude = gr.Number(label="Latitude")

    with gr.Row():
        with gr.Column(scale=5):
            cloud_cover = gr.Number(label="Monthly Cloud Cover", elem_classes="num-input")
            evapotranspiration = gr.Number(label="Potential EvapoTranspiration", elem_classes="num-input")
        
        with gr.Column(scale=5):
            precipitation = gr.Number(label="Precipitation", elem_classes="num-input")
            min_temp = gr.Number(label="Minimum Temperature", elem_classes="num-input")

        with gr.Column(scale=5):
            mean_temp = gr.Number(label="Mean Temperature", elem_classes="num-input")
            max_temp = gr.Number(label="Maximum Temperature", elem_classes="num-input")
        
        with gr.Column(scale=5):
            vapour_pressure = gr.Number(label="Vapour Pressure", elem_classes="num-input")
            wet_day_freq = gr.Number(label="Wet Day Frequency", elem_classes="num-input")

    with gr.Row():
        predict_button = gr.Button("Predict", variant="primary")
    
    processing_text = gr.Markdown("", visible=False, height=100)
    output_text = gr.Markdown(label="LLM Generated Diagnostic Report", container=True, show_copy_button=True, visible=False)

    predict_button.click(
        fn=show_processing_text,
        inputs=[],
        outputs=[processing_text, output_text],
        queue=False
    )
    predict_button.click(
        fn=prediction_with_loading,
        inputs=[image_input, longitude, latitude, cloud_cover, evapotranspiration, precipitation, min_temp, mean_temp, max_temp, vapour_pressure, wet_day_freq],
        outputs=[output_text, processing_text],
        queue=True
    )

demo.launch(share=True)