Upload folder using huggingface_hub
Browse files- app.py +37 -66
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import
|
| 2 |
import numpy as np
|
| 3 |
import joblib
|
| 4 |
|
|
@@ -8,80 +8,51 @@ import joblib
|
|
| 8 |
model = joblib.load("model.joblib")
|
| 9 |
|
| 10 |
# =========================
|
| 11 |
-
#
|
| 12 |
# =========================
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
)
|
| 18 |
-
|
| 19 |
-
# =========================
|
| 20 |
-
# Header
|
| 21 |
-
# =========================
|
| 22 |
-
st.markdown(
|
| 23 |
-
"""
|
| 24 |
-
<h1 style='text-align: center;'>🔋 Electric Vehicle Performance Prediction</h1>
|
| 25 |
-
<p style='text-align: center; font-size:18px;'>
|
| 26 |
-
Dự báo hiệu suất kỹ thuật xe điện (Electric Range)
|
| 27 |
-
</p>
|
| 28 |
-
<hr>
|
| 29 |
-
""",
|
| 30 |
-
unsafe_allow_html=True
|
| 31 |
-
)
|
| 32 |
-
|
| 33 |
-
# =========================
|
| 34 |
-
# Sidebar (thầy cô rất thích)
|
| 35 |
-
# =========================
|
| 36 |
-
st.sidebar.header("📌 Thông tin mô hình")
|
| 37 |
-
st.sidebar.markdown(
|
| 38 |
-
"""
|
| 39 |
-
- **Bài toán**: Hồi quy (Regression)
|
| 40 |
-
- **Thuật toán**: XGBoost
|
| 41 |
-
- **Đầu ra**: Electric Range
|
| 42 |
-
- **Triển khai**: Hugging Face
|
| 43 |
-
"""
|
| 44 |
-
)
|
| 45 |
|
| 46 |
# =========================
|
| 47 |
-
#
|
| 48 |
# =========================
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
|
| 52 |
|
| 53 |
-
with
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
|
| 58 |
-
with
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
# =========================
|
| 66 |
-
st.markdown("<br>", unsafe_allow_html=True)
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
| 74 |
)
|
| 75 |
|
| 76 |
-
|
| 77 |
-
# Footer
|
| 78 |
-
# =========================
|
| 79 |
-
st.markdown(
|
| 80 |
-
"""
|
| 81 |
-
<hr>
|
| 82 |
-
<p style='text-align: center; font-size:14px;'>
|
| 83 |
-
Student Research Project – Academic Year 2024–2025
|
| 84 |
-
</p>
|
| 85 |
-
""",
|
| 86 |
-
unsafe_allow_html=True
|
| 87 |
-
)
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
import joblib
|
| 4 |
|
|
|
|
| 8 |
model = joblib.load("model.joblib")
|
| 9 |
|
| 10 |
# =========================
|
| 11 |
+
# Prediction function
|
| 12 |
# =========================
|
| 13 |
+
def predict_ev(year, make, model_code, ev_type, cafv, utility):
|
| 14 |
+
X = np.array([[year, make, model_code, ev_type, cafv, utility]])
|
| 15 |
+
prediction = model.predict(X)
|
| 16 |
+
return f"🔍 Electric Range dự đoán: {prediction[0]:.2f} km"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# =========================
|
| 19 |
+
# Gradio Interface
|
| 20 |
# =========================
|
| 21 |
+
with gr.Blocks(title="EV Performance Prediction") as demo:
|
| 22 |
+
gr.Markdown(
|
| 23 |
+
"""
|
| 24 |
+
# 🔋 Electric Vehicle Performance Prediction
|
| 25 |
+
**Dự báo hiệu suất kỹ thuật xe điện (Electric Range)**
|
| 26 |
+
---
|
| 27 |
+
"""
|
| 28 |
+
)
|
| 29 |
|
| 30 |
+
gr.Markdown("### 📥 Nhập thông tin xe")
|
| 31 |
|
| 32 |
+
with gr.Row():
|
| 33 |
+
year = gr.Number(label="Model Year", value=2020)
|
| 34 |
+
make = gr.Number(label="Make (encoded)", value=10)
|
| 35 |
+
model_code = gr.Number(label="Model (encoded)", value=20)
|
| 36 |
|
| 37 |
+
with gr.Row():
|
| 38 |
+
ev_type = gr.Number(label="EV Type (encoded)", value=1)
|
| 39 |
+
cafv = gr.Number(label="CAFV Eligibility (encoded)", value=0)
|
| 40 |
+
utility = gr.Number(label="Electric Utility (encoded)", value=60)
|
| 41 |
|
| 42 |
+
predict_btn = gr.Button("🚀 Dự báo hiệu suất")
|
| 43 |
+
output = gr.Textbox(label="Kết quả dự báo")
|
|
|
|
|
|
|
| 44 |
|
| 45 |
+
predict_btn.click(
|
| 46 |
+
fn=predict_ev,
|
| 47 |
+
inputs=[year, make, model_code, ev_type, cafv, utility],
|
| 48 |
+
outputs=output
|
| 49 |
+
)
|
| 50 |
|
| 51 |
+
gr.Markdown(
|
| 52 |
+
"""
|
| 53 |
+
---
|
| 54 |
+
*Student Research Project – Academic Year 2024–2025*
|
| 55 |
+
"""
|
| 56 |
)
|
| 57 |
|
| 58 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -2,4 +2,4 @@ scikit-learn
|
|
| 2 |
xgboost
|
| 3 |
joblib
|
| 4 |
numpy
|
| 5 |
-
|
|
|
|
| 2 |
xgboost
|
| 3 |
joblib
|
| 4 |
numpy
|
| 5 |
+
gardio
|