Skip to content

Commit 2642d76

Browse files
authored
Create AutoValue_Pro.py
1 parent e589d35 commit 2642d76

1 file changed

Lines changed: 239 additions & 0 deletions

File tree

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
"""
2+
AutoValue Pro v1.0 - Enterprise Edition
3+
AI-Powered Car Price Prediction Tool
4+
Fast, Accurate & User-Friendly Desktop GUI
5+
"""
6+
7+
import os, sys, threading
8+
import tkinter as tk
9+
from tkinter import messagebox
10+
import ttkbootstrap as tb
11+
from ttkbootstrap.constants import *
12+
13+
import numpy as np
14+
from sklearn.linear_model import LinearRegression
15+
16+
17+
# ---------------------- UTIL ----------------------
18+
def resource_path(file_name):
19+
base_path = getattr(sys, "_MEIPASS", os.path.dirname(os.path.abspath(__file__)))
20+
return os.path.join(base_path, file_name)
21+
22+
23+
# ---------------------- ML WORKER ----------------------
24+
class PredictionWorker:
25+
def __init__(self, features, callbacks):
26+
self.features = features
27+
self.callbacks = callbacks
28+
self._running = True
29+
30+
# Dummy trained model (demo)
31+
self.model = LinearRegression()
32+
X = np.array([
33+
[1, 5000, 2015],
34+
[2, 3000, 2018],
35+
[3, 2000, 2020],
36+
[1, 8000, 2012],
37+
[2, 4000, 2016]
38+
])
39+
y = np.array([12000, 15000, 18000, 9000, 14000])
40+
self.model.fit(X, y)
41+
42+
def stop(self):
43+
self._running = False
44+
45+
def run(self):
46+
try:
47+
if "progress" in self.callbacks:
48+
self.callbacks
49+
50+
prediction = self.model.predict([self.features])[0]
51+
52+
if "progress" in self.callbacks:
53+
self.callbacks
54+
55+
if not self._running:
56+
return
57+
58+
if "result" in self.callbacks:
59+
self.callbacks["result"](round(prediction, 2))
60+
61+
except Exception as e:
62+
if "error" in self.callbacks:
63+
self.callbacks["error"](str(e))
64+
65+
if "progress" in self.callbacks:
66+
self.callbacks
67+
68+
69+
# ---------------------- MAIN APP ----------------------
70+
class AutoValueApp:
71+
APP_NAME = "AutoValue Pro"
72+
APP_VERSION = "1.0"
73+
74+
def __init__(self):
75+
self.root = tb.Window(themename="darkly")
76+
self.root.title(f"{self.APP_NAME} v{self.APP_VERSION}")
77+
self.root.minsize(900, 550)
78+
79+
try:
80+
self.root.iconbitmap(resource_path("logo.ico"))
81+
except:
82+
pass
83+
84+
self.worker = None
85+
self.target_progress = 0
86+
self.smooth_value = 0
87+
88+
self._build_ui()
89+
self._apply_styles()
90+
91+
# ---------------------- UI ----------------------
92+
def _build_ui(self):
93+
main = tb.Frame(self.root, padding=20)
94+
main.pack(fill=BOTH, expand=True)
95+
96+
tb.Label(
97+
main,
98+
text="🚗 AutoValue Pro – Car Price Predictor",
99+
font=("Segoe UI", 22, "bold")
100+
).pack(pady=(0, 6))
101+
102+
tb.Label(
103+
main,
104+
text="AI-Driven Used Car Price Estimation",
105+
font=("Segoe UI", 10, "italic"),
106+
foreground="#9ca3af"
107+
).pack(pady=(0, 25))
108+
109+
form = tb.Frame(main)
110+
form.pack(fill=X, pady=10)
111+
112+
# Inputs
113+
self.owner_var = tk.IntVar(value=1)
114+
self.km_var = tk.IntVar(value=3000)
115+
self.year_var = tk.IntVar(value=2018)
116+
117+
tb.Label(form, text="Number of Owners").grid(row=0, column=0, sticky=W, pady=6)
118+
tb.Spinbox(form, from_=1, to=5, textvariable=self.owner_var, width=10).grid(row=0, column=1, padx=10)
119+
120+
tb.Label(form, text="Kilometers Driven").grid(row=1, column=0, sticky=W, pady=6)
121+
tb.Entry(form, textvariable=self.km_var, width=15).grid(row=1, column=1, padx=10)
122+
123+
tb.Label(form, text="Manufacturing Year").grid(row=2, column=0, sticky=W, pady=6)
124+
tb.Entry(form, textvariable=self.year_var, width=15).grid(row=2, column=1, padx=10)
125+
126+
# Buttons
127+
btns = tb.Frame(main)
128+
btns.pack(pady=15)
129+
130+
self.predict_btn = tb.Button(
131+
btns, text="🔮 Predict Price", bootstyle=SUCCESS, command=self.start_prediction
132+
)
133+
self.predict_btn.pack(side=LEFT, padx=6)
134+
135+
self.cancel_btn = tb.Button(
136+
btns, text="⏹ Cancel", bootstyle=DANGER, command=self.cancel, state=DISABLED
137+
)
138+
self.cancel_btn.pack(side=LEFT, padx=6)
139+
140+
# Progress
141+
self.progress = tb.Progressbar(
142+
main, maximum=100, bootstyle="success-striped"
143+
)
144+
self.progress.pack(fill=X, pady=(20, 10))
145+
146+
# Result
147+
self.result_label = tb.Label(
148+
main,
149+
text="Predicted Price: —",
150+
font=("Segoe UI", 16, "bold"),
151+
foreground="#4ade80"
152+
)
153+
self.result_label.pack(pady=10)
154+
155+
self.root.after(15, self.animate_progress)
156+
157+
# ---------------------- Actions ----------------------
158+
def start_prediction(self):
159+
try:
160+
features = [
161+
self.owner_var.get(),
162+
self.km_var.get(),
163+
self.year_var.get()
164+
]
165+
except Exception:
166+
messagebox.showerror("Input Error", "Invalid input values")
167+
return
168+
169+
self.progress["value"] = 0
170+
self.target_progress = 0
171+
self.smooth_value = 0
172+
173+
self.predict_btn.config(state=DISABLED)
174+
self.cancel_btn.config(state=NORMAL)
175+
176+
threading.Thread(
177+
target=self._run_worker,
178+
args=(features,),
179+
daemon=True
180+
).start()
181+
182+
def _run_worker(self, features):
183+
self.worker = PredictionWorker(
184+
features,
185+
callbacks={
186+
"progress": self.set_target,
187+
"result": self.show_result,
188+
"error": self.show_error
189+
}
190+
)
191+
self.worker.run()
192+
193+
def show_result(self, price):
194+
self.result_label.config(text=f"Predicted Price: ${price:,}")
195+
self.finish()
196+
197+
def show_error(self, msg):
198+
messagebox.showerror("Prediction Error", msg)
199+
self.finish()
200+
201+
def cancel(self):
202+
if self.worker:
203+
self.worker.stop()
204+
self.finish()
205+
206+
def finish(self):
207+
self.predict_btn.config(state=NORMAL)
208+
self.cancel_btn.config(state=DISABLED)
209+
self.progress["value"] = 100
210+
211+
# ---------------------- Progress Animation ----------------------
212+
def set_target(self, v):
213+
self.target_progress = v
214+
215+
def animate_progress(self):
216+
if self.smooth_value < self.target_progress:
217+
self.smooth_value += 1
218+
self.progress["value"] = self.smooth_value
219+
self.root.after(15, self.animate_progress)
220+
221+
# ---------------------- Styles ----------------------
222+
def _apply_styles(self):
223+
style = tb.Style()
224+
style.configure(
225+
"TProgressbar",
226+
troughcolor="#1b1f3a",
227+
background="#22c55e",
228+
thickness=14
229+
)
230+
231+
# ---------------------- Run ----------------------
232+
def run(self):
233+
self.root.mainloop()
234+
235+
236+
# ---------------------- RUN ----------------------
237+
if __name__ == "__main__":
238+
app = AutoValueApp()
239+
app.run()

0 commit comments

Comments
 (0)