import pandas as pd import joblib import gradio as gr from datetime import datetime, timedelta # Load model model = joblib.load('random_forest_model.pkl') def predict_task_duration(task_name, duration, deadline): try: start_date = datetime(2024, 10, 20) deadline_date = datetime.strptime(deadline, '%Y-%m-%d') deadline_days = (deadline_date - start_date).days input_data = pd.DataFrame({ 'duration': [duration], 'deadline_days': [deadline_days] }) priority = model.predict(input_data) priority_map = { 1: "Rendah", 2: "Sedang", 3: "Tinggi" } result = priority_map.get(priority[0], "Tidak diketahui") return f'Prioritas Tugas: {result}' except Exception as e: return f"Error: {str(e)}" # Membuat interface Gradio iface = gr.Interface( fn=predict_task_duration, inputs=[ gr.Dropdown( choices=["Meeting", "Bekerja", "Belajar"], label="Nama Tugas" ), gr.Slider( minimum=1, maximum=10, value=5, step=0.1, label="Durasi Tugas (dalam jam)" ), gr.Date(label="Deadline") # Menambahkan input deadline ], outputs=gr.Text(label="Hasil Prediksi"), title="Sistem Prediksi Prioritas Tugas", description="Masukkan nama tugas, durasi, dan deadline untuk memprediksi prioritasnya" ) # Launch the interface iface.launch()