alperugurcan commited on
Commit
4d362c6
·
verified ·
1 Parent(s): 38f4e30

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import joblib
3
+ import gradio as gr
4
+
5
+ # Load the model
6
+ model = joblib.load('forest_model.joblib')
7
+
8
+ def predict(elevation, horizontal_distance_to_roadways, horizontal_distance_to_fire_points,
9
+ horizontal_distance_to_hydrology, vertical_distance_to_hydrology):
10
+
11
+ # Create a DataFrame with all features (initialized to 0)
12
+ input_data = pd.DataFrame(0, index=[0], columns=model.feature_names_in_)
13
+
14
+ # Set the values for our important features
15
+ feature_values = {
16
+ 'Elevation': elevation,
17
+ 'Horizontal_Distance_To_Roadways': horizontal_distance_to_roadways,
18
+ 'Horizontal_Distance_To_Fire_Points': horizontal_distance_to_fire_points,
19
+ 'Horizontal_Distance_To_Hydrology': horizontal_distance_to_hydrology,
20
+ 'Vertical_Distance_To_Hydrology': vertical_distance_to_hydrology
21
+ }
22
+
23
+ for feature, value in feature_values.items():
24
+ input_data[feature] = value
25
+
26
+ # Make prediction
27
+ prediction = model.predict(input_data)[0]
28
+
29
+ forest_types = {
30
+ 1: "Spruce/Fir",
31
+ 2: "Lodgepole Pine",
32
+ 3: "Ponderosa Pine",
33
+ 4: "Cottonwood/Willow",
34
+ 5: "Aspen",
35
+ 6: "Douglas-fir",
36
+ 7: "Krummholz"
37
+ }
38
+
39
+ return forest_types[prediction]
40
+
41
+ # Create Gradio interface
42
+ inputs = [
43
+ gr.Number(label="Elevation (meters)", minimum=1800, maximum=4000),
44
+ gr.Number(label="Distance to Roadways (meters)", minimum=0, maximum=8000),
45
+ gr.Number(label="Distance to Fire Points (meters)", minimum=0, maximum=8000),
46
+ gr.Number(label="Distance to Hydrology (meters)", minimum=0, maximum=1000),
47
+ gr.Number(label="Vertical Distance to Hydrology (meters)", minimum=-500, maximum=500)
48
+ ]
49
+
50
+ output = gr.Text(label="Predicted Forest Cover Type")
51
+
52
+ interface = gr.Interface(
53
+ fn=predict,
54
+ inputs=inputs,
55
+ outputs=output,
56
+ title="Forest Cover Type Prediction",
57
+ description="Predict forest cover type using the most important environmental features.",
58
+ examples=[
59
+ [2596, 510, 6279, 258, 0] # Sample values for the top 5 features
60
+ ]
61
+ )
62
+
63
+ if __name__ == "__main__":
64
+ interface.launch()