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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
IT-Business Analysis Assistant - Professional Version with DeepSeek AI
|
| 3 |
+
Enhanced Local Templates for Comprehensive BA Coverage
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
import json
|
| 8 |
+
import difflib
|
| 9 |
+
import logging
|
| 10 |
+
import requests
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
from typing import Tuple, List, Dict, Any, Optional
|
| 13 |
+
|
| 14 |
+
import gradio as gr
|
| 15 |
+
from dotenv import load_dotenv
|
| 16 |
+
|
| 17 |
+
# Load environment variables
|
| 18 |
+
load_dotenv()
|
| 19 |
+
|
| 20 |
+
# Configure logging
|
| 21 |
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 22 |
+
logger = logging.getLogger(__name__)
|
| 23 |
+
|
| 24 |
+
# ---------------------------
|
| 25 |
+
# Configuration
|
| 26 |
+
# ---------------------------
|
| 27 |
+
class Config:
|
| 28 |
+
"""Application configuration"""
|
| 29 |
+
|
| 30 |
+
BASE_DIR = Path(__file__).resolve().parent
|
| 31 |
+
DATA_DIR = BASE_DIR / "data"
|
| 32 |
+
KEYWORDS_FILE = DATA_DIR / "ba_keywords.json"
|
| 33 |
+
KEYWORD_MATCH_THRESHOLD = 0.7
|
| 34 |
+
|
| 35 |
+
APP_NAME = "Professional IT Business Analysis Assistant"
|
| 36 |
+
APP_VERSION = "3.0.0"
|
| 37 |
+
APP_DESCRIPTION = "AI-powered guide for BA concepts and business domains"
|
| 38 |
+
|
| 39 |
+
# DeepSeek API Configuration - Reads from secrets
|
| 40 |
+
DEEPSEEK_API_KEY = os.environ.get("BA_Assistant") or os.environ.get("DEEPSEEK_API_KEY") or ""
|
| 41 |
+
DEEPSEEK_BASE_URL = "https://api.deepseek.com/v1"
|
| 42 |
+
DEEPSEEK_MODEL = "deepseek-chat"
|
| 43 |
+
|
| 44 |
+
# ===== API KEY TEST (Using Config) =====
|
| 45 |
+
print("\n" + "="*50)
|
| 46 |
+
print("π TESTING DEEPSEEK API KEY DIRECTLY")
|
| 47 |
+
print("="*50)
|
| 48 |
+
|
| 49 |
+
if Config.DEEPSEEK_API_KEY:
|
| 50 |
+
print(f"Testing key: {Config.DEEPSEEK_API_KEY[:10]}...")
|
| 51 |
+
|
| 52 |
+
try:
|
| 53 |
+
headers = {"Authorization": f"Bearer {Config.DEEPSEEK_API_KEY}"}
|
| 54 |
+
response = requests.get(
|
| 55 |
+
"https://api.deepseek.com/v1/models",
|
| 56 |
+
headers=headers,
|
| 57 |
+
timeout=10
|
| 58 |
+
)
|
| 59 |
+
print(f"Status Code: {response.status_code}")
|
| 60 |
+
if response.status_code == 200:
|
| 61 |
+
print("β
SUCCESS! Key works!")
|
| 62 |
+
print(f"Response: {response.json()}")
|
| 63 |
+
else:
|
| 64 |
+
print(f"β FAILED: {response.text}")
|
| 65 |
+
except Exception as e:
|
| 66 |
+
print(f"β ERROR: {e}")
|
| 67 |
+
else:
|
| 68 |
+
print("β No API key found in environment")
|
| 69 |
+
print("="*50 + "\n")
|
| 70 |
+
# ===== END TEST =====
|
| 71 |
+
|
| 72 |
+
# Initialize DeepSeek
|
| 73 |
+
DEEPSEEK_AVAILABLE = False
|
| 74 |
+
DEEPSEEK_ERROR = None
|
| 75 |
+
|
| 76 |
+
if Config.DEEPSEEK_API_KEY:
|
| 77 |
+
logger.info(f"β
DeepSeek API key found (length: {len(Config.DEEPSEEK_API_KEY)})")
|
| 78 |
+
|
| 79 |
+
# Simple validation - just check key length
|
| 80 |
+
if len(Config.DEEPSEEK_API_KEY) > 20:
|
| 81 |
+
DEEPSEEK_AVAILABLE = True
|
| 82 |
+
logger.info("β
DeepSeek API is AVAILABLE and ready to use!")
|
| 83 |
+
else:
|
| 84 |
+
DEEPSEEK_ERROR = "API key too short"
|
| 85 |
+
logger.warning(f"β οΈ {DEEPSEEK_ERROR}")
|
| 86 |
+
else:
|
| 87 |
+
DEEPSEEK_ERROR = "No API key found"
|
| 88 |
+
logger.info("π No API key - using local templates")
|
| 89 |
+
|
| 90 |
+
# ---------------------------
|
| 91 |
+
# Load BA Keywords
|
| 92 |
+
# ---------------------------
|
| 93 |
+
def load_ba_keywords() -> Dict[str, List[str]]:
|
| 94 |
+
"""Load BA keywords from JSON file"""
|
| 95 |
+
try:
|
| 96 |
+
if not Config.KEYWORDS_FILE.exists():
|
| 97 |
+
logger.warning("Keywords file not found, using defaults")
|
| 98 |
+
return get_default_ba_keywords()
|
| 99 |
+
|
| 100 |
+
with open(Config.KEYWORDS_FILE, 'r', encoding='utf-8') as f:
|
| 101 |
+
data = json.load(f)
|
| 102 |
+
return data.get('categories', get_default_ba_keywords())
|
| 103 |
+
except Exception as e:
|
| 104 |
+
logger.error(f"Error loading keywords: {e}")
|
| 105 |
+
return get_default_ba_keywords()
|
| 106 |
+
|
| 107 |
+
def get_default_ba_keywords() -> Dict[str, List[str]]:
|
| 108 |
+
"""Fallback default BA keywords"""
|
| 109 |
+
return {
|
| 110 |
+
"Core Concepts": [
|
| 111 |
+
"business analysis", "requirements gathering", "stakeholder analysis",
|
| 112 |
+
"business case", "scope definition", "gap analysis", "requirements",
|
| 113 |
+
"stakeholder", "business need", "value proposition", "traceability",
|
| 114 |
+
"swot analysis", "pestle analysis", "mosco w", "prioritization"
|
| 115 |
+
],
|
| 116 |
+
"Methodologies": [
|
| 117 |
+
"agile", "scrum", "kanban", "waterfall", "babok", "bpmn", "uml",
|
| 118 |
+
"user stories", "acceptance criteria", "sprint", "product backlog"
|
| 119 |
+
],
|
| 120 |
+
"Requirements": [
|
| 121 |
+
"functional requirements", "non-functional requirements", "srs", "brd",
|
| 122 |
+
"user stories", "acceptance criteria", "requirements traceability",
|
| 123 |
+
"traceability matrix", "rtm", "use cases", "epics", "features"
|
| 124 |
+
],
|
| 125 |
+
"Business Domains": [
|
| 126 |
+
"financial services", "banking", "healthcare", "retail", "supply chain",
|
| 127 |
+
"insurance", "manufacturing", "telecom", "e-commerce", "logistics"
|
| 128 |
+
]
|
| 129 |
+
}
|
| 130 |
+
|
| 131 |
+
# Load keywords
|
| 132 |
+
BA_KEYWORDS = load_ba_keywords()
|
| 133 |
+
|
| 134 |
+
# Create a simple list of all keywords for matching
|
| 135 |
+
ALL_KEYWORDS = []
|
| 136 |
+
for category, keywords in BA_KEYWORDS.items():
|
| 137 |
+
ALL_KEYWORDS.extend([k.lower() for k in keywords])
|
| 138 |
+
ALL_KEYWORDS = list(set(ALL_KEYWORDS))
|
| 139 |
+
logger.info(f"π Loaded {len(ALL_KEYWORDS)} keywords")
|
| 140 |
+
|
| 141 |
+
# ---------------------------
|
| 142 |
+
# Simple Keyword Detection
|
| 143 |
+
# ---------------------------
|
| 144 |
+
def is_ba_related(question: str) -> Tuple[bool, List[str], List[str]]:
|
| 145 |
+
"""
|
| 146 |
+
Simple check if question contains BA-related keywords
|
| 147 |
+
"""
|
| 148 |
+
if not question or not question.strip():
|
| 149 |
+
return False, [], []
|
| 150 |
+
|
| 151 |
+
question_lower = question.lower()
|
| 152 |
+
matched_keywords = []
|
| 153 |
+
matched_categories = set()
|
| 154 |
+
|
| 155 |
+
# Simple contains check
|
| 156 |
+
for keyword in ALL_KEYWORDS:
|
| 157 |
+
if keyword in question_lower:
|
| 158 |
+
matched_keywords.append(keyword)
|
| 159 |
+
for cat, keys in BA_KEYWORDS.items():
|
| 160 |
+
if any(k.lower() == keyword for k in keys):
|
| 161 |
+
matched_categories.add(cat)
|
| 162 |
+
break
|
| 163 |
+
|
| 164 |
+
# Also check individual words for common BA terms
|
| 165 |
+
words = question_lower.split()
|
| 166 |
+
ba_terms = ["stakeholder", "requirement", "agile", "scrum", "babok",
|
| 167 |
+
"banking", "healthcare", "traceability", "waterfall", "kanban",
|
| 168 |
+
"swot", "pestle", "business case", "gap analysis", "mosco w"]
|
| 169 |
+
for term in ba_terms:
|
| 170 |
+
if term in words or term in question_lower:
|
| 171 |
+
matched_keywords.append(term)
|
| 172 |
+
if term in ["stakeholder", "requirement", "traceability", "business case", "gap analysis"]:
|
| 173 |
+
matched_categories.add("Core Concepts")
|
| 174 |
+
elif term in ["agile", "scrum", "babok", "waterfall", "kanban"]:
|
| 175 |
+
matched_categories.add("Methodologies")
|
| 176 |
+
elif term in ["swot", "pestle", "mosco w"]:
|
| 177 |
+
matched_categories.add("Core Concepts")
|
| 178 |
+
elif term in ["banking", "healthcare"]:
|
| 179 |
+
matched_categories.add("Business Domains")
|
| 180 |
+
|
| 181 |
+
is_related = len(matched_keywords) > 0
|
| 182 |
+
return is_related, list(set(matched_keywords))[:5], list(matched_categories)
|
| 183 |
+
|
| 184 |
+
# ---------------------------
|
| 185 |
+
# Get DeepSeek Response
|
| 186 |
+
# ---------------------------
|
| 187 |
+
def get_deepseek_response(question: str) -> Optional[str]:
|
| 188 |
+
"""Get response from DeepSeek API"""
|
| 189 |
+
|
| 190 |
+
if not DEEPSEEK_AVAILABLE:
|
| 191 |
+
logger.info("DeepSeek not available, skipping API call")
|
| 192 |
+
return None
|
| 193 |
+
|
| 194 |
+
try:
|
| 195 |
+
logger.info(f"Calling DeepSeek API for question: {question[:50]}...")
|
| 196 |
+
|
| 197 |
+
url = f"{Config.DEEPSEEK_BASE_URL}/chat/completions"
|
| 198 |
+
headers = {
|
| 199 |
+
"Authorization": f"Bearer {Config.DEEPSEEK_API_KEY}",
|
| 200 |
+
"Content-Type": "application/json"
|
| 201 |
+
}
|
| 202 |
+
payload = {
|
| 203 |
+
"model": Config.DEEPSEEK_MODEL,
|
| 204 |
+
"messages": [
|
| 205 |
+
{"role": "system", "content": "You are a senior IT Business Analysis consultant. Provide professional, practical advice."},
|
| 206 |
+
{"role": "user", "content": question}
|
| 207 |
+
],
|
| 208 |
+
"temperature": 0.7,
|
| 209 |
+
"max_tokens": 800
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
response = requests.post(url, headers=headers, json=payload, timeout=30)
|
| 213 |
+
|
| 214 |
+
if response.status_code != 200:
|
| 215 |
+
logger.warning(f"DeepSeek API error: {response.status_code} - {response.text}")
|
| 216 |
+
return None
|
| 217 |
+
|
| 218 |
+
result = response.json()
|
| 219 |
+
logger.info("β
DeepSeek API call successful")
|
| 220 |
+
return result["choices"][0]["message"]["content"]
|
| 221 |
+
|
| 222 |
+
except requests.exceptions.Timeout:
|
| 223 |
+
logger.warning("DeepSeek API timeout")
|
| 224 |
+
return None
|
| 225 |
+
except requests.exceptions.ConnectionError:
|
| 226 |
+
logger.warning("DeepSeek API connection error")
|
| 227 |
+
return None
|
| 228 |
+
except Exception as e:
|
| 229 |
+
logger.warning(f"DeepSeek API error: {type(e).__name__}: {e}")
|
| 230 |
+
return None
|
| 231 |
+
|
| 232 |
+
# ---------------------------
|
| 233 |
+
# Enhanced Local Response Templates
|
| 234 |
+
# ---------------------------
|
| 235 |
+
def get_local_response(question: str, keywords: List[str], categories: List[str]) -> str:
|
| 236 |
+
"""Get response from local templates"""
|
| 237 |
+
|
| 238 |
+
question_lower = question.lower()
|
| 239 |
+
|
| 240 |
+
# AGILE SPECIFIC
|
| 241 |
+
if "agile" in question_lower and "scrum" not in question_lower:
|
| 242 |
+
return """
|
| 243 |
+
## π Agile Methodology
|
| 244 |
+
|
| 245 |
+
### Core Agile Principles
|
| 246 |
+
- **Individuals and interactions** over processes and tools
|
| 247 |
+
- **Working software** over comprehensive documentation
|
| 248 |
+
- **Customer collaboration** over contract negotiation
|
| 249 |
+
- **Responding to change** over following a plan
|
| 250 |
+
|
| 251 |
+
### Agile Methodologies
|
| 252 |
+
- **Scrum**: Sprint-based framework with defined roles
|
| 253 |
+
- **Kanban**: Visual workflow management with WIP limits
|
| 254 |
+
- **XP (Extreme Programming)**: Technical practices for quality
|
| 255 |
+
- **Lean**: Focus on value and eliminating waste
|
| 256 |
+
|
| 257 |
+
### When to Use Agile
|
| 258 |
+
- Requirements expected to change
|
| 259 |
+
- Fast delivery to market is important
|
| 260 |
+
- Close collaboration possible
|
| 261 |
+
- Complex or uncertain projects
|
| 262 |
+
"""
|
| 263 |
+
|
| 264 |
+
# SCRUM SPECIFIC
|
| 265 |
+
elif "scrum" in question_lower:
|
| 266 |
+
return """
|
| 267 |
+
## π Scrum Framework
|
| 268 |
+
|
| 269 |
+
### Scrum Roles
|
| 270 |
+
| **Role** | **Responsibilities** |
|
| 271 |
+
|----------|----------------------|
|
| 272 |
+
| **Product Owner** | Manages backlog, maximizes value, stakeholder liaison |
|
| 273 |
+
| **Scrum Master** | Facilitates process, removes impediments, coaches team |
|
| 274 |
+
| **Development Team** | Self-organizing, cross-functional, delivers increments |
|
| 275 |
+
|
| 276 |
+
### Scrum Events
|
| 277 |
+
| **Event** | **Purpose** | **Duration** |
|
| 278 |
+
|-----------|-------------|--------------|
|
| 279 |
+
| **Sprint Planning** | Plan work for upcoming sprint | Max 8 hours for 1-month sprint |
|
| 280 |
+
| **Daily Stand-up** | Sync progress, plan next 24 hours | 15 minutes |
|
| 281 |
+
| **Sprint Review** | Demonstrate completed work | Max 4 hours for 1-month sprint |
|
| 282 |
+
| **Sprint Retrospective** | Inspect and adapt process | Max 3 hours for 1-month sprint |
|
| 283 |
+
|
| 284 |
+
### Scrum Artifacts
|
| 285 |
+
- **Product Backlog**: Prioritized list of all desired work
|
| 286 |
+
- **Sprint Backlog**: Selected items for current sprint + plan
|
| 287 |
+
- **Increment**: Potentially releasable product at end of sprint
|
| 288 |
+
"""
|
| 289 |
+
|
| 290 |
+
# KANBAN SPECIFIC
|
| 291 |
+
elif "kanban" in question_lower:
|
| 292 |
+
return """
|
| 293 |
+
## π Kanban Method
|
| 294 |
+
|
| 295 |
+
### Core Principles
|
| 296 |
+
- **Visualize Work**: Use boards with columns (To Do, Doing, Done)
|
| 297 |
+
- **Limit Work in Progress (WIP)** : Focus on completing tasks
|
| 298 |
+
- **Manage Flow**: Optimize throughput and reduce cycle time
|
| 299 |
+
- **Make Policies Explicit**: Clearly define processes
|
| 300 |
+
- **Improve Collaboratively**: Evolve with team feedback
|
| 301 |
+
|
| 302 |
+
### Kanban Metrics
|
| 303 |
+
- **Lead Time**: Time from request to delivery
|
| 304 |
+
- **Cycle Time**: Time work is actively being worked on
|
| 305 |
+
- **Throughput**: Amount of work completed per time period
|
| 306 |
+
- **WIP Limits**: Maximum items allowed in each column
|
| 307 |
+
"""
|
| 308 |
+
|
| 309 |
+
# WATERFALL SPECIFIC
|
| 310 |
+
elif "waterfall" in question_lower:
|
| 311 |
+
return """
|
| 312 |
+
## π§ Waterfall Methodology
|
| 313 |
+
|
| 314 |
+
### Phases of Waterfall
|
| 315 |
+
1. **Requirements Analysis**: Document all requirements upfront
|
| 316 |
+
2. **Design**: Create system architecture and design specifications
|
| 317 |
+
3. **Implementation**: Build the system according to design
|
| 318 |
+
4. **Testing**: Verify system meets requirements
|
| 319 |
+
5. **Deployment**: Release to production
|
| 320 |
+
6. **Maintenance**: Ongoing support and fixes
|
| 321 |
+
|
| 322 |
+
### When to Use Waterfall
|
| 323 |
+
- Requirements are clear and stable
|
| 324 |
+
- Project is simple and well-understood
|
| 325 |
+
- Regulatory/compliance needs extensive documentation
|
| 326 |
+
- Fixed budget and timeline are critical
|
| 327 |
+
"""
|
| 328 |
+
|
| 329 |
+
# BABOK SPECIFIC
|
| 330 |
+
elif "babok" in question_lower:
|
| 331 |
+
return """
|
| 332 |
+
## π BABOK Guide (Business Analysis Body of Knowledge)
|
| 333 |
+
|
| 334 |
+
### Six Knowledge Areas
|
| 335 |
+
| **Knowledge Area** | **Description** |
|
| 336 |
+
|-------------------|-----------------|
|
| 337 |
+
| **1. Business Analysis Planning & Monitoring** | Planning BA approach, stakeholder engagement |
|
| 338 |
+
| **2. Elicitation & Collaboration** | Gathering requirements from stakeholders |
|
| 339 |
+
| **3. Requirements Life Cycle Management** | Managing requirements throughout the project |
|
| 340 |
+
| **4. Strategy Analysis** | Understanding business needs and context |
|
| 341 |
+
| **5. Requirements Analysis & Design Definition** | Structuring and validating requirements |
|
| 342 |
+
| **6. Solution Evaluation** | Assessing solution performance and value |
|
| 343 |
+
|
| 344 |
+
### Certification Levels
|
| 345 |
+
| **Certification** | **Experience** | **Target** |
|
| 346 |
+
|-------------------|---------------|------------|
|
| 347 |
+
| **ECBA** (Entry) | None | New to BA field |
|
| 348 |
+
| **CCBA** (Capability) | 2-3 years | Experienced practitioners |
|
| 349 |
+
| **CBAP** (Professional) | 5+ years | Senior BAs and leaders |
|
| 350 |
+
"""
|
| 351 |
+
|
| 352 |
+
# STAKEHOLDER SPECIFIC
|
| 353 |
+
elif "stakeholder" in question_lower:
|
| 354 |
+
return """
|
| 355 |
+
## π₯ Stakeholder Management
|
| 356 |
+
|
| 357 |
+
### Stakeholder Identification
|
| 358 |
+
**Internal Stakeholders:**
|
| 359 |
+
- Project Sponsor, Product Owner, Team Members, Department Managers
|
| 360 |
+
|
| 361 |
+
**External Stakeholders:**
|
| 362 |
+
- Customers, Vendors, Regulators, Partners
|
| 363 |
+
|
| 364 |
+
### Power-Interest Grid
|
| 365 |
+
- **High Power, High Interest**: Manage closely (sponsors, key customers)
|
| 366 |
+
- **High Power, Low Interest**: Keep satisfied (executives, regulators)
|
| 367 |
+
- **Low Power, High Interest**: Keep informed (end users, SMEs)
|
| 368 |
+
- **Low Power, Low Interest**: Monitor (general staff)
|
| 369 |
+
|
| 370 |
+
### RACI Matrix
|
| 371 |
+
- **R** = Responsible (does the work)
|
| 372 |
+
- **A** = Accountable (approves)
|
| 373 |
+
- **C** = Consulted (provides input)
|
| 374 |
+
- **I** = Informed (receives updates)
|
| 375 |
+
"""
|
| 376 |
+
|
| 377 |
+
# REQUIREMENTS SPECIFIC
|
| 378 |
+
elif "requirement" in question_lower or "gathering" in question_lower:
|
| 379 |
+
return """
|
| 380 |
+
## π Requirements Engineering
|
| 381 |
+
|
| 382 |
+
### Types of Requirements
|
| 383 |
+
| **Type** | **Description** | **Example** |
|
| 384 |
+
|----------|-----------------|-------------|
|
| 385 |
+
| **Business Requirements** | High-level organizational needs | "Increase customer satisfaction by 20%" |
|
| 386 |
+
| **User Requirements** | What users need to do | "Users need to reset password easily" |
|
| 387 |
+
| **Functional Requirements** | What system must do | "System shall send password reset email" |
|
| 388 |
+
| **Non-Functional Requirements** | Quality attributes | "System shall respond within 2 seconds" |
|
| 389 |
+
|
| 390 |
+
### Elicitation Techniques
|
| 391 |
+
- **Interviews**: One-on-one discussions with stakeholders
|
| 392 |
+
- **Workshops**: Collaborative sessions with multiple stakeholders
|
| 393 |
+
- **Surveys**: Gather input from large groups
|
| 394 |
+
- **Observation**: Understand current workflows
|
| 395 |
+
- **Document Analysis**: Review existing documentation
|
| 396 |
+
"""
|
| 397 |
+
|
| 398 |
+
# TRACEABILITY SPECIFIC
|
| 399 |
+
elif "traceability" in question_lower or "rtm" in question_lower:
|
| 400 |
+
return """
|
| 401 |
+
## π Requirements Traceability
|
| 402 |
+
|
| 403 |
+
### What is Traceability?
|
| 404 |
+
The ability to track requirements throughout the project lifecycleβfrom origin to delivery.
|
| 405 |
+
|
| 406 |
+
### Traceability Matrix (RTM)
|
| 407 |
+
| **Req ID** | **Requirement** | **Source** | **Design** | **Test Case** | **Status** |
|
| 408 |
+
|------------|-----------------|------------|------------|---------------|------------|
|
| 409 |
+
| REQ-001 | User login | Stakeholder interview | UI-101 | TC-201 | β
Done |
|
| 410 |
+
|
| 411 |
+
### Why Traceability Matters
|
| 412 |
+
| **Scenario** | **Without Traceability** | **With Traceability** |
|
| 413 |
+
|--------------|-------------------------|----------------------|
|
| 414 |
+
| Regulatory audit | 3 months preparation | 3 days with documentation |
|
| 415 |
+
| Requirement change | 2 weeks impact analysis | 2 hours automated |
|
| 416 |
+
"""
|
| 417 |
+
|
| 418 |
+
# BANKING/FINANCIAL SPECIFIC
|
| 419 |
+
elif "banking" in question_lower or "financial" in question_lower:
|
| 420 |
+
return """
|
| 421 |
+
## π¦ Banking & Financial Services
|
| 422 |
+
|
| 423 |
+
### Key Regulations
|
| 424 |
+
| **Regulation** | **Region** | **Impact** |
|
| 425 |
+
|----------------|------------|------------|
|
| 426 |
+
| **Basel III/IV** | Global | Capital adequacy, risk management |
|
| 427 |
+
| **SOX** | US | Internal controls, audit trails |
|
| 428 |
+
| **PSD2/Open Banking** | EU | API requirements, customer data access |
|
| 429 |
+
|
| 430 |
+
### Common Projects
|
| 431 |
+
- Core banking transformation
|
| 432 |
+
- Payment systems
|
| 433 |
+
- Mobile banking apps
|
| 434 |
+
- Regulatory reporting
|
| 435 |
+
|
| 436 |
+
### Sample Requirements
|
| 437 |
+
REQ-BANK-001: System shall enforce dual control for transactions > $1M
|
| 438 |
+
REQ-BANK-002: All user actions shall be logged with timestamp and user ID
|
| 439 |
+
"""
|
| 440 |
+
|
| 441 |
+
# HEALTHCARE SPECIFIC
|
| 442 |
+
elif "healthcare" in question_lower or "hipaa" in question_lower:
|
| 443 |
+
return """
|
| 444 |
+
## π₯ Healthcare IT
|
| 445 |
+
|
| 446 |
+
### Key Regulations
|
| 447 |
+
| **Regulation** | **Scope** | **BA Impact** |
|
| 448 |
+
|----------------|-----------|---------------|
|
| 449 |
+
| **HIPAA** | US | Privacy, security, patient data |
|
| 450 |
+
| **FDA 21 CFR Part 11** | US | Medical device software validation |
|
| 451 |
+
| **HL7/FHIR** | Global | Healthcare data interoperability |
|
| 452 |
+
|
| 453 |
+
### Sample Requirements
|
| 454 |
+
REQ-HC-001: System shall encrypt all PHI at rest and in transit
|
| 455 |
+
REQ-HC-002: User sessions shall timeout after 15 minutes of inactivity
|
| 456 |
+
REQ-HC-003: System shall support HL7 v2.x messages for ADT feeds
|
| 457 |
+
"""
|
| 458 |
+
|
| 459 |
+
# RETAIL SPECIFIC
|
| 460 |
+
elif "retail" in question_lower or "e-commerce" in question_lower:
|
| 461 |
+
return """
|
| 462 |
+
## ποΈ Retail & E-commerce
|
| 463 |
+
|
| 464 |
+
### Key Industry Trends
|
| 465 |
+
- **Omnichannel**: Unified experience across channels
|
| 466 |
+
- **Personalization**: Tailored customer experience
|
| 467 |
+
- **Mobile Commerce**: App-based shopping
|
| 468 |
+
|
| 469 |
+
### Sample Requirements
|
| 470 |
+
REQ-RT-001: System shall support BOPIS (Buy Online, Pickup In Store)
|
| 471 |
+
REQ-RT-002: Inventory levels shall update in real-time across all channels
|
| 472 |
+
REQ-RT-003: Customer profiles shall be unified across online and in-store
|
| 473 |
+
"""
|
| 474 |
+
|
| 475 |
+
# BUSINESS CASE SPECIFIC
|
| 476 |
+
elif "business case" in question_lower:
|
| 477 |
+
return """
|
| 478 |
+
## πΌ Business Case Development
|
| 479 |
+
|
| 480 |
+
### What is a Business Case?
|
| 481 |
+
A business case provides justification for initiating a project or task. It presents the benefits, costs, and risks of various options.
|
| 482 |
+
|
| 483 |
+
### Business Case Structure
|
| 484 |
+
| **Section** | **Description** |
|
| 485 |
+
|-------------|-----------------|
|
| 486 |
+
| **Executive Summary** | Brief overview of the proposal |
|
| 487 |
+
| **Problem Statement** | Current issues and opportunities |
|
| 488 |
+
| **Options Analysis** | Evaluation of possible solutions |
|
| 489 |
+
| **Cost-Benefit Analysis** | Financial justification |
|
| 490 |
+
| **Risk Assessment** | Potential risks and mitigation |
|
| 491 |
+
| **Recommendation** | Proposed solution with rationale |
|
| 492 |
+
|
| 493 |
+
### Key Metrics
|
| 494 |
+
- **ROI** (Return on Investment)
|
| 495 |
+
- **NPV** (Net Present Value)
|
| 496 |
+
- **Payback Period**
|
| 497 |
+
- **IRR** (Internal Rate of Return)
|
| 498 |
+
"""
|
| 499 |
+
|
| 500 |
+
# SWOT ANALYSIS SPECIFIC
|
| 501 |
+
elif "swot" in question_lower:
|
| 502 |
+
return """
|
| 503 |
+
## π SWOT Analysis
|
| 504 |
+
|
| 505 |
+
### What is SWOT?
|
| 506 |
+
SWOT is a strategic planning technique used to identify Strengths, Weaknesses, Opportunities, and Threats.
|
| 507 |
+
|
| 508 |
+
### SWOT Matrix
|
| 509 |
+
| **Positive** | **Negative** |
|
| 510 |
+
|--------------|--------------|
|
| 511 |
+
| **Strengths** (Internal) | **Weaknesses** (Internal) |
|
| 512 |
+
| β’ Unique capabilities | β’ Resource gaps |
|
| 513 |
+
| β’ Competitive advantages | β’ Skill deficiencies |
|
| 514 |
+
| β’ Valuable assets | β’ Process inefficiencies |
|
| 515 |
+
| **Opportunities** (External) | **Threats** (External) |
|
| 516 |
+
| β’ Market growth | β’ New competitors |
|
| 517 |
+
| β’ Emerging technologies | β’ Regulatory changes |
|
| 518 |
+
| β’ Strategic partnerships | β’ Economic downturns |
|
| 519 |
+
|
| 520 |
+
### How to Use SWOT
|
| 521 |
+
1. List internal strengths and weaknesses
|
| 522 |
+
2. Identify external opportunities and threats
|
| 523 |
+
3. Develop strategies that:
|
| 524 |
+
- Leverage strengths to capture opportunities
|
| 525 |
+
- Address weaknesses to mitigate threats
|
| 526 |
+
"""
|
| 527 |
+
|
| 528 |
+
# PESTLE ANALYSIS SPECIFIC
|
| 529 |
+
elif "pestle" in question_lower:
|
| 530 |
+
return """
|
| 531 |
+
## π PESTLE Analysis
|
| 532 |
+
|
| 533 |
+
### What is PESTLE?
|
| 534 |
+
PESTLE analyzes external factors affecting an organization: Political, Economic, Social, Technological, Legal, Environmental.
|
| 535 |
+
|
| 536 |
+
### PESTLE Framework
|
| 537 |
+
| **Factor** | **Examples** |
|
| 538 |
+
|------------|--------------|
|
| 539 |
+
| **Political** | Government policies, trade restrictions, tax policies |
|
| 540 |
+
| **Economic** | Inflation, interest rates, economic growth |
|
| 541 |
+
| **Social** | Demographics, cultural trends, lifestyle changes |
|
| 542 |
+
| **Technological** | Automation, R&D, technology innovation |
|
| 543 |
+
| **Legal** | Employment laws, health & safety, regulations |
|
| 544 |
+
| **Environmental** | Climate change, sustainability, carbon footprint |
|
| 545 |
+
|
| 546 |
+
### When to Use PESTLE
|
| 547 |
+
- Strategic planning
|
| 548 |
+
- Market entry decisions
|
| 549 |
+
- New product development
|
| 550 |
+
- Business transformation projects
|
| 551 |
+
"""
|
| 552 |
+
|
| 553 |
+
# GAP ANALYSIS SPECIFIC
|
| 554 |
+
elif "gap analysis" in question_lower:
|
| 555 |
+
return """
|
| 556 |
+
## π Gap Analysis
|
| 557 |
+
|
| 558 |
+
### What is Gap Analysis?
|
| 559 |
+
Gap analysis compares current state with desired future state to identify what's missing.
|
| 560 |
+
|
| 561 |
+
### Gap Analysis Process
|
| 562 |
+
1. **Define Current State**: Document existing processes, capabilities, performance
|
| 563 |
+
2. **Define Future State**: Describe desired outcomes and objectives
|
| 564 |
+
3. **Identify Gaps**: List what's missing or needs improvement
|
| 565 |
+
4. **Develop Action Plan**: Create initiatives to close gaps
|
| 566 |
+
|
| 567 |
+
### Gap Analysis Framework
|
| 568 |
+
| **Area** | **Current State** | **Future State** | **Gap** | **Action** |
|
| 569 |
+
|----------|-------------------|------------------|---------|------------|
|
| 570 |
+
| Process | Manual data entry | Automated workflow | Automation missing | Implement RPA |
|
| 571 |
+
| Skills | Basic Excel | Advanced analytics | Training needed | Upskill team |
|
| 572 |
+
| Technology | Legacy system | Cloud platform | Migration required | Cloud strategy |
|
| 573 |
+
"""
|
| 574 |
+
|
| 575 |
+
# REQUIREMENTS PRIORITIZATION SPECIFIC
|
| 576 |
+
elif "prioritization" in question_lower or "mosco w" in question_lower:
|
| 577 |
+
return """
|
| 578 |
+
## βοΈ Requirements Prioritization
|
| 579 |
+
|
| 580 |
+
### MoSCoW Method
|
| 581 |
+
| **Priority** | **Meaning** | **Description** |
|
| 582 |
+
|--------------|-------------|-----------------|
|
| 583 |
+
| **M**ust have | Critical | Non-negotiable requirements |
|
| 584 |
+
| **S**hould have | Important | High priority but can wait |
|
| 585 |
+
| **C**ould have | Nice to have | Desirable if time permits |
|
| 586 |
+
| **W**on't have | Out of scope | Explicitly excluded for now |
|
| 587 |
+
|
| 588 |
+
### Other Prioritization Techniques
|
| 589 |
+
| **Technique** | **Description** | **Best For** |
|
| 590 |
+
|---------------|-----------------|--------------|
|
| 591 |
+
| **Kano Model** | Classifies features as Basic, Performance, or Delighters | Customer satisfaction |
|
| 592 |
+
| **Value vs Effort** | Plot requirements on value/effort matrix | Quick wins identification |
|
| 593 |
+
| **100-Point Method** | Stakeholders allocate 100 points across requirements | Group consensus |
|
| 594 |
+
| **Pairwise Comparison** | Compare requirements in pairs | Detailed analysis |
|
| 595 |
+
"""
|
| 596 |
+
|
| 597 |
+
# GENERIC RESPONSE
|
| 598 |
+
else:
|
| 599 |
+
cats = ', '.join(categories) if categories else 'General BA'
|
| 600 |
+
topics = ', '.join(keywords[:3]) if keywords else 'BA concepts'
|
| 601 |
+
|
| 602 |
+
return f"""
|
| 603 |
+
## π Business Analysis Information
|
| 604 |
+
|
| 605 |
+
**Categories:** {cats}
|
| 606 |
+
**Topics:** {topics}
|
| 607 |
+
|
| 608 |
+
### Quick Reference
|
| 609 |
+
- **Core Concepts**: Requirements, stakeholders, scope, value, business case, SWOT, PESTLE
|
| 610 |
+
- **Methodologies**: Agile, Scrum, Waterfall, BABOK, Kanban
|
| 611 |
+
- **Domains**: Banking, Healthcare, Retail, Supply Chain
|
| 612 |
+
|
| 613 |
+
### Popular BA Techniques
|
| 614 |
+
- **MoSCoW Prioritization**: Must/Should/Could/Won't
|
| 615 |
+
- **SWOT Analysis**: Strengths/Weaknesses/Opportunities/Threats
|
| 616 |
+
- **PESTLE**: Political/Economic/Social/Technological/Legal/Environmental
|
| 617 |
+
- **Gap Analysis**: Current vs Future state
|
| 618 |
+
- **Business Case**: ROI, NPV, Payback period
|
| 619 |
+
|
| 620 |
+
### Ask for More Details
|
| 621 |
+
Try specific questions like:
|
| 622 |
+
- "Explain Scrum roles and events"
|
| 623 |
+
- "What is the difference between Agile and Waterfall?"
|
| 624 |
+
- "How to create a traceability matrix?"
|
| 625 |
+
- "Banking regulations for BAs"
|
| 626 |
+
- "Healthcare compliance requirements (HIPAA)"
|
| 627 |
+
- "How to create a business case?"
|
| 628 |
+
- "Explain SWOT analysis"
|
| 629 |
+
- "What is PESTLE analysis?"
|
| 630 |
+
- "How to prioritize requirements with MoSCoW?"
|
| 631 |
+
"""
|
| 632 |
+
|
| 633 |
+
# ---------------------------
|
| 634 |
+
# Main Function
|
| 635 |
+
# ---------------------------
|
| 636 |
+
def ask_ba_assistant(question: str) -> str:
|
| 637 |
+
"""Main function to handle BA queries"""
|
| 638 |
+
|
| 639 |
+
question = question.strip()
|
| 640 |
+
|
| 641 |
+
if not question:
|
| 642 |
+
return "Please enter a question about IT-Business Analysis."
|
| 643 |
+
|
| 644 |
+
# Check if BA-related
|
| 645 |
+
is_related, keywords, categories = is_ba_related(question)
|
| 646 |
+
|
| 647 |
+
if not is_related:
|
| 648 |
+
return """β I specialize in IT-Business Analysis topics only.
|
| 649 |
+
|
| 650 |
+
### β
Try Asking About:
|
| 651 |
+
β’ What is requirements gathering?
|
| 652 |
+
β’ How to manage stakeholders?
|
| 653 |
+
β’ Explain Agile methodology
|
| 654 |
+
β’ Banking domain analysis
|
| 655 |
+
β’ Healthcare IT requirements
|
| 656 |
+
β’ How to create a business case?
|
| 657 |
+
β’ Explain SWOT analysis
|
| 658 |
+
β’ What is PESTLE analysis?
|
| 659 |
+
β’ How to prioritize requirements with MoSCoW?
|
| 660 |
+
"""
|
| 661 |
+
|
| 662 |
+
# Try DeepSeek if available
|
| 663 |
+
if DEEPSEEK_AVAILABLE:
|
| 664 |
+
logger.info(f"Attempting DeepSeek for: {question}")
|
| 665 |
+
ai_response = get_deepseek_response(question)
|
| 666 |
+
if ai_response:
|
| 667 |
+
return ai_response + "\n\n---\n*Powered by DeepSeek AI Free Tier*"
|
| 668 |
+
else:
|
| 669 |
+
logger.info("DeepSeek failed, falling back to local templates")
|
| 670 |
+
|
| 671 |
+
# Fallback to local templates
|
| 672 |
+
response = get_local_response(question, keywords, categories)
|
| 673 |
+
return response + "\n\n---\n*Professional Knowledge Base*"
|
| 674 |
+
|
| 675 |
+
# ---------------------------
|
| 676 |
+
# Build Interface
|
| 677 |
+
# ---------------------------
|
| 678 |
+
def build_app():
|
| 679 |
+
"""Build the Gradio interface"""
|
| 680 |
+
|
| 681 |
+
if DEEPSEEK_AVAILABLE:
|
| 682 |
+
status = "π’ DEEPSEEK AI ACTIVE"
|
| 683 |
+
status_detail = "Using DeepSeek Free Tier (5M tokens/month)"
|
| 684 |
+
else:
|
| 685 |
+
status = "π‘ LOCAL TEMPLATES"
|
| 686 |
+
status_detail = DEEPSEEK_ERROR if DEEPSEEK_ERROR else "No API key configured"
|
| 687 |
+
|
| 688 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 689 |
+
gr.Markdown(f"""
|
| 690 |
+
<div style='text-align:center;'>
|
| 691 |
+
<h1>π Professional IT Business Analysis Assistant</h1>
|
| 692 |
+
<p><i>AI-powered guide for BA concepts and business domains</i></p>
|
| 693 |
+
<p>Version 3.0.0 | Mode: {status}</p>
|
| 694 |
+
<p style='font-size:0.9em; color:#666;'>{status_detail}</p>
|
| 695 |
+
</div>
|
| 696 |
+
""")
|
| 697 |
+
|
| 698 |
+
with gr.Row():
|
| 699 |
+
with gr.Column(scale=2):
|
| 700 |
+
question = gr.Textbox(
|
| 701 |
+
label="Ask your BA question",
|
| 702 |
+
placeholder="e.g., How to manage stakeholders? What is requirements traceability? Explain SWOT analysis",
|
| 703 |
+
lines=3
|
| 704 |
+
)
|
| 705 |
+
submit_btn = gr.Button("π Get Guidance", variant="primary", size="lg")
|
| 706 |
+
|
| 707 |
+
with gr.Column(scale=3):
|
| 708 |
+
output = gr.Textbox(
|
| 709 |
+
label="Response",
|
| 710 |
+
lines=20,
|
| 711 |
+
interactive=False,
|
| 712 |
+
show_copy_button=True
|
| 713 |
+
)
|
| 714 |
+
|
| 715 |
+
gr.Examples(
|
| 716 |
+
examples=[
|
| 717 |
+
["How to manage stakeholders?"],
|
| 718 |
+
["What is requirements traceability?"],
|
| 719 |
+
["Explain Agile methodology"],
|
| 720 |
+
["Banking domain analysis techniques"],
|
| 721 |
+
["Healthcare compliance requirements"],
|
| 722 |
+
["How to create a business case?"],
|
| 723 |
+
["Explain SWOT analysis"],
|
| 724 |
+
["What is PESTLE analysis?"],
|
| 725 |
+
["How to prioritize requirements with MoSCoW?"]
|
| 726 |
+
],
|
| 727 |
+
inputs=question
|
| 728 |
+
)
|
| 729 |
+
|
| 730 |
+
submit_btn.click(fn=ask_ba_assistant, inputs=question, outputs=output)
|
| 731 |
+
|
| 732 |
+
return demo
|
| 733 |
+
|
| 734 |
+
# ---------------------------
|
| 735 |
+
# Launch
|
| 736 |
+
# ---------------------------
|
| 737 |
+
if __name__ == "__main__":
|
| 738 |
+
demo = build_app()
|
| 739 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|