Skip to content

Commit

Permalink
Merge pull request #29 from dncq/dev/model
Browse files Browse the repository at this point in the history
Dev/model
  • Loading branch information
dncq authored Dec 27, 2023
2 parents c1d2876 + be66649 commit 0eb1f3f
Show file tree
Hide file tree
Showing 11 changed files with 22,859 additions and 651 deletions.
1,373 changes: 1,373 additions & 0 deletions Data/processed/bhp_dataset.csv

Large diffs are not rendered by default.

9,206 changes: 9,206 additions & 0 deletions Data/processed/final_dataset.csv

Large diffs are not rendered by default.

Binary file added assets/knn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/knn0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/knn2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/knn3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 45 additions & 34 deletions src/app/app.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,57 @@
import streamlit as st

laptop_config = {
'Brand': ['Dell','Apple', 'Lenovo', 'HP', 'Asus', 'Acer', 'MSI', 'Microsoft', 'Other'],
'CPU': ['i5', 'i7', 'Ryzen 5', 'Ryzen 7'],
'RAM': ['8GB', '16GB', '32GB'],
'GPU': ['Integrated', 'NVIDIA GTX', 'NVIDIA RTX', 'AMD Radeon'],
'Storage': ['256GB SSD', '512GB SSD', '1TB HDD', '1TB SSD']
}

st.title('Laptop Price Prediction')

st.caption("#fromhelaricawithluv")

company = st.selectbox('Brand', laptop_config['Company'])
cpu = st.selectbox('CPU', laptop_config['CPU'])
# ram = st.selectbox('RAM', laptop_config['RAM'])

ram = st.select_slider("RAM", options=['4GB', '8GB', '12GB', '16GB', '32GB', '64GB'])
gpu = st.selectbox('GPU', laptop_config['GPU'])
storage = st.selectbox('Storage', laptop_config['Storage'])
def predict_price(brand="Apple", cpu="Intel Iris Xe", gpu="GeForce GTX 1650", monitor="15.6\"", screen_size="11920x1080", ram="8GB", storage="256GB", os="macOS", weight="1.78kg", model="RF"):
predicted = 195

return brand, cpu, gpu, monitor, screen_size, ram, storage, os, weight, model, predicted

def predict_price(company, cpu, ram, gpu, storage):
def main():
st.title("Laptop Price Prediction")
st.caption("Introduction to Data Science")

return 1500000000
brand = st.selectbox(label="Brand", options=["Apple", "Dell", "Lenovo", "Asus", "Acer", "HP", "Microsoft", "Other"])
os = st.selectbox(label="Operating System", options=["macOS", "Windows 11", "Windows 11 Home", "Windows 11 Pro", "Windows 10", "Chrome OS", "Other"])

cpu = st.text_input(label="CPU", placeholder="e.g. Intel Iris Xe..", value="Intel Iris Xe")
gpu = st.text_input(label="GPU", placeholder="e.g. GeForce GTX 1650..", value="GeForce GTX 1650")

if st.button('Prediction'):
predicted_price = predict_price(company, cpu, ram, gpu, storage)

st.success(f'{predicted_price} USD')
ram_input = st.text_input("Enter RAM value:", key="ram_input", placeholder="e.g. 8GB")

st.camera_input('Camera nek')
storage_input = st.text_input("Enter storage value:", key="storage_input", placeholder="e.g. 256GB")

st.download_button("Download Button", data="main.py")
st.code('''st.download_button("Download Button", data="str")
# data la string, khi download ve se thanh file txt chua doan string do''')
weight_input = st.text_input("Enter weight value:", key="weight_input", placeholder="e.g. 1.78kg")

with st.form("This is form"):
st.write("Ben trong form nek")
monitor_input = st.text_input("Enter monitor value:", key="monitor_input", placeholder="e.g. 15.6\"")

st.slider("Slider nek", 15, 20)

st.checkbox("Checkbox nek")
screen_size = st.text_input("Enter screen_size value:", key="screen_size_input", placeholder="e.g. 1920x1080")

# Display selected values
st.write("___")

selected_model = "RF"

if st.button('Submit'):
brand, cpu, gpu, monitor, screen_size, ram, storage, os, weight, model, predicted = predict_price(brand, cpu, gpu, monitor_input, screen_size, ram_input, storage_input, os, weight_input, selected_model)
st.success(f'{predicted} USD')

st.write("Features Summary:")
st.table({
"Brand": brand,
"CPU": cpu,
"GPU": gpu,
"RAM": ram,
"Storage": storage,
"Weight": weight,
"Monitor": monitor,
"Screen Size": screen_size,
"Operating System": os
})

st.write("___")

else:
st.success("")

st.form_submit_button("Submit")
if __name__ == '__main__':
main()
40 changes: 15 additions & 25 deletions src/app/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
import pandas as pd
from mapping import *

PARENT_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
PARENT_PATH = os.path.abspath(os.path.join(PARENT_PATH, '..'))
DATA_PATH = os.path.abspath(os.path.join(PARENT_PATH, "data", "raw", "cpu_gpu_mark"))

CPU_FILENAME = "cpu_mark.csv"
GPU_FILENAME = "gpu_mark.csv"

cpu_df = pd.read_csv(os.path.abspath(os.path.join(DATA_PATH, CPU_FILENAME)), index_col = 0)
gpu_df = pd.read_csv(os.path.abspath(os.path.join(DATA_PATH, GPU_FILENAME)), index_col = 0)

cpu_name_list = [cpu_df['CPU Name'][idx].lower() for idx in cpu_df.index]
gpu_name_list = [gpu_df['GPU Name'][idx].lower() for idx in gpu_df.index]

def predict(model_name: pk.Pickler,
brand: str,
cpu_name: str,
Expand All @@ -12,35 +25,12 @@ def predict(model_name: pk.Pickler,
storage: str,
os: str,
weight: str) -> float:

PARENT_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
PARENT_PATH = os.path.abspath(os.path.join(PARENT_PATH, '..'))
DATA_PATH = os.path.abspath(os.path.join(PARENT_PATH, "data", "raw", "cpu_gpu_mark"))

CPU_FILENAME = "cpu_mark.csv"
GPU_FILENAME = "gpu_mark.csv"

cpu_df = pd.read_csv(os.path.abspath(os.path.join(DATA_PATH, CPU_FILENAME)), index_col = 0)
gpu_df = pd.read_csv(os.path.abspath(os.path.join(DATA_PATH, GPU_FILENAME)), index_col = 0)

cpu_name_list = [cpu_df['CPU Name'][idx].lower() for idx in cpu_df.index]
gpu_name_list = [gpu_df['GPU Name'][idx].lower() for idx in gpu_df.index]

# Transform data to predict
name_cpu, cpu_mark = get_cpu_name(cpu_name)
name_gpu, gpu_mark = get_gpu_name(gpu_name)

# Monitor to Float
if "\"" in monitor or "\'" in monitor:
elements = monitor.split()
if len(elements) == 2:
pros_monitor, _ = elements[0], elements[1]
pros_monitor = float(pros_monitor[:-1])

if len(elements) == 1:
monitor = elements[0]
pros_monitor = float(pros_monitor[:-1])
else:
pros_monitor = float(monitor[:-1])
# Monitor size
width, height = [float(x.strip()) for x in monitor_size.split("x")]


Loading

0 comments on commit 0eb1f3f

Please sign in to comment.