File size: 4,346 Bytes
fe03bf4
 
 
 
 
 
 
 
 
 
 
 
 
ce3c51f
 
 
 
fe03bf4
 
 
 
 
ce3c51f
fe03bf4
 
 
 
ce3c51f
fe03bf4
 
 
 
 
 
 
 
 
 
 
 
 
 
ce3c51f
fe03bf4
ce3c51f
fe03bf4
 
 
 
 
ce3c51f
fe03bf4
 
ce3c51f
 
fe03bf4
ce3c51f
 
 
 
fe03bf4
 
ce3c51f
 
 
 
fe03bf4
 
ce3c51f
 
 
 
fe03bf4
 
 
 
 
 
 
 
 
 
ce3c51f
 
 
 
fe03bf4
 
 
 
 
 
ce3c51f
 
fe03bf4
 
ce3c51f
fe03bf4
ce3c51f
fe03bf4
 
ce3c51f
fe03bf4
 
 
 
 
 
ce3c51f
 
 
 
 
 
 
 
fe03bf4
 
 
ba9ba46
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import pandas as pd
import numpy as np
import gradio as gr
import joblib
from datetime import datetime

# Load model, scaler, dan feature names
model = joblib.load('random_forest_model.pkl')
scaler = joblib.load('scaler.pkl')
feature_names = joblib.load('feature_names.pkl')['feature_names']

def predict_task_priority(task_name, duration, deadline_str):
    try:
        # Validasi input task name
        if not task_name.strip():
            return "Error: Nama tugas tidak boleh kosong"
            
        # Parse deadline string to calculate days
        start_date = datetime.now()
        try:
            deadline = datetime.strptime(deadline_str, '%Y-%m-%d')
        except:
            return "Error: Format tanggal harus YYYY-MM-DD (contoh: 2024-12-31)"
            
        deadline_days = (deadline - start_date).days
        
        if deadline_days < 0:
            return "Error: Deadline tidak boleh di masa lalu"
        
        # Buat DataFrame dengan feature names yang sesuai
        input_data = pd.DataFrame({
            'duration_hours': [duration],
            'deadline_days': [deadline_days]
        })
        
        # Transform menggunakan scaler
        input_scaled = scaler.transform(input_data)
        
        # Predict
        priority = model.predict(input_scaled)[0]
        
        priority_map = {
            1: "Tinggi",
            2: "Sedang",
            3: "Rendah"
        }
        
        # Generate response
        response = f"Analisis Tugas: {task_name}\n"
        response += f"Durasi: {duration} jam\n"
        response += f"Deadline: {deadline_str} ({deadline_days} hari lagi)\n"
        response += f"Prioritas: {priority_map[priority]}\n\n"
        
        # Add recommendations based on priority
        if priority == 1:
            response += "Rekomendasi: Kerjakan segera! Deadline dekat dan membutuhkan waktu lama."
            response += "\nTindakan yang disarankan:"
            response += "\n• Fokus utama pada tugas ini"
            response += "\n• Buat jadwal spesifik untuk pengerjaannya"
            response += "\n• Siapkan semua resource yang dibutuhkan"
        elif priority == 2:
            response += "Rekomendasi: Buatlah jadwal yang tepat dan mulai kerjakan secara bertahap."
            response += "\nTindakan yang disarankan:"
            response += "\n• Bagi tugas menjadi beberapa milestone"
            response += "\n• Alokasikan waktu setiap hari untuk progress"
            response += "\n• Pantau perkembangan secara reguler"
        else:
            response += "Rekomendasi: Dapat dikerjakan dengan lebih santai, tapi tetap pantau progress."
            response += "\nTindakan yang disarankan:"
            response += "\n• Buat timeline longgar untuk pengerjaan"
            response += "\n• Sesuaikan dengan jadwal tugas prioritas lain"
            response += "\n• Review progress mingguan"
            
        return response
    
    except Exception as e:
        return f"Error: {str(e)}"

# Create Gradio interface
iface = gr.Interface(
    fn=predict_task_priority,
    inputs=[
        gr.Textbox(
            label="Nama Tugas",
            placeholder="Masukkan nama tugas Anda",
            info="Contoh: Laporan Akhir, Presentasi Project, dll."
        ),
        gr.Slider(
            minimum=1,
            maximum=10,
            value=5,
            step=0.5,
            label="Durasi Tugas (dalam jam)",
            info="Perkiraan waktu yang dibutuhkan untuk menyelesaikan tugas"
        ),
        gr.Textbox(
            label="Deadline (YYYY-MM-DD)",
            placeholder="Contoh: 2024-12-31",
            info="Masukkan tanggal dalam format YYYY-MM-DD"
        )
    ],
    outputs=gr.Textbox(label="Hasil Analisis", lines=10),
    title="Sistem Prioritas Tugas",
    description="""
    Sistem ini akan membantu Anda menentukan prioritas tugas berdasarkan:
    1. Durasi pengerjaan tugas
    2. Jarak waktu ke deadline
    
    Hasil analisis akan memberikan rekomendasi pengelolaan waktu yang sesuai untuk membantu
    Anda mengelola tugas dengan lebih efektif.
    """,
    examples=[
        ["Laporan Akhir Semester", 8, "2024-11-30"],
        ["Presentasi Project", 3, "2024-12-15"],
        ["Revisi Proposal", 5, "2024-11-25"]
    ]
)

if __name__ == "__main__":
    iface.launch()