CoolFace
Apppublic

sai07/Tech-Price-Analyzer

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
app.py261 linesDownload Raw Back to root
1import streamlit as st2import pickle3import pandas as pd4import numpy as np5import requests6from streamlit_lottie import st_lottie7 8st.set_page_config(page_title="My Webpage",page_icon="🤵")9 10def load_lottieurl(url):11    r = requests.get(url)12    if r.status_code!=200:13        return None14    return r.json()15lottie_coding = load_lottieurl("https://lottie.host/c9e78571-886e-4a40-9285-d22e6422ee48/iXVZeU57Ej.json"16)17 18lottie_coding1 = load_lottieurl("https://lottie.host/e3101877-8ed2-4ea4-8780-d7835de800f4/cn3ZqmjzSD.json"19)20 21 22# for laptop we use the model is randomforest r2_score:-89%23def Laptop():24    pipe = pickle.load(open('pipe.pkl','rb'))25 26    df = pickle.load(open('df.pkl','rb'))27 28    st.title('Laptop Price Predictor')29 30    # brand31    company = st.selectbox("Brand",df['Company'].unique())32 33    # type of laptop34    type = st.selectbox("Type",df['TypeName'].unique())35 36    # ram37    ram = st.selectbox("RAM(in GB)",[2,4,6,8,12,16,24,32,64])38 39    # weight40    weight = st.number_input('Weight of the Laptop')41 42    # touchscreen43    touchscreen = st.selectbox("TouchScreen",['No','Yes'])44 45    # IPS46    ips = st.selectbox('IPS',['No','Yes'])47 48    # screen size49    screen_size = st.number_input("Screen Size")50 51    # resolution52    resolution = st.selectbox('Screen Resolution',['1920x1080','1366x768','1600x900','3840x2160','3200x1800','2880x1800','2560x1600','2560x1440','2304x1440'])53 54    #cpu55    cpu = st.selectbox('CPU',df['Cpu brand'].unique())56 57    hdd = st.selectbox('HDD(in GB)',[0,128,256,512,1024,2048])58 59    ssd = st.selectbox('SSD(in GB)',[0,8,128,256,512,1024])60 61    gpu = st.selectbox('GPU',df['Gpu brand'].unique())62 63    os = st.selectbox('OS',df['os'].unique())64 65    if st.button('Predict Price'):66        # query67        ppi = None68        if touchscreen == 'Yes':69            touchscreen = 170        else:71            touchscreen = 072 73        if ips == 'Yes':74            ips = 175        else:76            ips = 077 78        X_res = int(resolution.split('x')[0])79        Y_res = int(resolution.split('x')[1])80        ppi = ((X_res**2) + (Y_res**2))**0.5/screen_size81        query = np.array([company,type,ram,weight,touchscreen,ips,ppi,cpu,hdd,ssd,gpu,os])82 83        query = query.reshape(1,12)84        st.title("The predicted price of this configuration is " + str(int(np.exp(pipe.predict(query)[0]))))85 86        # st.markdown('<b><font color="orange" size="30">The predicted price of this configuration is: </font></b>', unsafe_allow_html=True)87 88        # st.title(str(int(np.exp(pipe.predict(query)[0]))))89 90 91def Mobile():92        pipe = pickle.load(open('pipe8.pkl','rb'))93 94        df = pickle.load(open('X_train.pkl','rb'))95 96        st.title('Mobile Price Predictor')97 98        # ['mobile_color', 'disp_size', 'os', 'num_cores', 'mp_speed',99        #        'int_memory', 'ram', 'battery_power', 'mob_width', 'mob_height',100        #        'mob_depth', 'mob_weight', 'res_dim_1', 'res_dim_2', 'p_cam_max',101        #        'p_cam_count', 'f_cam_max', 'f_cam_count', '2G', '3G', '4G', '4GVOLTE',102        #        '5G']103 104        # mobile color105        color = st.selectbox("Color",df['mobile_color'].unique())106 107        # disp_size108        disp_size = st.number_input('Display Size(in inches)')109 110        # os111        os = st.selectbox("Operating System",sorted(df['os'].unique()))112 113        # num_cores114        num_cores = st.selectbox("No.of Cores",sorted(df['num_cores'].unique()))115 116        # speed of cpu117        mp_speed = disp_size = st.number_input('processor speed',help='2GHz processor')118 119        # memory120        int_memory = st.selectbox("Internal Memory",sorted(df['int_memory'].unique()))121 122        # ram123        ram = st.selectbox("RAM",sorted(df['ram'].unique(),reverse=True))124 125        # battery_power126        battery_power = st.selectbox("Battery",sorted(df['battery_power'].unique(),reverse=True))127 128 129        # mob_width130        mob_width = st.number_input('Mobile Width(mm)')131 132        # mob_height133        mob_height = st.number_input('Mobile Height(mm)')134 135        # mob_depth136        mob_depth = st.number_input('Mobile Depth(mm)')137 138        # mob_weight139        mob_weight = st.number_input('Mobile Weight')140        141        # resolution142        resolution = st.text_input("Enter Resulution")143 144        # p_cam_max145        p_cam_max = st.selectbox("Max rear camera",sorted(df['p_cam_max'].unique(),reverse=True),help='Primay Max camera')146 147        # p_cam_count148        p_cam_count = st.selectbox("Count of rear cameras",sorted(df['p_cam_count'].unique()))149 150        # f_cam_max151        f_cam_max = st.selectbox("Max front camera",sorted(df['f_cam_max'].unique()),help='Secondary Max camera')152 153        # f_cam_count154        f_cam_count = st.selectbox("Toatl no. of front cameras",[1,2],help='total no.of cameras including max camera')155 156        # Network157        network_choices = {158        "2G": df['2G'].unique(),159        "3G": df['3G'].unique(),160        "4G": df['4G'].unique(),161        "4GVOLTE": df['4GVOLTE'].unique(),162        "5G": df['5G'].unique()163        }164 165        selected_network = st.selectbox("Select Network", network_choices.keys())166        # selected_value = 1167        if selected_network == '2G':168                G2 = 1169                G3 = 0170                G4 = 0171                G4VOLTE = 0172                G5 = 0173        elif selected_network == '3G':174                G2 = 0175                G3 = 1176                G4 = 0177                G4VOLTE = 0178                G5 = 0179        elif selected_network == '4G':180                G2 = 0181                G3 = 0182                G4 = 1183                G4VOLTE = 0184                G5 = 0185        elif selected_network == '4GVOLTE':186                G2 = 0187                G3 = 0188                G4 = 0189                G4VOLTE = 1190                G5 = 0191        else:192                G2 = 0193                G3 = 0194                G4 = 0195                G4VOLTE = 0196                G5 = 1197                198 199        # 'mobile_color', 'dual_sim', 'disp_size', 'os', 'num_cores', 'mp_speed',200        #        'int_memory', 'ram', 'battery_power', 'mob_width', 'mob_height',201        #        'mob_depth', 'mob_weight', 'res_dim_1', 'res_dim_2', 'p_cam_max',202        #        'p_cam_count', 'f_cam_max', 'f_cam_count', '2G', '3G', '4G', '4GVOLTE',203        #        '5G'204        if st.button('Predict Mobile Price'):205                res_dim_1 = int(resolution.split('x')[0])206                res_dim_2 = int(resolution.split('x')[1])207 208 209                query = np.array([color,disp_size,os,num_cores,mp_speed,int_memory,ram,battery_power,mob_width,mob_height,mob_depth,mob_weight,res_dim_1,res_dim_2,p_cam_max,p_cam_count,f_cam_max,f_cam_count,G2,G3,G4,G4VOLTE,G5])210 211                query = query.reshape(1,23)212                213                st.title("The predicted price of this configuration is " + str(int(pipe.predict(query)[0])))214 215# pip install pandas==1.5.3216 217 218 219# Define two buttons with unique keys220with st.container():221    left,right = st.columns(2)222    with left:223        button_clicked1 = st.button("Click For Mobile Price Predictor!📱", key="button1")224        st_lottie(lottie_coding1,height=200,key='Laptop')225        button_clicked2 = st.button("Click For Laptop Price Predictor!💻", key="button2")226    with right:227        st_lottie(lottie_coding,height=200,key='Mobile')228 229 230 231# Use a session state to track whether each button has been clicked232if 'button1_click_state' not in st.session_state:233    st.session_state.button1_click_state = False234 235if 'button2_click_state' not in st.session_state:236    st.session_state.button2_click_state = False237 238# Check if each button was clicked239if button_clicked1:240    st.session_state.button1_click_state = True241    st.session_state.button2_click_state = False242 243if button_clicked2:244    st.session_state.button2_click_state = True245    st.session_state.button1_click_state = False246 247# Display content based on button clicks248if st.session_state.button1_click_state:249    # Clear previous content250    st.empty()251    # Display con252    # tent for the first button253    Mobile()254 255if st.session_state.button2_click_state:256    # Clear previous content257    st.empty()258    # Display content for the second button259    Laptop()260 261