File size: 1,680 Bytes
29661bc
84143cd
 
 
 
caaf51a
84143cd
caaf51a
 
84143cd
29661bc
84143cd
29661bc
 
 
 
84143cd
 
29661bc
84143cd
29661bc
 
 
 
 
 
 
 
caaf51a
29661bc
caaf51a
29661bc
 
 
 
84143cd
29661bc
 
 
 
84143cd
29661bc
 
caaf51a
29661bc
 
 
 
 
84143cd
29661bc
 
 
 
 
caaf51a
 
29661bc
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
import gradio as gr
import numpy as np
import joblib

# =========================
# Load model
# =========================
model = joblib.load("model.joblib")

# =========================
# Prediction function
# =========================
def predict_ev(year, make, model_code, ev_type, cafv, utility):
    X = np.array([[year, make, model_code, ev_type, cafv, utility]])
    prediction = model.predict(X)
    return f"🔍 Electric Range dự đoán: {prediction[0]:.2f} km"

# =========================
# Gradio Interface
# =========================
with gr.Blocks(title="EV Performance Prediction") as demo:
    gr.Markdown(
        """
        # 🔋 Electric Vehicle Performance Prediction
        **Dự báo hiệu suất kỹ thuật xe điện (Electric Range)**  
        ---
        """
    )

    gr.Markdown("### 📥 Nhập thông tin xe")

    with gr.Row():
        year = gr.Number(label="Model Year", value=2020)
        make = gr.Number(label="Make (encoded)", value=10)
        model_code = gr.Number(label="Model (encoded)", value=20)

    with gr.Row():
        ev_type = gr.Number(label="EV Type (encoded)", value=1)
        cafv = gr.Number(label="CAFV Eligibility (encoded)", value=0)
        utility = gr.Number(label="Electric Utility (encoded)", value=60)

    predict_btn = gr.Button("🚀 Dự báo hiệu suất")
    output = gr.Textbox(label="Kết quả dự báo")

    predict_btn.click(
        fn=predict_ev,
        inputs=[year, make, model_code, ev_type, cafv, utility],
        outputs=output
    )

    gr.Markdown(
        """
        ---
        *Student Research Project – Academic Year 2024–2025*
        """
    )

demo.launch()