Spaces:
Build error
Build error
| 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() | |