File size: 2,315 Bytes
341bdae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3375473
 
341bdae
 
 
 
 
 
 
 
 
 
 
 
 
3375473
 
 
 
341bdae
 
 
 
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
import sys
sys.path.append('src/') # Add src to path

import gradio as gr

from utils import get_array, save_video, make_predictions
from data.processing import Scaler

examples = [["data/2023-05-05.mp4", '2023-05-05', '12:00:00', '21:30:00'],
            ["data/2023-09-07.mp4", '2023-09-07', '07:00:00', '16:30:00'],
            ["data/2023-10-28.mp4", '2023-10-28', '12:00:00', '21:30:00'],
            ["data/2023-11-09.mp4", '2023-11-09', '01:30:00', '11:00:00'],
            ["data/2023-11-13.mp4", '2023-11-15', '00:00:00', '09:30:00'],
            ["data/2023-11-18.mp4", '2023-11-18', '00:00:00', '09:30:00']]

scaler_dict = {"2023-05-05.mp4": "models/scaler_1.pkl",
               "2023-09-07.mp4": "models/scaler_2.pkl",
               "2023-10-28.mp4": "models/scaler_3.pkl",
               "2023-11-09.mp4": "models/scaler_4.pkl",
               "2023-11-13.mp4": "models/scaler_5.pkl",
               "2023-11-18.mp4": "models/scaler_6.pkl"}

def predict(source, date, start, end):

    print(f"Date: {date}")
    print(f"Start: {start}")
    print(f"End: {end}")

    X, y = get_array(source, scaler_dict)
    print(X.shape, y.shape)

    file_path_input = 'data/input.mp4'
    save_video(X, threshold=0, file_path=file_path_input)
    
    file_path_output = 'data/output.mp4'
    save_video(y, threshold=0, file_path=file_path_output)

    ypred = make_predictions(X)

    file_path_predict = 'data/predict.mp4'
    save_video(ypred, threshold=0.1, file_path=file_path_predict)

    return [file_path_input, file_path_output, file_path_predict]

article = "<div style='text-align: center;'><a href='https://www.linkedin.com/in/rlrocha/' target='_blank'>Space by Rafael Rocha</a><br></div>"

demo = gr.Interface(
    fn=predict,
    inputs=[
        gr.Video(label="Source", visible=False),
        gr.Text(label='Date'),
        gr.Text(label='Start'),
        gr.Text(label='End')
        ],
    outputs=[
        gr.Video(label='Input'),
        gr.Video(label='Output'),
        gr.Video(label='Prediction')
    ],
    examples=examples,
    title = 'IMERG Nowcasting from Southern Brazil',
    description = 'Precipitation nowcasting of south region of Brazil using Integrated Multi-satellitE Retrievals for GPM (IMERG) data',
    article=article
)

if __name__ == "__main__":
    demo.launch()