Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -2,24 +2,14 @@ import gradio as gr
|
|
2 |
import pandas as pd
|
3 |
import joblib
|
4 |
|
|
|
5 |
df = pd.read_csv('data_summary.csv') # Pastikan file ada di direktori repo HF
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
"Gradient Boosting": "model_gb.joblib",
|
10 |
-
"SVR": "model_svr.joblib",
|
11 |
-
"Stack RF + GB": "stacking_rf_plus_gb.joblib",
|
12 |
-
"Stack RF + SVR": "stacking_rf_plus_svr.joblib",
|
13 |
-
"Stack GB + SVR": "stacking_gb_plus_svr.joblib",
|
14 |
-
"Stack RF + GB + SVR": "stacking_rf_plus_gb_plus_svr.joblib"
|
15 |
-
}
|
16 |
|
17 |
-
def prediksi_harga(
|
18 |
transmission, body_type, engine_capacity, seller_type):
|
19 |
-
try:
|
20 |
-
model = joblib.load(model_paths[model_choice])
|
21 |
-
except Exception as e:
|
22 |
-
return f"Gagal load model: {str(e)}"
|
23 |
input_df = pd.DataFrame([{
|
24 |
'brand': brand,
|
25 |
'model': model_input,
|
@@ -42,11 +32,10 @@ def get_unique(col):
|
|
42 |
return sorted(df[col].dropna().unique().tolist())
|
43 |
|
44 |
with gr.Blocks() as demo:
|
45 |
-
gr.Markdown("## π Prediksi Harga Mobil Bekas")
|
46 |
-
gr.Markdown("
|
47 |
with gr.Row():
|
48 |
with gr.Column():
|
49 |
-
model_choice = gr.Dropdown(choices=list(model_paths.keys()), label="Pilih Model", value="Random Forest")
|
50 |
brand = gr.Dropdown(choices=get_unique('brand'), label="Brand")
|
51 |
model_input = gr.Dropdown(choices=get_unique('model'), label="Model")
|
52 |
year = gr.Number(label="Tahun", value=2020, precision=0)
|
@@ -59,7 +48,9 @@ with gr.Blocks() as demo:
|
|
59 |
predict_button = gr.Button("π Prediksi Harga")
|
60 |
with gr.Column():
|
61 |
output = gr.Textbox(label="Hasil Prediksi Harga", lines=2)
|
62 |
-
predict_button.click(fn=prediksi_harga, inputs=[
|
63 |
-
|
|
|
|
|
64 |
|
65 |
-
demo.launch()
|
|
|
2 |
import pandas as pd
|
3 |
import joblib
|
4 |
|
5 |
+
# Load dataset referensi
|
6 |
df = pd.read_csv('data_summary.csv') # Pastikan file ada di direktori repo HF
|
7 |
|
8 |
+
# Load model Random Forest
|
9 |
+
model = joblib.load("model_rf.joblib")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
def prediksi_harga(brand, model_input, year, mileage, fuel_type,
|
12 |
transmission, body_type, engine_capacity, seller_type):
|
|
|
|
|
|
|
|
|
13 |
input_df = pd.DataFrame([{
|
14 |
'brand': brand,
|
15 |
'model': model_input,
|
|
|
32 |
return sorted(df[col].dropna().unique().tolist())
|
33 |
|
34 |
with gr.Blocks() as demo:
|
35 |
+
gr.Markdown("## π Prediksi Harga Mobil Bekas (Random Forest)")
|
36 |
+
gr.Markdown("Isi informasi mobil untuk memprediksi harga jual.")
|
37 |
with gr.Row():
|
38 |
with gr.Column():
|
|
|
39 |
brand = gr.Dropdown(choices=get_unique('brand'), label="Brand")
|
40 |
model_input = gr.Dropdown(choices=get_unique('model'), label="Model")
|
41 |
year = gr.Number(label="Tahun", value=2020, precision=0)
|
|
|
48 |
predict_button = gr.Button("π Prediksi Harga")
|
49 |
with gr.Column():
|
50 |
output = gr.Textbox(label="Hasil Prediksi Harga", lines=2)
|
51 |
+
predict_button.click(fn=prediksi_harga, inputs=[
|
52 |
+
brand, model_input, year, mileage, fuel_type,
|
53 |
+
transmission, body_type, engine_capacity, seller_type
|
54 |
+
], outputs=output)
|
55 |
|
56 |
+
demo.launch()
|