Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from datetime import datetime, timedelta
|
| 4 |
+
import plotly.express as px
|
| 5 |
+
from transformers import pipeline
|
| 6 |
+
|
| 7 |
+
# Caching untuk performa
|
| 8 |
+
@st.cache_resource
|
| 9 |
+
def load_ai_models():
|
| 10 |
+
try:
|
| 11 |
+
text_generator = pipeline('text-generation', model='distilgpt2')
|
| 12 |
+
task_classifier = pipeline('zero-shot-classification',
|
| 13 |
+
model='facebook/bart-large-mnli')
|
| 14 |
+
return text_generator, task_classifier
|
| 15 |
+
except Exception as e:
|
| 16 |
+
st.error(f"Error loading AI models: {e}")
|
| 17 |
+
return None, None
|
| 18 |
+
|
| 19 |
+
class AIProjectManager:
|
| 20 |
+
def __init__(self):
|
| 21 |
+
self.text_generator, self.task_classifier = load_ai_models()
|
| 22 |
+
|
| 23 |
+
def generate_task_description(self, task_type):
|
| 24 |
+
if not self.text_generator:
|
| 25 |
+
return "AI description generation failed"
|
| 26 |
+
|
| 27 |
+
prompt = f"Generate a project task description for {task_type}:"
|
| 28 |
+
try:
|
| 29 |
+
description = self.text_generator(prompt, max_length=100)[0]['generated_text']
|
| 30 |
+
return description.strip()
|
| 31 |
+
except:
|
| 32 |
+
return "Default task description"
|
| 33 |
+
|
| 34 |
+
def classify_task_complexity(self, task_description):
|
| 35 |
+
if not self.task_classifier:
|
| 36 |
+
return "Medium"
|
| 37 |
+
|
| 38 |
+
try:
|
| 39 |
+
classification = self.task_classifier(
|
| 40 |
+
task_description,
|
| 41 |
+
candidate_labels=['Low', 'Medium', 'High'],
|
| 42 |
+
multi_label=False
|
| 43 |
+
)
|
| 44 |
+
return classification['labels'][0]
|
| 45 |
+
except:
|
| 46 |
+
return "Medium"
|
| 47 |
+
|
| 48 |
+
class ProjectManagementApp:
|
| 49 |
+
def __init__(self):
|
| 50 |
+
self.ai_manager = AIProjectManager()
|
| 51 |
+
|
| 52 |
+
def initialize_session_state(self):
|
| 53 |
+
if 'tasks' not in st.session_state:
|
| 54 |
+
st.session_state.tasks = pd.DataFrame(columns=[
|
| 55 |
+
'Task Name', 'Start Date', 'End Date',
|
| 56 |
+
'Duration', 'Complexity', 'Progress', 'Cost'
|
| 57 |
+
])
|
| 58 |
+
|
| 59 |
+
def add_task(self, task_name, start_date, duration):
|
| 60 |
+
task_description = self.ai_manager.generate_task_description(task_name)
|
| 61 |
+
complexity = self.ai_manager.classify_task_complexity(task_description)
|
| 62 |
+
|
| 63 |
+
new_task = pd.DataFrame([{
|
| 64 |
+
'Task Name': task_name,
|
| 65 |
+
'Start Date': start_date,
|
| 66 |
+
'End Date': start_date + timedelta(days=duration),
|
| 67 |
+
'Duration': duration,
|
| 68 |
+
'Complexity': complexity,
|
| 69 |
+
'Progress': 0,
|
| 70 |
+
'Cost': duration * 500
|
| 71 |
+
}])
|
| 72 |
+
|
| 73 |
+
st.session_state.tasks = pd.concat([st.session_state.tasks, new_task], ignore_index=True)
|
| 74 |
+
|
| 75 |
+
def render_dashboard(self):
|
| 76 |
+
st.title("🚀 AI Project Management Dashboard")
|
| 77 |
+
|
| 78 |
+
# Input Task Section
|
| 79 |
+
with st.form("task_input"):
|
| 80 |
+
col1, col2 = st.columns(2)
|
| 81 |
+
with col1:
|
| 82 |
+
task_name = st.text_input("Nama Tugas")
|
| 83 |
+
with col2:
|
| 84 |
+
duration = st.number_input("Durasi (Hari)", min_value=1, max_value=365)
|
| 85 |
+
|
| 86 |
+
start_date = st.date_input("Tanggal Mulai")
|
| 87 |
+
|
| 88 |
+
if st.form_submit_button("Tambah Tugas"):
|
| 89 |
+
if task_name:
|
| 90 |
+
self.add_task(task_name, start_date, duration)
|
| 91 |
+
else:
|
| 92 |
+
st.warning("Nama tugas tidak boleh kosong!")
|
| 93 |
+
|
| 94 |
+
# Tampilkan Tasks
|
| 95 |
+
if not st.session_state.tasks.empty:
|
| 96 |
+
st.subheader("Daftar Tugas")
|
| 97 |
+
st.dataframe(st.session_state.tasks)
|
| 98 |
+
|
| 99 |
+
# Visualisasi
|
| 100 |
+
col1, col2 = st.columns(2)
|
| 101 |
+
|
| 102 |
+
with col1:
|
| 103 |
+
st.subheader("Kompleksitas Tugas")
|
| 104 |
+
complexity_chart = st.session_state.tasks['Complexity'].value_counts()
|
| 105 |
+
st.bar_chart(complexity_chart)
|
| 106 |
+
|
| 107 |
+
with col2:
|
| 108 |
+
st.subheader("Gantt Chart")
|
| 109 |
+
try:
|
| 110 |
+
fig = px.timeline(
|
| 111 |
+
st.session_state.tasks,
|
| 112 |
+
x_start='Start Date',
|
| 113 |
+
x_end='End Date',
|
| 114 |
+
y='Task Name',
|
| 115 |
+
color='Complexity'
|
| 116 |
+
)
|
| 117 |
+
st.plotly_chart(fig)
|
| 118 |
+
except Exception as e:
|
| 119 |
+
st.error(f"Gagal membuat Gantt Chart: {e}")
|
| 120 |
+
|
| 121 |
+
def run(self):
|
| 122 |
+
self.initialize_session_state()
|
| 123 |
+
self.render_dashboard()
|
| 124 |
+
|
| 125 |
+
def main():
|
| 126 |
+
app = ProjectManagementApp()
|
| 127 |
+
app.run()
|
| 128 |
+
|
| 129 |
+
if __name__ == "__main__":
|
| 130 |
+
main()
|