UdayPrasad commited on
Commit
529d50f
·
1 Parent(s): 2e8e8f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py CHANGED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ input_module1 = gr.inputs.Slider(1, 100, step=5, label = "Longitude")
4
+ input_module2 = gr.inputs.Slider(1, 100, step=5, label = "Latitude")
5
+ input_module3 = gr.inputs.Slider(1, 100, step=5, label = "Housing_median_age (Year)")
6
+ input_module4 = gr.inputs.Slider(1, 100, step=5, label = "Total_rooms")
7
+ input_module5 = gr.inputs.Slider(1, 100, step=5, label = "Total_bedrooms")
8
+ input_module6 = gr.inputs.Slider(1, 100, step=5, label = "Population")
9
+ input_module7 = gr.inputs.Slider(1, 100, step=5, label = "Households")
10
+ input_module8 = gr.inputs.Slider(1, 100, step=5, label = "Median_income")
11
+
12
+ # Step 6.2: Define different output components
13
+ # a. define text data type
14
+ output_module1 = gr.outputs.Textbox(label = "Output Text")
15
+
16
+ # b. define image data type
17
+ output_module2 = gr.outputs.Image(label = "Output Image")
18
+
19
+ # you can define more output components
20
+
21
+ def machine_learning_pipeline(input1, input2, input3, input4, input5, input6, input7, input8):
22
+ import numpy as np
23
+ import pandas as pd
24
+ new_feature = np.array([[input1, input2, input3, input4, input5, input6, input7, input8]])
25
+ test_set = pd.DataFrame(new_feature, columns = ['longitude', 'latitude', 'housing_median_age', 'total_rooms',
26
+ 'total_bedrooms', 'population', 'households', 'median_income'])
27
+ test_set_clean = test_set.dropna(subset=["total_bedrooms"])
28
+ import pickle
29
+ with open('minmax_scaler.pkl', 'rb') as f:
30
+ scaler = pickle.load(f)
31
+ test_features_normalized = scaler.transform(test_set_clean)
32
+ with open('tree_reg.pkl', 'rb') as f:
33
+ tree_reg = pickle.load(f)
34
+ test_predictions_trees = tree_reg.predict(test_features_normalized)
35
+ import matplotlib.pyplot as plt
36
+ plt.scatter([input1], [input2])
37
+ plt.savefig('scatterplot.png')
38
+ return test_predictions_trees[0], 'scatterplot.png'
39
+
40
+ gr.Interface(fn=machine_learning_pipeline,
41
+ inputs = [input_module1, input_module2, input_module3,
42
+ input_module4, input_module5, input_module6,
43
+ input_module7, input_module8],
44
+ outputs = [output_module1, output_module2]).launch(debug=True)
45
+