Skip to content

Commit e007989

Browse files
authored
Create LaptopPricePredictor.py
1 parent 47df9fa commit e007989

1 file changed

Lines changed: 114 additions & 0 deletions

File tree

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
"""
2+
LaptopPricePredictor v1.0 - Desktop Edition
3+
Predict laptop prices based on specs in a simple UI
4+
Supports CPU, RAM, GPU, storage, and brand selection
5+
"""
6+
7+
import tkinter as tk
8+
from tkinter import messagebox
9+
import ttkbootstrap as tb
10+
from ttkbootstrap.constants import *
11+
12+
# ---------------------- MOCK MODEL ----------------------
13+
# Replace this with a real ML model later
14+
def predict_price(specs):
15+
base_price = 300
16+
cpu_factor = {"i3": 100, "i5": 200, "i7": 350, "Ryzen 3": 90, "Ryzen 5": 180, "Ryzen 7": 320}
17+
ram_factor = {4: 50, 8: 100, 16: 200, 32: 350}
18+
storage_factor = {"HDD": 50, "SSD": 150, "Hybrid": 100}
19+
gpu_factor = {"Integrated": 0, "GTX 1650": 200, "RTX 3050": 350, "RTX 4070": 600}
20+
brand_factor = {"Dell": 100, "HP": 80, "Lenovo": 70, "Asus": 90, "Apple": 400}
21+
22+
price = base_price
23+
price += cpu_factor.get(specs["CPU"], 0)
24+
price += ram_factor.get(specs["RAM"], 0)
25+
price += storage_factor.get(specs["Storage"], 0)
26+
price += gpu_factor.get(specs["GPU"], 0)
27+
price += brand_factor.get(specs["Brand"], 0)
28+
return price
29+
30+
# ---------------------- MAIN APP ----------------------
31+
class LaptopPriceApp:
32+
APP_NAME = "LaptopPricePredictor"
33+
APP_VERSION = "1.0"
34+
35+
def __init__(self):
36+
self.root = tb.Window(themename="darkly")
37+
self.root.title(f"{self.APP_NAME} v{self.APP_VERSION}")
38+
self.root.geometry("600x550")
39+
40+
self._build_ui()
41+
self._apply_styles()
42+
43+
# ---------------------- UI ----------------------
44+
def _build_ui(self):
45+
main = tb.Frame(self.root, padding=20)
46+
main.pack(fill=tk.BOTH, expand=True)
47+
48+
tb.Label(main, text="💻 Laptop Price Predictor", font=("Segoe UI", 20, "bold")).pack(pady=(0,10))
49+
tb.Label(main, text="Enter your laptop specs below:", font=("Segoe UI", 10, "italic"), foreground="#9ca3af").pack(pady=(0,20))
50+
51+
# Brand
52+
tb.Label(main, text="Brand").pack(anchor=W)
53+
self.brand_combo = tb.Combobox(main, values=["Dell","HP","Lenovo","Asus","Apple"])
54+
self.brand_combo.pack(fill=X, pady=(0,10))
55+
self.brand_combo.set("Dell")
56+
57+
# CPU
58+
tb.Label(main, text="CPU").pack(anchor=W)
59+
self.cpu_combo = tb.Combobox(main, values=["i3","i5","i7","Ryzen 3","Ryzen 5","Ryzen 7"])
60+
self.cpu_combo.pack(fill=X, pady=(0,10))
61+
self.cpu_combo.set("i5")
62+
63+
# RAM
64+
tb.Label(main, text="RAM (GB)").pack(anchor=W)
65+
self.ram_combo = tb.Combobox(main, values=[4,8,16,32])
66+
self.ram_combo.pack(fill=X, pady=(0,10))
67+
self.ram_combo.set(8)
68+
69+
# Storage
70+
tb.Label(main, text="Storage Type").pack(anchor=W)
71+
self.storage_combo = tb.Combobox(main, values=["HDD","SSD","Hybrid"])
72+
self.storage_combo.pack(fill=X, pady=(0,10))
73+
self.storage_combo.set("SSD")
74+
75+
# GPU
76+
tb.Label(main, text="GPU").pack(anchor=W)
77+
self.gpu_combo = tb.Combobox(main, values=["Integrated","GTX 1650","RTX 3050","RTX 4070"])
78+
self.gpu_combo.pack(fill=X, pady=(0,20))
79+
self.gpu_combo.set("Integrated")
80+
81+
# Predict button
82+
self.predict_btn = tb.Button(main, text="💰 Predict Price", bootstyle=SUCCESS, command=self.predict)
83+
self.predict_btn.pack(pady=(0,10))
84+
85+
# Result label
86+
self.result_label = tb.Label(main, text="", font=("Segoe UI", 16, "bold"))
87+
self.result_label.pack(pady=(10,0))
88+
89+
# ---------------------- Actions ----------------------
90+
def predict(self):
91+
specs = {
92+
"Brand": self.brand_combo.get(),
93+
"CPU": self.cpu_combo.get(),
94+
"RAM": int(self.ram_combo.get()),
95+
"Storage": self.storage_combo.get(),
96+
"GPU": self.gpu_combo.get()
97+
}
98+
price = predict_price(specs)
99+
self.result_label.config(text=f"Estimated Price: ${price}")
100+
101+
# ---------------------- Styles ----------------------
102+
def _apply_styles(self):
103+
104+
self.root.style.configure("TButton", font=("Segoe UI", 12))
105+
106+
# ---------------------- Run ----------------------
107+
def run(self):
108+
self.root.mainloop()
109+
110+
111+
# ---------------------- RUN ----------------------
112+
if __name__ == "__main__":
113+
app = LaptopPriceApp()
114+
app.run()

0 commit comments

Comments
 (0)