File size: 3,012 Bytes
702f546
 
 
 
 
7110b0e
 
702f546
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7110b0e
702f546
fda53d7
 
 
702f546
35fece6
702f546
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2f91532
702f546
472fea6
 
206eb02
472fea6
 
 
206eb02
472fea6
 
 
25ad673
472fea6
 
25ad673
472fea6
de82577
25ad673
472fea6
 
 
 
 
 
702f546
 
 
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
75
76
77
78
79
80
81
82
83
84
85
import tensorflow as tf
from tensorflow.keras.models import load_model
import streamlit as st
from PIL import Image
import numpy as np
import pandas as pd
import ast

# Load Sequential Model
model_cnn = load_model('car_model.h5')

# Load DataFrame
df_car_info = pd.read_csv ('CarData.csv')
df_income_info = pd.read_csv ('SalaryData.csv')

def calculate_cicilan(predicted_label):
    # Get car info based on predicted_label
    car_info = df_car_info[df_car_info['predicted_label'] == predicted_label].iloc[0]

    # Calculate cicilan_per_bulan
    harga_mobil_avg = (car_info['harga_mobil_min'] + car_info['harga_mobil_max']) / 2
    cicilan_per_bulan = harga_mobil_avg / 60  # 5 tahun (60 bulan)

    # Find the matching gaji range based on cicilan_per_bulan
    df_income_info['rentang_gaji'] = df_income_info['rentang_gaji'].apply(lambda x: ast.literal_eval(x))
    matching_income = df_income_info[
    (cicilan_per_bulan / 0.3 >= df_income_info['rentang_gaji'].apply(lambda x: float(x.split('-')[0]))) &
    (cicilan_per_bulan / 0.3 <= df_income_info['rentang_gaji'].apply(lambda x: float(x.split('-')[1])))]



    if not matching_income.empty:
        rentang_usia = matching_income['rentang_usia'].iloc[0]
        rentang_gaji_min = int(matching_income['rentang_gaji'].iloc[0][0])
        rentang_gaji_max = int(matching_income['rentang_gaji'].iloc[0][1])
        pekerjaan = matching_income['pekerjaan'].iloc[0]

        return {
            'Jenis Mobil': car_info['jenis_mobil'],
            'Merek Mobil': car_info['merek_mobil'],
            'Rentang Usia': f"{rentang_usia[0]}-{rentang_usia[1]} Tahun",
            'Rentang Gaji': f"Rp {rentang_gaji_min} - {rentang_gaji_max}",
            'Pekerjaan': pekerjaan
        }

    else:
        return None

def run():
    st.title('Toyota Car Prediction')
    st.subheader('This Prediction use for provide passanger information from his car')
    st.subheader('Only Uploaded Image New Alphard, Innova 2015 - 2022, Innova Zennix, New Veloz')
    st.image("Yow.jpeg")
    st.markdown('---')
    
    st.subheader('Car Prediction')
    upload = st.file_uploader("Please upload an only Toyota Car image for prediction", type=["jpg"])
    
    if upload is not None:
        img = Image.open(upload)
        img = img.resize((224, 224)).convert("RGB")
        img_array = np.array(img)
        img_array = img_array / 255.0
        img_array = np.expand_dims(img_array, axis=0)
    
        # Model inference
        images = np.vstack([img_array])
        classes = model_cnn.predict(images)
    
        # Memilih label kelas
        predicted_label = np.argmax(classes)
    
        # Assuming df_car_info and df_income_info are available
        result = calculate_cicilan(predicted_label)
    
        st.write("Hasil Prediksi:")
        if result is not None:
            for key, value in result.items():
                st.write(f"{key}: {value}")
        else:
            st.write("Maaf, tidak ditemukan.")

if __name__ == '__main__':
    run()