Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,23 +14,22 @@ logging.basicConfig(level=logging.INFO)
|
|
| 14 |
logger = logging.getLogger(__name__)
|
| 15 |
|
| 16 |
# Global variables
|
| 17 |
-
CURRENT_UTC_TIME = datetime.strptime("2025-02-04 19:
|
| 18 |
CURRENT_USER = "ChadSaglam"
|
| 19 |
|
| 20 |
@st.cache_resource
|
| 21 |
def load_ai_model():
|
| 22 |
-
"""Initialize the AI model for task generation"""
|
| 23 |
try:
|
| 24 |
model_name = "EleutherAI/gpt-neo-125M"
|
| 25 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 26 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 27 |
|
| 28 |
-
# Create pipeline
|
| 29 |
pipe = pipeline(
|
| 30 |
"text-generation",
|
| 31 |
model=model,
|
| 32 |
tokenizer=tokenizer,
|
| 33 |
max_new_tokens=512,
|
|
|
|
| 34 |
temperature=0.7,
|
| 35 |
top_p=0.95,
|
| 36 |
repetition_penalty=1.15
|
|
@@ -59,77 +58,122 @@ class AIProjectManager:
|
|
| 59 |
"Retrospective"
|
| 60 |
]
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
def generate_project_tasks(self, project_name: str, project_type: str) -> List[Dict]:
|
| 63 |
-
"""AI-driven task generation based on project type and name"""
|
| 64 |
try:
|
| 65 |
-
# Create prompt for the AI model
|
| 66 |
prompt = f"""
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
"""
|
| 80 |
|
| 81 |
# Generate response using the AI model
|
| 82 |
response = self.llm(prompt)
|
| 83 |
|
| 84 |
-
# Parse the response and format tasks
|
| 85 |
try:
|
|
|
|
| 86 |
tasks_data = json.loads(response)
|
| 87 |
-
return self.
|
| 88 |
except json.JSONDecodeError:
|
| 89 |
-
# Fallback to structured
|
|
|
|
| 90 |
return self._generate_structured_tasks(project_name, project_type)
|
| 91 |
|
| 92 |
except Exception as e:
|
| 93 |
logger.error(f"Error generating tasks: {str(e)}")
|
| 94 |
return self._generate_structured_tasks(project_name, project_type)
|
| 95 |
|
| 96 |
-
def _format_tasks(self, tasks_data: Dict) -> List[Dict]:
|
| 97 |
-
"""Format AI-generated tasks into standardized structure"""
|
| 98 |
-
formatted_tasks = []
|
| 99 |
-
|
| 100 |
-
for task in tasks_data.get("tasks", []):
|
| 101 |
-
formatted_task = {
|
| 102 |
-
"id": str(uuid.uuid4()),
|
| 103 |
-
"title": task.get("title", "Untitled Task"),
|
| 104 |
-
"priority": task.get("priority", "P2"),
|
| 105 |
-
"status": "TO_DO",
|
| 106 |
-
"assigned_to": task.get("assigned_to", "Unassigned"),
|
| 107 |
-
"estimated_hours": task.get("estimated_hours", 0),
|
| 108 |
-
"description": task.get("description", ""),
|
| 109 |
-
"acceptance_criteria": task.get("acceptance_criteria", []),
|
| 110 |
-
"subtasks": []
|
| 111 |
-
}
|
| 112 |
-
|
| 113 |
-
# Format subtasks
|
| 114 |
-
for subtask in task.get("subtasks", []):
|
| 115 |
-
formatted_subtask = {
|
| 116 |
-
"id": str(uuid.uuid4()),
|
| 117 |
-
"title": subtask.get("title", "Untitled Subtask"),
|
| 118 |
-
"status": "TO_DO",
|
| 119 |
-
"assigned_to": subtask.get("assigned_to", "Unassigned"),
|
| 120 |
-
"estimated_hours": subtask.get("estimated_hours", 0)
|
| 121 |
-
}
|
| 122 |
-
formatted_task["subtasks"].append(formatted_subtask)
|
| 123 |
-
|
| 124 |
-
formatted_tasks.append(formatted_task)
|
| 125 |
-
|
| 126 |
-
return formatted_tasks
|
| 127 |
-
|
| 128 |
def render_task_ui():
|
| 129 |
st.title("AI-Powered Project Management")
|
| 130 |
|
| 131 |
-
|
| 132 |
-
project_name = st.text_input("Project Name")
|
| 133 |
project_type = st.selectbox("Project Type", [
|
| 134 |
"E-commerce Website",
|
| 135 |
"Mobile Application",
|
|
@@ -140,17 +184,15 @@ def render_task_ui():
|
|
| 140 |
])
|
| 141 |
|
| 142 |
if st.button("Generate Tasks") and project_name:
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
st.session_state.tasks = tasks
|
| 148 |
|
| 149 |
-
# Display tasks
|
| 150 |
display_tasks(tasks)
|
| 151 |
|
| 152 |
def display_tasks(tasks: List[Dict]):
|
| 153 |
-
st.subheader("
|
| 154 |
|
| 155 |
for task in tasks:
|
| 156 |
with st.expander(f"📋 {task['title']} ({task['priority']})"):
|
|
@@ -185,11 +227,9 @@ def display_tasks(tasks: List[Dict]):
|
|
| 185 |
def main():
|
| 186 |
st.set_page_config(page_title="AI Project Management", layout="wide")
|
| 187 |
|
| 188 |
-
# Display current user and time
|
| 189 |
st.sidebar.info(f"Current User: {CURRENT_USER}")
|
| 190 |
st.sidebar.info(f"Current Time (UTC): {CURRENT_UTC_TIME.strftime('%Y-%m-%d %H:%M:%S')}")
|
| 191 |
|
| 192 |
-
# Initialize session state
|
| 193 |
if "tasks" not in st.session_state:
|
| 194 |
st.session_state.tasks = []
|
| 195 |
|
|
|
|
| 14 |
logger = logging.getLogger(__name__)
|
| 15 |
|
| 16 |
# Global variables
|
| 17 |
+
CURRENT_UTC_TIME = datetime.strptime("2025-02-04 19:27:44", "%Y-%m-%d %H:%M:%S")
|
| 18 |
CURRENT_USER = "ChadSaglam"
|
| 19 |
|
| 20 |
@st.cache_resource
|
| 21 |
def load_ai_model():
|
|
|
|
| 22 |
try:
|
| 23 |
model_name = "EleutherAI/gpt-neo-125M"
|
| 24 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 25 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 26 |
|
|
|
|
| 27 |
pipe = pipeline(
|
| 28 |
"text-generation",
|
| 29 |
model=model,
|
| 30 |
tokenizer=tokenizer,
|
| 31 |
max_new_tokens=512,
|
| 32 |
+
do_sample=True,
|
| 33 |
temperature=0.7,
|
| 34 |
top_p=0.95,
|
| 35 |
repetition_penalty=1.15
|
|
|
|
| 58 |
"Retrospective"
|
| 59 |
]
|
| 60 |
|
| 61 |
+
def _generate_structured_tasks(self, project_name: str, project_type: str) -> List[Dict]:
|
| 62 |
+
"""Fallback method for generating structured tasks"""
|
| 63 |
+
base_tasks = {
|
| 64 |
+
"E-commerce Website": [
|
| 65 |
+
{
|
| 66 |
+
"title": "User Authentication System",
|
| 67 |
+
"priority": "P0",
|
| 68 |
+
"assigned_to": "Backend Team",
|
| 69 |
+
"estimated_hours": 40,
|
| 70 |
+
"description": "Implement secure authentication system",
|
| 71 |
+
"acceptance_criteria": ["Secure login", "Password recovery", "OAuth integration"],
|
| 72 |
+
"subtasks": [
|
| 73 |
+
{"title": "Setup Auth API", "assigned_to": "Backend Dev", "estimated_hours": 16},
|
| 74 |
+
{"title": "Implement OAuth", "assigned_to": "Backend Dev", "estimated_hours": 24}
|
| 75 |
+
]
|
| 76 |
+
},
|
| 77 |
+
{
|
| 78 |
+
"title": "Product Catalog",
|
| 79 |
+
"priority": "P0",
|
| 80 |
+
"assigned_to": "Frontend Team",
|
| 81 |
+
"estimated_hours": 60,
|
| 82 |
+
"description": "Create product listing and details pages",
|
| 83 |
+
"acceptance_criteria": ["Product grid", "Search functionality", "Filtering"],
|
| 84 |
+
"subtasks": [
|
| 85 |
+
{"title": "Product Grid UI", "assigned_to": "Frontend Dev", "estimated_hours": 24},
|
| 86 |
+
{"title": "Search Implementation", "assigned_to": "Frontend Dev", "estimated_hours": 36}
|
| 87 |
+
]
|
| 88 |
+
}
|
| 89 |
+
],
|
| 90 |
+
"Mobile Application": [
|
| 91 |
+
{
|
| 92 |
+
"title": "App Architecture Setup",
|
| 93 |
+
"priority": "P0",
|
| 94 |
+
"assigned_to": "Mobile Team",
|
| 95 |
+
"estimated_hours": 40,
|
| 96 |
+
"description": "Setup initial app architecture",
|
| 97 |
+
"acceptance_criteria": ["Project structure", "Navigation flow", "State management"],
|
| 98 |
+
"subtasks": [
|
| 99 |
+
{"title": "Project Setup", "assigned_to": "Mobile Dev", "estimated_hours": 16},
|
| 100 |
+
{"title": "Navigation Setup", "assigned_to": "Mobile Dev", "estimated_hours": 24}
|
| 101 |
+
]
|
| 102 |
+
}
|
| 103 |
+
]
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
tasks = base_tasks.get(project_type, [])
|
| 107 |
+
return [self._format_single_task(task) for task in tasks]
|
| 108 |
+
|
| 109 |
+
def _format_single_task(self, task: Dict) -> Dict:
|
| 110 |
+
"""Format a single task with required fields"""
|
| 111 |
+
return {
|
| 112 |
+
"id": str(uuid.uuid4()),
|
| 113 |
+
"title": task.get("title", "Untitled Task"),
|
| 114 |
+
"priority": task.get("priority", "P2"),
|
| 115 |
+
"status": "TO_DO",
|
| 116 |
+
"assigned_to": task.get("assigned_to", "Unassigned"),
|
| 117 |
+
"estimated_hours": task.get("estimated_hours", 0),
|
| 118 |
+
"description": task.get("description", ""),
|
| 119 |
+
"acceptance_criteria": task.get("acceptance_criteria", []),
|
| 120 |
+
"subtasks": [
|
| 121 |
+
{
|
| 122 |
+
"id": str(uuid.uuid4()),
|
| 123 |
+
"title": subtask.get("title", "Untitled Subtask"),
|
| 124 |
+
"status": "TO_DO",
|
| 125 |
+
"assigned_to": subtask.get("assigned_to", "Unassigned"),
|
| 126 |
+
"estimated_hours": subtask.get("estimated_hours", 0)
|
| 127 |
+
}
|
| 128 |
+
for subtask in task.get("subtasks", [])
|
| 129 |
+
]
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
def generate_project_tasks(self, project_name: str, project_type: str) -> List[Dict]:
|
|
|
|
| 133 |
try:
|
|
|
|
| 134 |
prompt = f"""
|
| 135 |
+
Create a detailed project plan for {project_name} ({project_type}) with the following JSON structure:
|
| 136 |
+
{{
|
| 137 |
+
"tasks": [
|
| 138 |
+
{{
|
| 139 |
+
"title": "Task name",
|
| 140 |
+
"priority": "P0/P1/P2/P3",
|
| 141 |
+
"assigned_to": "Team/Role",
|
| 142 |
+
"estimated_hours": number,
|
| 143 |
+
"description": "Detailed description",
|
| 144 |
+
"acceptance_criteria": ["criteria1", "criteria2"],
|
| 145 |
+
"subtasks": [
|
| 146 |
+
{{
|
| 147 |
+
"title": "Subtask name",
|
| 148 |
+
"assigned_to": "Team/Role",
|
| 149 |
+
"estimated_hours": number
|
| 150 |
+
}}
|
| 151 |
+
]
|
| 152 |
+
}}
|
| 153 |
+
]
|
| 154 |
+
}}
|
| 155 |
"""
|
| 156 |
|
| 157 |
# Generate response using the AI model
|
| 158 |
response = self.llm(prompt)
|
| 159 |
|
|
|
|
| 160 |
try:
|
| 161 |
+
# Try to parse the AI response as JSON
|
| 162 |
tasks_data = json.loads(response)
|
| 163 |
+
return [self._format_single_task(task) for task in tasks_data.get("tasks", [])]
|
| 164 |
except json.JSONDecodeError:
|
| 165 |
+
# Fallback to structured tasks if JSON parsing fails
|
| 166 |
+
logger.warning("Failed to parse AI response, using structured tasks")
|
| 167 |
return self._generate_structured_tasks(project_name, project_type)
|
| 168 |
|
| 169 |
except Exception as e:
|
| 170 |
logger.error(f"Error generating tasks: {str(e)}")
|
| 171 |
return self._generate_structured_tasks(project_name, project_type)
|
| 172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
def render_task_ui():
|
| 174 |
st.title("AI-Powered Project Management")
|
| 175 |
|
| 176 |
+
project_name = st.text_input("Project Name", placeholder="Enter your project name")
|
|
|
|
| 177 |
project_type = st.selectbox("Project Type", [
|
| 178 |
"E-commerce Website",
|
| 179 |
"Mobile Application",
|
|
|
|
| 184 |
])
|
| 185 |
|
| 186 |
if st.button("Generate Tasks") and project_name:
|
| 187 |
+
with st.spinner("Generating tasks with AI..."):
|
| 188 |
+
ai_manager = AIProjectManager()
|
| 189 |
+
tasks = ai_manager.generate_project_tasks(project_name, project_type)
|
| 190 |
+
st.session_state.tasks = tasks
|
|
|
|
| 191 |
|
|
|
|
| 192 |
display_tasks(tasks)
|
| 193 |
|
| 194 |
def display_tasks(tasks: List[Dict]):
|
| 195 |
+
st.subheader("Project Tasks")
|
| 196 |
|
| 197 |
for task in tasks:
|
| 198 |
with st.expander(f"📋 {task['title']} ({task['priority']})"):
|
|
|
|
| 227 |
def main():
|
| 228 |
st.set_page_config(page_title="AI Project Management", layout="wide")
|
| 229 |
|
|
|
|
| 230 |
st.sidebar.info(f"Current User: {CURRENT_USER}")
|
| 231 |
st.sidebar.info(f"Current Time (UTC): {CURRENT_UTC_TIME.strftime('%Y-%m-%d %H:%M:%S')}")
|
| 232 |
|
|
|
|
| 233 |
if "tasks" not in st.session_state:
|
| 234 |
st.session_state.tasks = []
|
| 235 |
|