Spaces:
Sleeping
Sleeping
add app
Browse files
app.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
sys.path.append('src/') # Add src to path
|
3 |
+
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
from utils import get_array, save_video, make_predictions
|
7 |
+
from data.processing import Scaler
|
8 |
+
|
9 |
+
examples = [["data/2023-05-05.mp4", '2023-05-05', '12:00:00', '21:30:00'],
|
10 |
+
["data/2023-09-07.mp4", '2023-09-07', '07:00:00', '16:30:00'],
|
11 |
+
["data/2023-10-28.mp4", '2023-10-28', '12:00:00', '21:30:00'],
|
12 |
+
["data/2023-11-09.mp4", '2023-11-09', '01:30:00', '11:00:00'],
|
13 |
+
["data/2023-11-13.mp4", '2023-11-15', '00:00:00', '09:30:00'],
|
14 |
+
["data/2023-11-18.mp4", '2023-11-18', '00:00:00', '09:30:00']]
|
15 |
+
|
16 |
+
scaler_dict = {"2023-05-05.mp4": "models/scaler_1.pkl",
|
17 |
+
"2023-09-07.mp4": "models/scaler_2.pkl",
|
18 |
+
"2023-10-28.mp4": "models/scaler_3.pkl",
|
19 |
+
"2023-11-09.mp4": "models/scaler_4.pkl",
|
20 |
+
"2023-11-13.mp4": "models/scaler_5.pkl",
|
21 |
+
"2023-11-18.mp4": "models/scaler_6.pkl"}
|
22 |
+
|
23 |
+
def predict(source, date, start, end):
|
24 |
+
|
25 |
+
print(f"Date: {date}")
|
26 |
+
print(f"Start: {start}")
|
27 |
+
print(f"End: {end}")
|
28 |
+
|
29 |
+
X, y = get_array(source, scaler_dict)
|
30 |
+
print(X.shape, y.shape)
|
31 |
+
|
32 |
+
file_path_input = 'data/input.mp4'
|
33 |
+
save_video(X, threshold=0, file_path=file_path_input)
|
34 |
+
|
35 |
+
file_path_output = 'data/output.mp4'
|
36 |
+
save_video(y, threshold=0, file_path=file_path_output)
|
37 |
+
|
38 |
+
ypred = make_predictions(X)
|
39 |
+
|
40 |
+
file_path_predict = 'data/predict.mp4'
|
41 |
+
save_video(ypred, threshold=0.1, file_path=file_path_predict)
|
42 |
+
|
43 |
+
return [file_path_input, file_path_output, file_path_predict]
|
44 |
+
|
45 |
+
demo = gr.Interface(
|
46 |
+
fn=predict,
|
47 |
+
inputs=[
|
48 |
+
gr.Video(label="Source", visible=False),
|
49 |
+
gr.Text(label='Date'),
|
50 |
+
gr.Text(label='Start'),
|
51 |
+
gr.Text(label='End')
|
52 |
+
],
|
53 |
+
outputs=[
|
54 |
+
gr.Video(label='Input'),
|
55 |
+
gr.Video(label='Output'),
|
56 |
+
gr.Video(label='Prediction')
|
57 |
+
],
|
58 |
+
examples=examples
|
59 |
+
)
|
60 |
+
|
61 |
+
if __name__ == "__main__":
|
62 |
+
demo.launch()
|