# import library import streamlit as st import pandas as pd import numpy as np import pickle import json # Load Model with open('model.pkl', 'rb') as file: model = pickle.load(file) with open('feature.txt', 'r') as file: feature = json.load(file) # Function to run streamlit model predictor def run(): # Set Title st.title("Predict the Price Range of a Mobile Based on its Features") st.markdown('---') # Create a Form for Data Inference st.markdown('## Input Data') with st.form('my_form'): battery_power = st.number_input('Battery Power', min_value=500, max_value=8000) blue = st.selectbox('Has bluetooth or not? 0 = No, Yes = 1', (0,1)) clock_speed = st.number_input('Clock Speed (Speed at Wich Microprocessor Execute Instruction)', min_value=0.5, max_value=3.0) dual_sim = st.selectbox('Has dual sim or not? 0 = No, Yes = 1', (0,1)) fc = st.number_input('Front Camera mega pixels', min_value=0, max_value=40) four_g = st.selectbox('Has 4G or not? 0 = No, Yes = 1', (0,1)) int_memory = st.number_input('Internal Memory in Gigabytes', min_value=2, max_value=256) m_dep = st.number_input('Mobile Depth in cm', min_value=0.1, max_value=1.0) mobile_wt = st.number_input('Weight of Mobilephone', min_value=80, max_value=300) n_cores = st.number_input('Number of Cores of Processor', min_value=1, max_value=10) pc = st.number_input('Primary Camera mega pixels', min_value=0, max_value=20) px_height = st.number_input('Pixel Resolution Height', min_value=0, max_value=2000) px_width = st.number_input('Pixel Resolution Width', min_value=500, max_value=2000) ram = st.number_input('RAM in Megabytes', min_value=256, max_value=4000) sc_h = st.number_input('Screen Height of Mobile in cm', min_value=5, max_value=20) sc_w = st.number_input('Screen Width of Mobile in cm', min_value=1, max_value=15) talk_time = st.number_input('The Longest Time for one battery charge when you use it', min_value=2, max_value=168) three_g = st.selectbox('Has 3G or not? 0 = No, Yes = 1', (0,1)) touch_screen = st.selectbox('Has touch_screen or not? 0 = No, Yes = 1', (0,1)) wifi = st.selectbox('Has wifi or not? 0 = No, Yes = 1', (0,1)) # Create a button to make predictions submitted = st.form_submit_button("Predict") # Dataframe data = {'battery_power': battery_power, 'blue': blue, 'clock_speed': clock_speed, 'dual_sim': dual_sim, 'fc': fc, 'four_g': four_g, 'int_memory': int_memory, 'm_dep': m_dep, 'mobile_wt': mobile_wt, 'n_cores': n_cores, 'pc': pc, 'px_height': px_height, 'px_width': px_width, 'ram': ram, 'sc_h': sc_h, 'sc_w': sc_w, 'talk_time': talk_time, 'three_g': three_g, 'touch_screen': touch_screen, 'wifi': wifi} df = pd.DataFrame([data]) st.dataframe(df) if submitted: df_selected = df[feature] y_pred_inf = model.predict(df_selected) if y_pred_inf[0] == 0: st.subheader('~ The Mobile Features you Enter is in "Entry-Level" price ~') elif y_pred_inf[0] == 1: st.write('~ The Mobile Features you Enter is in "Mid-Range" price ~') elif y_pred_inf[0] == 2: st.write('~ The Mobile Features you Enter is in "High-End" price ~') elif y_pred_inf[0] == 3: st.write('~ The Mobile Features you Enter is in "Flagship" price ~') if __name__== '__main__': run()