Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +60 -0
- model.pkl +3 -0
- requirements.txt +9 -0
app.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import joblib
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# Load mô hình đã huấn luyện
|
| 6 |
+
model = joblib.load("model/model.pkl")
|
| 7 |
+
|
| 8 |
+
# Map label -> thông tin loài hoa
|
| 9 |
+
class_info = {
|
| 10 |
+
0: {
|
| 11 |
+
"name": "Iris-setosa 🌱",
|
| 12 |
+
"description": "Iris-setosa là loài nhỏ nhất trong 3 loài, thường có cánh hoa ngắn và màu xanh tím.",
|
| 13 |
+
"image": "https://upload.wikimedia.org/wikipedia/commons/thumb/1/11/Iris_setosa_2.jpg/330px-Iris_setosa_2.jpg"
|
| 14 |
+
},
|
| 15 |
+
1: {
|
| 16 |
+
"name": "Iris-versicolor 🌷",
|
| 17 |
+
"description": "Iris-versicolor có màu sắc đa dạng và thường được tìm thấy ở vùng đất ngập nước.",
|
| 18 |
+
"image": "https://upload.wikimedia.org/wikipedia/commons/thumb/0/03/Verschiedenfarbige_Schwertlilie_%28Iris_versicolor%29-20200603-RM-100257.jpg/330px-Verschiedenfarbige_Schwertlilie_%28Iris_versicolor%29-20200603-RM-100257.jpg"
|
| 19 |
+
},
|
| 20 |
+
2: {
|
| 21 |
+
"name": "Iris-virginica 🌸",
|
| 22 |
+
"description": "Iris-virginica có kích thước lớn nhất và thường mọc ở bờ sông hoặc đầm lầy.",
|
| 23 |
+
"image": "https://upload.wikimedia.org/wikipedia/commons/thumb/f/f8/Iris_virginica_2.jpg/250px-Iris_virginica_2.jpg"
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
def predict(sepal_length, sepal_width, petal_length, petal_width):
|
| 28 |
+
X = np.array([[sepal_length, sepal_width, petal_length, petal_width]])
|
| 29 |
+
prediction = model.predict(X)[0]
|
| 30 |
+
info = class_info.get(prediction, {})
|
| 31 |
+
return (
|
| 32 |
+
info.get("name", "Không xác định"),
|
| 33 |
+
info.get("description", "Không có mô tả"),
|
| 34 |
+
info.get("image", "")
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# Giao diện hiện đại dùng Blocks
|
| 38 |
+
with gr.Blocks(title="🌸 Dự đoán Loài Hoa Iris") as demo:
|
| 39 |
+
gr.Markdown("## 🔍 Nhập thông số để dự đoán loài hoa Iris")
|
| 40 |
+
|
| 41 |
+
with gr.Row():
|
| 42 |
+
sepal_length = gr.Number(label="Sepal Length (cm)")
|
| 43 |
+
sepal_width = gr.Number(label="Sepal Width (cm)")
|
| 44 |
+
petal_length = gr.Number(label="Petal Length (cm)")
|
| 45 |
+
petal_width = gr.Number(label="Petal Width (cm)")
|
| 46 |
+
|
| 47 |
+
submit_btn = gr.Button("Dự đoán")
|
| 48 |
+
|
| 49 |
+
with gr.Column():
|
| 50 |
+
label_output = gr.Text(label="Tên loài")
|
| 51 |
+
desc_output = gr.Textbox(label="Thông tin loài", lines=2)
|
| 52 |
+
image_output = gr.Image(label="Ảnh minh họa")
|
| 53 |
+
|
| 54 |
+
submit_btn.click(fn=predict,
|
| 55 |
+
inputs=[sepal_length, sepal_width, petal_length, petal_width],
|
| 56 |
+
outputs=[label_output, desc_output, image_output])
|
| 57 |
+
|
| 58 |
+
# Chạy app
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
demo.launch()
|
model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b2cae641bde339f08a5b2533e01208a775a6334b8220323949ccf5fae3237e12
|
| 3 |
+
size 1327
|
requirements.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
dvc
|
| 2 |
+
scikit-learn
|
| 3 |
+
pandas
|
| 4 |
+
numpy
|
| 5 |
+
joblib
|
| 6 |
+
mlflow
|
| 7 |
+
watchdog
|
| 8 |
+
pyyaml
|
| 9 |
+
gradio
|