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()