-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
74 lines (62 loc) · 2.51 KB
/
app.py
File metadata and controls
74 lines (62 loc) · 2.51 KB
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
from flask import Flask, request, jsonify, render_template
import google.generativeai as genai
import datetime
import os
import re
import random
print("CURRENT FOLDER:", os.getcwd())
if os.path.exists('templates'):
print("'templates' folder FOUND!")
print("Files inside:", os.listdir('templates'))
else:
print("ERROR: 'templates' folder NOT FOUND. Did you name it 'template'?")
app = Flask(__name__)
MY_API_KEY = "PASTE_YOUR_GOOGLE_API_KEY_HERE"
genai.configure(api_key=MY_API_KEY)
history = []
@app.route('/', methods=['GET'])
def dashboard():
print("Loading the FINAL DASHBOARD...")
return render_template('finaldashboard.html', predictions=history)
@app.route('/predict', methods=['POST'])
def predict():
try:
data = request.json
brand = data.get('brand', 'Unknown')
model_name = data.get('model', 'Car')
year = int(data.get('year', 2024))
engine = float(data['engine'])
hp = float(data['hp'])
try:
model = genai.GenerativeModel('gemini-pro')
prompt = (
f"Estimate the market price in Indian Rupees (INR) for a used {year} {brand} {model_name}. "
f"Specs: {engine}L Engine, {hp} Horsepower. "
"Consider the specific model's luxury status and depreciation in India. "
"Return ONLY the numeric value (e.g. 1500000)."
)
response = model.generate_content(prompt)
text = response.text.strip()
print(f"AI Valuing: {year} {brand} {model_name} -> {text}")
match = re.search(r"[\d,]+", text)
if match:
final_price = float(match.group().replace(',', ''))
status = "success_ai"
else:
raise Exception("No number found")
except Exception:
base = (hp * 2500) + (engine * 200000)
if "mercedes" in brand.lower() or "bmw" in brand.lower():
base *= 1.5
final_price = max(100000, base)
status = "success_math"
history.insert(0, {
"time": datetime.datetime.now().strftime("%H:%M:%S"),
"car": f"{year} {brand} {model_name}",
"price": final_price
})
return jsonify({"estimated_price": final_price, "status": status})
except Exception as e:
return jsonify({"estimated_price": 0, "status": "error", "message": str(e)})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5001, debug=True)