Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| input_module1 = gr.inputs.Slider(1, 100, step=5, label = "Longitude") | |
| input_module2 = gr.inputs.Slider(1, 100, step=5, label = "Latitude") | |
| input_module3 = gr.inputs.Slider(1, 100, step=5, label = "Housing_median_age (Year)") | |
| input_module4 = gr.inputs.Slider(1, 100, step=5, label = "Total_rooms") | |
| input_module5 = gr.inputs.Slider(1, 100, step=5, label = "Total_bedrooms") | |
| input_module6 = gr.inputs.Slider(1, 100, step=5, label = "Population") | |
| input_module7 = gr.inputs.Slider(1, 100, step=5, label = "Households") | |
| input_module8 = gr.inputs.Slider(1, 100, step=5, label = "Median_income") | |
| # Step 6.2: Define different output components | |
| # a. define text data type | |
| output_module1 = gr.outputs.Textbox(label = "Output Text") | |
| # b. define image data type | |
| output_module2 = gr.outputs.Image(label = "Output Image") | |
| # you can define more output components | |
| def machine_learning_pipeline(input1, input2, input3, input4, input5, input6, input7, input8): | |
| import numpy as np | |
| import pandas as pd | |
| new_feature = np.array([[input1, input2, input3, input4, input5, input6, input7, input8]]) | |
| test_set = pd.DataFrame(new_feature, columns = ['longitude', 'latitude', 'housing_median_age', 'total_rooms', | |
| 'total_bedrooms', 'population', 'households', 'median_income']) | |
| test_set_clean = test_set.dropna(subset=["total_bedrooms"]) | |
| import pickle | |
| with open('minmax_scaler.pkl', 'rb') as f: | |
| scaler = pickle.load(f) | |
| test_features_normalized = scaler.transform(test_set_clean) | |
| with open('tree_reg.pkl', 'rb') as f: | |
| tree_reg = pickle.load(f) | |
| test_predictions_trees = tree_reg.predict(test_features_normalized) | |
| import matplotlib.pyplot as plt | |
| plt.scatter([input1], [input2]) | |
| plt.savefig('scatterplot.png') | |
| return test_predictions_trees[0], 'scatterplot.png' | |
| gr.Interface(fn=machine_learning_pipeline, | |
| inputs = [input_module1, input_module2, input_module3, | |
| input_module4, input_module5, input_module6, | |
| input_module7, input_module8], | |
| outputs = [output_module1, output_module2]).launch(debug=True) | |