carlosgonzalezmartinez commited on
Commit
594eb60
·
verified ·
1 Parent(s): 476edf6

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +116 -0
  2. model.joblib +3 -0
  3. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import uuid
3
+ import joblib
4
+ import json
5
+
6
+ import gradio as gr
7
+ import pandas as pd
8
+
9
+ from huggingface_hub import CommitScheduler
10
+ from pathlib import Path
11
+
12
+ import pandas as pd
13
+ import numpy as np
14
+ import matplotlib.pyplot as plt
15
+ import seaborn as sns
16
+ from warnings import filterwarnings
17
+ filterwarnings('ignore')
18
+
19
+
20
+ log_file = Path("logs/") / f"data_{uuid.uuid4()}.json"
21
+ log_folder = log_file.parent
22
+
23
+ scheduler = CommitScheduler(
24
+ repo_id="machine-failure-logs",
25
+ repo_type="dataset",
26
+ folder_path=log_folder,
27
+ path_in_repo="data",
28
+ every=2
29
+ )
30
+
31
+ health_status_predictor = joblib.load('model.joblib')
32
+
33
+ Latitude = gr.Number(label='Latitude')
34
+ Longitude = gr.Number(label='Longitude')
35
+ DBH = gr.Number(label='DBH')
36
+ Tree_Height = gr.Number(label='Tree_Height')
37
+ Crown_Width_North_South = gr.Number(label='Crown_Width_North_South')
38
+ Crown_Width_East_West = gr.Number(label='Crown_Width_East_West')
39
+ Slope = gr.Number(label='Slope')
40
+ Elevation = gr.Number(label='Elevation')
41
+ Temperature = gr.Number(label='Temperature')
42
+ Humidity = gr.Number(label='Humidity')
43
+ Soil_TN = gr.Number(label='Soil_TN')
44
+ Soil_TP = gr.Number(label='Soil_TP')
45
+ Soil_AP = gr.Number(label='Soil_AP')
46
+ Soil_AN = gr.Number(label='Soil_AN')
47
+ Menhinick_Index = gr.Number(label='Menhinick_Index')
48
+ Gleason_Index = gr.Number(label='Gleason_Index')
49
+ Fire_Risk_Index = gr.Number(label='Fire_Risk_Index')
50
+
51
+ model_output = gr.Label(label="Health Status")
52
+
53
+ def predict_health_status(Latitude, Longitude, DBH, Tree_Height, Crown_Width_North_South, Crown_Width_East_West, Slope, Elevation, Temperature, Humidity, Soil_TN, Soil_TP, Soil_AP, Soil_AN, Menhinick_Index, Gleason_Index, Fire_Risk_Index):
54
+ sample = {
55
+ 'Latitude': Latitude,
56
+ 'Longitude': Longitude,
57
+ 'DBH': DBH,
58
+ 'Tree_Height': Tree_Height,
59
+ 'Crown_Width_North_South': Crown_Width_North_South,
60
+ 'Crown_Width_East_West': Crown_Width_East_West,
61
+ 'Slope': Slope,
62
+ 'Elevation': Elevation,
63
+ 'Temperature': Temperature,
64
+ 'Humidity': Humidity,
65
+ 'Soil_TN': Soil_TN,
66
+ 'Soil_TP': Soil_TP,
67
+ 'Soil_AP': Soil_AP,
68
+ 'Soil_AN': Soil_AN,
69
+ 'Menhinick_Index': Menhinick_Index,
70
+ 'Gleason_Index': Gleason_Index.
71
+ 'Fire_Risk_Index': Fire_Risk_Index
72
+
73
+ }
74
+ data_point = pd.DataFrame([sample])
75
+ prediction = health_status_predictor.predict(data_point).tolist()
76
+
77
+ with scheduler.lock:
78
+ with log_file.open("a") as f:
79
+ f.write(json.dumps(
80
+ {
81
+ 'Latitude': Latitude,
82
+ 'Longitude': Longitude,
83
+ 'DBH': DBH,
84
+ 'Tree_Height': Tree_Height,
85
+ 'Crown_Width_North_South': Crown_Width_North_South,
86
+ 'Crown_Width_East_West': Crown_Width_East_West,
87
+ 'Slope': Slope,
88
+ 'Elevation': Elevation,
89
+ 'Temperature': Temperature,
90
+ 'Humidity': Humidity,
91
+ 'Soil_TN': Soil_TN,
92
+ 'Soil_TP': Soil_TP,
93
+ 'Soil_AP': Soil_AP,
94
+ 'Soil_AN': Soil_AN,
95
+ 'Menhinick_Index': Menhinick_Index,
96
+ 'Gleason_Index': Gleason_Index,
97
+ 'Fire_Risk_Index': Fire_Risk_Index,
98
+ 'prediction': prediction[0]
99
+ }
100
+ ))
101
+ f.write("\n")
102
+
103
+ return prediction[0]
104
+
105
+ demo = gr.Interface(
106
+ fn=predict_health_status,
107
+ inputs=[Latitude, Longitude, DBH, Tree_Height, Crown_Width_North_South, Crown_Width_East_West, Slope, Elevation, Temperature, Humidity, Soil_TN, Soil_TP, Soil_AP, Soil_AN, Menhinick_Index, Gleason_Index, Fire_Risk_Index],
108
+ outputs=model_output,
109
+ title="Health Status Predictor",
110
+ description="This API allows you to predict the health status of a Tree",
111
+ allow_flagging="auto",
112
+ concurrency_limit=8
113
+ )
114
+
115
+ demo.queue()
116
+ demo.launch(share=False)
model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cd88a95d898fdfeaa52814163167680b1069d479b399777f32c33fb800a9e6c2
3
+ size 4550
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ scikit-learn==1.2.2