Spaces:
Runtime error
Runtime error
File size: 3,712 Bytes
9ff6f28 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# 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() |