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