Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- app.py +102 -0
- feature_names.pkl +3 -0
- random_forest_model.pkl +3 -0
- requirements.txt +7 -0
- scaler.pkl +3 -0
app.py
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import numpy as np
|
3 |
+
import gradio as gr
|
4 |
+
import joblib
|
5 |
+
from datetime import datetime
|
6 |
+
|
7 |
+
# Load model, scaler, dan feature names
|
8 |
+
model = joblib.load('random_forest_model.pkl')
|
9 |
+
scaler = joblib.load('scaler.pkl')
|
10 |
+
feature_names = joblib.load('feature_names.pkl')['feature_names']
|
11 |
+
|
12 |
+
def predict_task_priority(task_name, duration, deadline_str):
|
13 |
+
try:
|
14 |
+
# Parse deadline string to calculate days
|
15 |
+
start_date = datetime.now()
|
16 |
+
try:
|
17 |
+
deadline = datetime.strptime(deadline_str, '%Y-%m-%d')
|
18 |
+
except:
|
19 |
+
return "Error: Format tanggal harus YYYY-MM-DD (contoh: 2024-12-31)"
|
20 |
+
|
21 |
+
deadline_days = (deadline - start_date).days
|
22 |
+
|
23 |
+
if deadline_days < 0:
|
24 |
+
return "Error: Deadline tidak boleh di masa lalu"
|
25 |
+
|
26 |
+
# Buat DataFrame dengan feature names yang sesuai
|
27 |
+
input_data = pd.DataFrame({
|
28 |
+
'duration_hours': [duration],
|
29 |
+
'deadline_days': [deadline_days]
|
30 |
+
})
|
31 |
+
|
32 |
+
# Transform menggunakan scaler
|
33 |
+
input_scaled = scaler.transform(input_data)
|
34 |
+
|
35 |
+
# Predict
|
36 |
+
priority = model.predict(input_scaled)[0]
|
37 |
+
|
38 |
+
priority_map = {
|
39 |
+
1: "Rendah",
|
40 |
+
2: "Sedang",
|
41 |
+
3: "Tinggi"
|
42 |
+
}
|
43 |
+
|
44 |
+
# Generate response
|
45 |
+
response = f"Analisis Tugas: {task_name}\n"
|
46 |
+
response += f"Durasi: {duration} jam\n"
|
47 |
+
response += f"Deadline: {deadline_days} hari lagi\n"
|
48 |
+
response += f"Prioritas: {priority_map[priority]}\n\n"
|
49 |
+
|
50 |
+
# Add recommendations
|
51 |
+
if priority == 3:
|
52 |
+
response += "Rekomendasi: Kerjakan segera! Deadline dekat dan membutuhkan waktu lama."
|
53 |
+
elif priority == 2:
|
54 |
+
response += "Rekomendasi: Buatlah jadwal yang tepat dan mulai kerjakan secara bertahap."
|
55 |
+
else:
|
56 |
+
response += "Rekomendasi: Dapat dikerjakan dengan lebih santai, tapi tetap pantau progress."
|
57 |
+
|
58 |
+
return response
|
59 |
+
|
60 |
+
except Exception as e:
|
61 |
+
return f"Error: {str(e)}"
|
62 |
+
|
63 |
+
# Create Gradio interface
|
64 |
+
iface = gr.Interface(
|
65 |
+
fn=predict_task_priority,
|
66 |
+
inputs=[
|
67 |
+
gr.Dropdown(
|
68 |
+
choices=[
|
69 |
+
"Meeting",
|
70 |
+
"Bekerja",
|
71 |
+
"Belajar",
|
72 |
+
"Tugas Kuliah",
|
73 |
+
"Proyek"
|
74 |
+
],
|
75 |
+
label="Nama Tugas"
|
76 |
+
),
|
77 |
+
gr.Slider(
|
78 |
+
minimum=1,
|
79 |
+
maximum=10,
|
80 |
+
value=5,
|
81 |
+
step=0.5,
|
82 |
+
label="Durasi Tugas (dalam jam)"
|
83 |
+
),
|
84 |
+
gr.Textbox(
|
85 |
+
label="Deadline (YYYY-MM-DD)",
|
86 |
+
placeholder="Contoh: 2024-12-31",
|
87 |
+
info="Masukkan tanggal dalam format YYYY-MM-DD"
|
88 |
+
)
|
89 |
+
],
|
90 |
+
outputs=gr.Textbox(label="Hasil Analisis", lines=6),
|
91 |
+
title="Sistem Prioritas Tugas",
|
92 |
+
description="""
|
93 |
+
Sistem ini akan membantu Anda menentukan prioritas tugas berdasarkan:
|
94 |
+
1. Durasi pengerjaan tugas
|
95 |
+
2. Jarak waktu ke deadline
|
96 |
+
|
97 |
+
Hasil analisis akan memberikan rekomendasi pengelolaan waktu yang sesuai.
|
98 |
+
"""
|
99 |
+
)
|
100 |
+
|
101 |
+
if __name__ == "__main__":
|
102 |
+
iface.launch()
|
feature_names.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d25d890a4b1d46bc451c5d0b3c9716ef62cb1535ecf0f6ed4c0aaa88889def15
|
3 |
+
size 68
|
random_forest_model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2ba6a8562739e97a01bcfd9ab8951b517fbe9facdeab5bcc377a2a75c7b11c20
|
3 |
+
size 208177
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pandas
|
2 |
+
numpy
|
3 |
+
scikit-learn
|
4 |
+
matplotlib
|
5 |
+
seaborn
|
6 |
+
openpyxl
|
7 |
+
joblib
|
scaler.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0966b70867b160ff7825c7ffa262286e8e1652eb43cdc8a4a0ea2f2355f2591a
|
3 |
+
size 999
|