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 # Load Sequential Model model_cnn = load_model('car_model.h5') # Load DataFrame income_data = { 'pekerjaan': ["Staff - Fresh Graduate", "Asisten Manajer", "Manajer", "General Manajer", "Kepala Divisi atau Direksi"], 'rentang_usia': [(21, 25), (26, 29), (29, 35), (36, 42), (42, 100)], 'rentang_gaji': [(2000000, 4000000), (5000000, 8000000), (10000000, 15000000), (20000000, 30000000), (50000000, 100000000)] } data = { 'predicted_label': [0, 1, 2, 3], 'jenis_mobil': ["Alphard", "Innova 2015-2022", "Innova Zennix", "New Veloz"], 'merek_mobil': ["Toyota", "Toyota", "Toyota", "Toyota"], 'harga_mobil_min': [1356100000, 215000000, 425000000, 288000000], 'harga_mobil_max': [1950000000, 480000000, 610000000, 350000000]} # Create DataFrame df_car_info = pd.DataFrame(data) df_income_info = pd.DataFrame(income_data) 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 matching_income = df_income_info[ (cicilan_per_bulan / 0.3 >= df_income_info['rentang_gaji'].apply(lambda x: x[0])) & (cicilan_per_bulan / 0.3 <= df_income_info['rentang_gaji'].apply(lambda x: x[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()