Amrith2k6 commited on
Commit
0109c0e
Β·
verified Β·
1 Parent(s): 5b3b2da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +233 -189
app.py CHANGED
@@ -1,6 +1,5 @@
1
  """
2
- IT-Business Analysis Assistant - Professional Hybrid Version
3
- Uses DeepSeek API Free Tier (5M tokens/month)
4
  """
5
 
6
  import os
@@ -10,7 +9,6 @@ import logging
10
  import requests
11
  from pathlib import Path
12
  from typing import Tuple, List, Dict, Any, Optional
13
- from datetime import datetime
14
 
15
  import gradio as gr
16
  from dotenv import load_dotenv
@@ -28,58 +26,43 @@ logger = logging.getLogger(__name__)
28
  class Config:
29
  """Application configuration"""
30
 
31
- # Paths
32
  BASE_DIR = Path(__file__).resolve().parent
33
  DATA_DIR = BASE_DIR / "data"
34
- ASSETS_DIR = BASE_DIR / "assets"
35
-
36
- # Files
37
  KEYWORDS_FILE = DATA_DIR / "ba_keywords.json"
 
38
 
39
- # Keyword Detection
40
- KEYWORD_MATCH_THRESHOLD = 0.8
41
-
42
- # App Info
43
  APP_NAME = "Professional IT Business Analysis Assistant"
44
  APP_VERSION = "3.0.0"
45
  APP_DESCRIPTION = "AI-powered guide for BA concepts and business domains"
46
 
47
- # DeepSeek API Configuration - FREE TIER
48
  DEEPSEEK_API_KEY = os.getenv("DEEPSEEK_API_KEY", "")
49
  DEEPSEEK_BASE_URL = "https://api.deepseek.com/v1"
50
- DEEPSEEK_MODEL = "deepseek-chat" # Free tier accessible model
51
 
52
  # ---------------------------
53
- # Initialize DeepSeek (if key available)
54
  # ---------------------------
55
  DEEPSEEK_AVAILABLE = False
56
-
57
- if Config.DEEPSEEK_API_KEY:
58
- try:
59
- # Simple validation - just check if key exists and format is valid
60
- if len(Config.DEEPSEEK_API_KEY) > 20: # Basic sanity check
61
- DEEPSEEK_AVAILABLE = True
62
- logger.info("βœ… DeepSeek API configured - FREE TIER ACTIVE (5M tokens/month)")
63
- else:
64
- logger.warning("⚠️ DeepSeek API key appears invalid")
65
- except Exception as e:
66
- logger.warning(f"⚠️ DeepSeek initialization failed: {e}")
67
  else:
68
- logger.info("πŸ“š No DeepSeek API key - using local templates only")
69
 
70
  # ---------------------------
71
  # Load BA Keywords
72
  # ---------------------------
73
  def load_ba_keywords() -> Dict[str, List[str]]:
74
  """Load BA keywords from JSON file"""
75
-
76
  try:
 
 
 
 
77
  with open(Config.KEYWORDS_FILE, 'r', encoding='utf-8') as f:
78
  data = json.load(f)
79
- ba_keywords = data.get('categories', {})
80
- total_keywords = sum(len(v) for v in ba_keywords.values())
81
- logger.info(f"βœ… Loaded {total_keywords} BA keywords")
82
- return ba_keywords
83
  except Exception as e:
84
  logger.error(f"Error loading keywords: {e}")
85
  return get_default_ba_keywords()
@@ -89,92 +72,40 @@ def get_default_ba_keywords() -> Dict[str, List[str]]:
89
  return {
90
  "Core Concepts": [
91
  "business analysis", "requirements gathering", "stakeholder analysis",
92
- "business needs", "solution assessment", "value proposition"
 
93
  ],
94
  "Methodologies": [
95
- "agile", "scrum", "kanban", "waterfall", "babok"
 
96
  ],
97
  "Requirements": [
98
- "functional requirements", "non-functional requirements", "srs", "brd"
 
 
99
  ],
100
  "Business Domains": [
101
- "financial services", "banking", "healthcare", "retail", "supply chain"
 
102
  ]
103
  }
104
 
105
- # Load BA keywords
106
  BA_KEYWORDS = load_ba_keywords()
107
 
108
- # Flatten keywords for detection
109
  ALL_KEYWORDS = []
110
  for category, keywords in BA_KEYWORDS.items():
111
  ALL_KEYWORDS.extend(keywords)
112
- ALL_KEYWORDS = list(set(ALL_KEYWORDS))
113
- logger.info(f"πŸ“Š Total unique keywords: {len(ALL_KEYWORDS)}")
114
 
115
  # ---------------------------
116
- # Professional Templates (Local Fallback)
117
  # ---------------------------
118
- PROFESSIONAL_TEMPLATES = {
119
- "traceability": """
120
- ## πŸ” Requirements Traceability: Professional BA Guide
121
-
122
- ### Business Value of Traceability
123
- Traceability is about managing complexity and reducing risk.
124
-
125
- ### Industry-Specific Examples
126
-
127
- **Healthcare (FDA)**
128
- Requirement: "System shall lock after 3 failed attempts"
129
- Design: Login screen with counter
130
- Code: LoginModule.java lines 45-67
131
- Test: Verify lockout after 3 attempts
132
- Audit: Trace to 21 CFR Part 11
133
-
134
- **Financial Services (SOX)**
135
- Control: "Segregation of duties"
136
- Requirement: Different users for create/approve
137
- Design: Role-based access control
138
- Test: Verify cannot self-approve
139
- Audit: User access reports
140
- """,
141
- "stakeholder": """
142
- ## πŸ‘₯ Professional Stakeholder Management
143
-
144
- ### Power-Interest Grid
145
-
146
- HIGH POWER, LOW INTEREST (Keep Satisfied)
147
- β€’ CFO: Monthly reports
148
- β€’ Legal: Quarterly reviews
149
-
150
- HIGH POWER, HIGH INTEREST (Manage Closely)
151
- β€’ Sponsor: Weekly steering
152
- β€’ Product Owner: Daily sync
153
-
154
- LOW POWER, LOW INTEREST (Monitor)
155
- β€’ IT Support: As needed
156
- β€’ Vendors: Contract reviews
157
-
158
- LOW POWER, HIGH INTEREST (Keep Informed)
159
- β€’ End Users: Demos, UAT
160
- β€’ SMEs: Workshops
161
-
162
- ### RACI Matrix Template
163
-
164
- | Activity | Sponsor | PO | BA | Dev | QA |
165
- |----------|---------|-----|-----|-----|-----|
166
- | Requirements | A | R | R | C | C |
167
- | UAT | A | C | R | I | C |
168
- """
169
- }
170
-
171
- # ---------------------------
172
- # Keyword Detection
173
- # ---------------------------
174
- def detect_ba_topics(question: str) -> Tuple[bool, List[str], List[str]]:
175
  """
176
- Detect if question contains BA-related keywords
177
- Returns: (is_related, matched_keywords, matched_categories)
178
  """
179
  if not question or not question.strip():
180
  return False, [], []
@@ -183,50 +114,42 @@ def detect_ba_topics(question: str) -> Tuple[bool, List[str], List[str]]:
183
  matched_keywords = []
184
  matched_categories = set()
185
 
186
- # Check for exact matches
187
  for keyword in ALL_KEYWORDS:
188
- if keyword.lower() in question_lower:
189
  matched_keywords.append(keyword)
 
190
  for cat, keys in BA_KEYWORDS.items():
191
- if keyword.lower() in [k.lower() for k in keys]:
192
  matched_categories.add(cat)
 
193
 
194
- # Fuzzy matching for typos
195
  words = question_lower.split()
196
- for keyword in ALL_KEYWORDS:
197
- matches = difflib.get_close_matches(keyword.lower(), words, cutoff=Config.KEYWORD_MATCH_THRESHOLD)
198
- if matches and keyword not in matched_keywords:
199
- matched_keywords.append(keyword)
 
 
 
 
 
 
200
 
201
  is_related = len(matched_keywords) > 0
202
- return is_related, matched_keywords[:5], list(matched_categories)
203
 
204
  # ---------------------------
205
- # DeepSeek AI Response (Free Tier)
206
  # ---------------------------
207
- def get_deepseek_response(question: str, keywords: List[str], categories: List[str]) -> Optional[str]:
208
- """Get AI response using DeepSeek FREE TIER (5M tokens/month)"""
209
 
210
  if not DEEPSEEK_AVAILABLE:
211
  return None
212
 
213
  try:
214
- # Build context
215
- context = f"BA Categories: {', '.join(categories) if categories else 'General BA'}"
216
-
217
- system_prompt = """You are a senior IT Business Analysis consultant. Provide professional, practical advice for business analysts.
218
- Keep responses concise and actionable. Focus on real-world application."""
219
-
220
- user_prompt = f"""Context: {context}
221
-
222
- Question: {question}
223
-
224
- Provide a professional response covering:
225
- 1. Core concepts
226
- 2. Practical application
227
- 3. Best practices"""
228
-
229
- # Prepare API request
230
  url = f"{Config.DEEPSEEK_BASE_URL}/chat/completions"
231
  headers = {
232
  "Authorization": f"Bearer {Config.DEEPSEEK_API_KEY}",
@@ -235,63 +158,173 @@ Provide a professional response covering:
235
  payload = {
236
  "model": Config.DEEPSEEK_MODEL,
237
  "messages": [
238
- {"role": "system", "content": system_prompt},
239
- {"role": "user", "content": user_prompt}
240
  ],
241
  "temperature": 0.7,
242
- "max_tokens": 600, # Keep responses moderate to save tokens
243
- "top_p": 0.9
244
  }
245
 
246
- # Make API call
247
  response = requests.post(url, headers=headers, json=payload, timeout=30)
248
  response.raise_for_status()
249
-
250
  result = response.json()
251
  return result["choices"][0]["message"]["content"]
252
 
253
- except requests.exceptions.RequestException as e:
254
- logger.warning(f"⚠️ DeepSeek API request failed: {e}")
255
  return None
256
 
257
  # ---------------------------
258
  # Local Response
259
  # ---------------------------
260
  def get_local_response(question: str, keywords: List[str], categories: List[str]) -> str:
261
- """Get professional-grade local response"""
262
 
263
  question_lower = question.lower()
264
 
265
- # Check for template matches
266
- if "traceability" in question_lower or "rtm" in question_lower:
267
- return PROFESSIONAL_TEMPLATES["traceability"]
268
- elif "stakeholder" in question_lower:
269
- return PROFESSIONAL_TEMPLATES["stakeholder"]
270
-
271
- # Generic response
272
- return f"""
273
- ## πŸ“Š Professional Business Analysis Guidance
274
 
275
- **Categories:** {', '.join(categories) if categories else 'General BA'}
276
- **Topics:** {', '.join(keywords[:3]) if keywords else 'Business Analysis'}
 
 
277
 
278
- ### Quick Reference
279
-
280
- | **Area** | **Best Practice** |
281
- |----------|------------------|
282
- | **Requirements** | Use multiple elicitation techniques. Validate with stakeholders. |
283
- | **Stakeholders** | Map influence early. Communicate regularly. |
284
- | **Methodology** | Choose based on project context and constraints. |
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
285
 
286
- ### πŸ“š Recommended Resources
287
- - BABOK Guide v3 - IIBA
288
- - PMI-PBA Certification - PMI
289
 
290
- *For more specific guidance, please provide additional context.*
 
 
 
 
 
 
 
 
 
291
  """
292
 
293
  # ---------------------------
294
- # Main Query Function
295
  # ---------------------------
296
  def ask_ba_assistant(question: str) -> str:
297
  """Main function to handle BA queries"""
@@ -301,46 +334,59 @@ def ask_ba_assistant(question: str) -> str:
301
  if not question:
302
  return "Please enter a question about IT-Business Analysis."
303
 
304
- # Detect BA topics
305
- is_related, keywords, categories = detect_ba_topics(question)
306
 
307
  if not is_related:
308
  return """❌ I specialize in IT-Business Analysis topics only.
309
 
310
- **Try asking about:**
311
- β€’ Core Concepts (requirements, stakeholders)
312
- β€’ Methodologies (Agile, Scrum, BABOK)
313
- β€’ Business Domains (Banking, Healthcare, Retail)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
314
  """
315
 
316
- # Try DeepSeek AI first (FREE TIER)
317
  if DEEPSEEK_AVAILABLE:
318
- ai_response = get_deepseek_response(question, keywords, categories)
319
  if ai_response:
320
- return ai_response + "\n\n---\n*Powered by DeepSeek AI Free Tier (5M tokens/month)*"
321
 
322
  # Fallback to local templates
323
  response = get_local_response(question, keywords, categories)
324
- status = "πŸ“š Professional Templates" if not DEEPSEEK_AVAILABLE else "⚠️ Using Templates (API unavailable)"
325
-
326
- return response + f"\n\n---\n*{status}*"
327
 
328
  # ---------------------------
329
- # Build Gradio Interface
330
  # ---------------------------
331
  def build_app():
332
  """Build the Gradio interface"""
333
 
334
- status = "🟒 DEEPSEEK FREE TIER" if DEEPSEEK_AVAILABLE else "🟑 LOCAL TEMPLATES"
335
 
336
- with gr.Blocks(theme=gr.themes.Soft(), title=Config.APP_NAME) as demo:
337
-
338
  gr.Markdown(f"""
339
  <div style='text-align:center;'>
340
- <h1>πŸ“Š {Config.APP_NAME}</h1>
341
- <p><i>{Config.APP_DESCRIPTION}</i></p>
342
- <p>Version {Config.APP_VERSION} | Mode: {status}</p>
343
- { "🎁 5M Free Tokens/month" if DEEPSEEK_AVAILABLE else "" }
344
  </div>
345
  """)
346
 
@@ -348,7 +394,7 @@ def build_app():
348
  with gr.Column(scale=2):
349
  question = gr.Textbox(
350
  label="Ask your BA question",
351
- placeholder="E.g., What is requirements traceability?",
352
  lines=3
353
  )
354
  submit_btn = gr.Button("πŸ” Get Guidance", variant="primary")
@@ -363,9 +409,11 @@ def build_app():
363
 
364
  gr.Examples(
365
  examples=[
366
- ["What is requirements traceability in healthcare projects?"],
367
- ["How to manage difficult stakeholders?"],
368
- ["BA techniques for banking projects"]
 
 
369
  ],
370
  inputs=question
371
  )
@@ -375,12 +423,8 @@ def build_app():
375
  return demo
376
 
377
  # ---------------------------
378
- # Launch App
379
  # ---------------------------
380
  if __name__ == "__main__":
381
  demo = build_app()
382
- demo.launch(
383
- server_name=os.getenv("GRADIO_SERVER_NAME", "0.0.0.0"),
384
- server_port=int(os.getenv("GRADIO_SERVER_PORT", "7860")),
385
- share=False
386
- )
 
1
  """
2
+ IT-Business Analysis Assistant - Professional Version
 
3
  """
4
 
5
  import os
 
9
  import requests
10
  from pathlib import Path
11
  from typing import Tuple, List, Dict, Any, Optional
 
12
 
13
  import gradio as gr
14
  from dotenv import load_dotenv
 
26
  class Config:
27
  """Application configuration"""
28
 
 
29
  BASE_DIR = Path(__file__).resolve().parent
30
  DATA_DIR = BASE_DIR / "data"
 
 
 
31
  KEYWORDS_FILE = DATA_DIR / "ba_keywords.json"
32
+ KEYWORD_MATCH_THRESHOLD = 0.7 # Lowered for better matching
33
 
 
 
 
 
34
  APP_NAME = "Professional IT Business Analysis Assistant"
35
  APP_VERSION = "3.0.0"
36
  APP_DESCRIPTION = "AI-powered guide for BA concepts and business domains"
37
 
38
+ # DeepSeek API Configuration
39
  DEEPSEEK_API_KEY = os.getenv("DEEPSEEK_API_KEY", "")
40
  DEEPSEEK_BASE_URL = "https://api.deepseek.com/v1"
41
+ DEEPSEEK_MODEL = "deepseek-chat"
42
 
43
  # ---------------------------
44
+ # Initialize DeepSeek
45
  # ---------------------------
46
  DEEPSEEK_AVAILABLE = False
47
+ if Config.DEEPSEEK_API_KEY and len(Config.DEEPSEEK_API_KEY) > 10:
48
+ DEEPSEEK_AVAILABLE = True
49
+ logger.info("βœ… DeepSeek API configured - FREE TIER ACTIVE")
 
 
 
 
 
 
 
 
50
  else:
51
+ logger.info("πŸ“š Using local templates only")
52
 
53
  # ---------------------------
54
  # Load BA Keywords
55
  # ---------------------------
56
  def load_ba_keywords() -> Dict[str, List[str]]:
57
  """Load BA keywords from JSON file"""
 
58
  try:
59
+ if not Config.KEYWORDS_FILE.exists():
60
+ logger.warning("Keywords file not found, using defaults")
61
+ return get_default_ba_keywords()
62
+
63
  with open(Config.KEYWORDS_FILE, 'r', encoding='utf-8') as f:
64
  data = json.load(f)
65
+ return data.get('categories', get_default_ba_keywords())
 
 
 
66
  except Exception as e:
67
  logger.error(f"Error loading keywords: {e}")
68
  return get_default_ba_keywords()
 
72
  return {
73
  "Core Concepts": [
74
  "business analysis", "requirements gathering", "stakeholder analysis",
75
+ "business case", "scope definition", "gap analysis", "requirements",
76
+ "stakeholder", "business need", "value proposition"
77
  ],
78
  "Methodologies": [
79
+ "agile", "scrum", "kanban", "waterfall", "babok", "bpmn", "uml",
80
+ "user stories", "acceptance criteria"
81
  ],
82
  "Requirements": [
83
+ "functional requirements", "non-functional requirements", "srs", "brd",
84
+ "user stories", "acceptance criteria", "requirements traceability",
85
+ "traceability matrix", "rtm"
86
  ],
87
  "Business Domains": [
88
+ "financial services", "banking", "healthcare", "retail", "supply chain",
89
+ "insurance", "manufacturing", "telecom"
90
  ]
91
  }
92
 
93
+ # Load keywords
94
  BA_KEYWORDS = load_ba_keywords()
95
 
96
+ # Create a simple list of all keywords for matching
97
  ALL_KEYWORDS = []
98
  for category, keywords in BA_KEYWORDS.items():
99
  ALL_KEYWORDS.extend(keywords)
100
+ ALL_KEYWORDS = list(set([k.lower() for k in ALL_KEYWORDS]))
101
+ logger.info(f"πŸ“Š Loaded {len(ALL_KEYWORDS)} keywords")
102
 
103
  # ---------------------------
104
+ # Simple Keyword Detection
105
  # ---------------------------
106
+ def is_ba_related(question: str) -> Tuple[bool, List[str], List[str]]:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  """
108
+ Simple check if question contains BA-related keywords
 
109
  """
110
  if not question or not question.strip():
111
  return False, [], []
 
114
  matched_keywords = []
115
  matched_categories = set()
116
 
117
+ # Simple contains check - no fuzzy matching needed
118
  for keyword in ALL_KEYWORDS:
119
+ if keyword in question_lower:
120
  matched_keywords.append(keyword)
121
+ # Find category
122
  for cat, keys in BA_KEYWORDS.items():
123
+ if any(k.lower() == keyword for k in keys):
124
  matched_categories.add(cat)
125
+ break
126
 
127
+ # Also check individual words for common BA terms
128
  words = question_lower.split()
129
+ ba_terms = ["stakeholder", "requirement", "agile", "scrum", "babok", "banking", "healthcare"]
130
+ for term in ba_terms:
131
+ if term in words or term in question_lower:
132
+ matched_keywords.append(term)
133
+ if term == "stakeholder":
134
+ matched_categories.add("Core Concepts")
135
+ elif term in ["agile", "scrum", "babok"]:
136
+ matched_categories.add("Methodologies")
137
+ elif term in ["banking", "healthcare"]:
138
+ matched_categories.add("Business Domains")
139
 
140
  is_related = len(matched_keywords) > 0
141
+ return is_related, list(set(matched_keywords))[:5], list(matched_categories)
142
 
143
  # ---------------------------
144
+ # Get DeepSeek Response
145
  # ---------------------------
146
+ def get_deepseek_response(question: str) -> Optional[str]:
147
+ """Get response from DeepSeek API"""
148
 
149
  if not DEEPSEEK_AVAILABLE:
150
  return None
151
 
152
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  url = f"{Config.DEEPSEEK_BASE_URL}/chat/completions"
154
  headers = {
155
  "Authorization": f"Bearer {Config.DEEPSEEK_API_KEY}",
 
158
  payload = {
159
  "model": Config.DEEPSEEK_MODEL,
160
  "messages": [
161
+ {"role": "system", "content": "You are a senior IT Business Analysis consultant. Provide professional, practical advice."},
162
+ {"role": "user", "content": question}
163
  ],
164
  "temperature": 0.7,
165
+ "max_tokens": 800
 
166
  }
167
 
 
168
  response = requests.post(url, headers=headers, json=payload, timeout=30)
169
  response.raise_for_status()
 
170
  result = response.json()
171
  return result["choices"][0]["message"]["content"]
172
 
173
+ except Exception as e:
174
+ logger.warning(f"DeepSeek API error: {e}")
175
  return None
176
 
177
  # ---------------------------
178
  # Local Response
179
  # ---------------------------
180
  def get_local_response(question: str, keywords: List[str], categories: List[str]) -> str:
181
+ """Get response from local templates"""
182
 
183
  question_lower = question.lower()
184
 
185
+ # Check for common topics
186
+ if "stakeholder" in question_lower:
187
+ return """
188
+ ## πŸ‘₯ Stakeholder Management
 
 
 
 
 
189
 
190
+ ### Key Concepts
191
+ - **Stakeholder Identification**: Find all people affected by your project
192
+ - **Stakeholder Analysis**: Assess power, interest, and influence
193
+ - **Engagement Strategies**: Communicate appropriately with each group
194
 
195
+ ### Power-Interest Grid
196
+ - **High Power, High Interest**: Manage closely (sponsors, key customers)
197
+ - **High Power, Low Interest**: Keep satisfied (executives, regulators)
198
+ - **Low Power, High Interest**: Keep informed (end users, SMEs)
199
+ - **Low Power, Low Interest**: Monitor (general staff)
200
+
201
+ ### RACI Matrix
202
+ - **R** = Responsible (does the work)
203
+ - **A** = Accountable (approves)
204
+ - **C** = Consulted (provides input)
205
+ - **I** = Informed (receives updates)
206
+
207
+ ### Quick Tips
208
+ 1. Identify stakeholders early
209
+ 2. Understand their motivations
210
+ 3. Communicate regularly
211
+ 4. Manage expectations
212
+ 5. Build relationships
213
+ """
214
+
215
+ elif "requirement" in question_lower or "gathering" in question_lower:
216
+ return """
217
+ ## πŸ“ Requirements Gathering
218
+
219
+ ### Elicitation Techniques
220
+ - **Interviews**: One-on-one discussions with stakeholders
221
+ - **Workshops**: Collaborative sessions with multiple stakeholders
222
+ - **Surveys**: Collect feedback from large groups
223
+ - **Observation**: Watch users in their environment
224
+ - **Document Analysis**: Review existing documentation
225
+
226
+ ### Types of Requirements
227
+ 1. **Business Requirements**: High-level organizational needs
228
+ 2. **User Requirements**: What users need to do
229
+ 3. **Functional Requirements**: What the system must do
230
+ 4. **Non-Functional Requirements**: Performance, security, usability
231
+
232
+ ### Best Practices
233
+ - Ask open-ended questions
234
+ - Listen actively
235
+ - Validate understanding
236
+ - Document clearly
237
+ - Get sign-off
238
+ """
239
+
240
+ elif "agile" in question_lower or "scrum" in question_lower:
241
+ return """
242
+ ## πŸ”„ Agile Methodology
243
+
244
+ ### Agile Principles
245
+ - Individuals and interactions over processes and tools
246
+ - Working software over comprehensive documentation
247
+ - Customer collaboration over contract negotiation
248
+ - Responding to change over following a plan
249
+
250
+ ### Scrum Framework
251
+ - **Roles**: Product Owner, Scrum Master, Development Team
252
+ - **Events**: Sprint Planning, Daily Stand-up, Sprint Review, Retrospective
253
+ - **Artifacts**: Product Backlog, Sprint Backlog, Increment
254
+
255
+ ### Key Concepts
256
+ - **User Stories**: "As a [user], I want [feature] so that [benefit]"
257
+ - **Acceptance Criteria**: Conditions that must be met
258
+ - **Definition of Done**: Team's agreement on completion
259
+ """
260
+
261
+ elif "banking" in question_lower or "financial" in question_lower:
262
+ return """
263
+ ## 🏦 Banking & Financial Services
264
+
265
+ ### Key Regulations
266
+ - **Basel III/IV**: Capital adequacy, risk management
267
+ - **SOX**: Internal controls, audit trails
268
+ - **PSD2/Open Banking**: API requirements, customer data access
269
+
270
+ ### Common Projects
271
+ - Core banking transformation
272
+ - Payment systems
273
+ - Mobile banking apps
274
+ - Regulatory reporting
275
+
276
+ ### BA Considerations
277
+ - Security and compliance are critical
278
+ - Real-time processing requirements
279
+ - Complex integration with legacy systems
280
+ """
281
+
282
+ elif "healthcare" in question_lower or "hipaa" in question_lower:
283
+ return """
284
+ ## πŸ₯ Healthcare IT
285
+
286
+ ### Key Regulations
287
+ - **HIPAA**: Privacy, security, patient data
288
+ - **FDA**: Medical device software validation
289
+ - **HL7/FHIR**: Healthcare data interoperability
290
+
291
+ ### Common Projects
292
+ - Electronic Health Records (EHR)
293
+ - Telemedicine platforms
294
+ - Medical devices
295
+ - Clinical trials management
296
+
297
+ ### BA Considerations
298
+ - Patient safety is paramount
299
+ - Strict compliance requirements
300
+ - Complex clinical workflows
301
+ - Interoperability standards
302
+ """
303
+
304
+ else:
305
+ categories_str = ', '.join(categories) if categories else 'General BA'
306
+ keywords_str = ', '.join(keywords) if keywords else 'business analysis'
307
+
308
+ return f"""
309
+ ## πŸ“Š Business Analysis Information
310
 
311
+ **Categories:** {categories_str}
312
+ **Topics:** {keywords_str}
 
313
 
314
+ ### Quick Reference
315
+ - **Core Concepts**: Requirements, stakeholders, scope, value
316
+ - **Methodologies**: Agile, Scrum, Waterfall, BABOK
317
+ - **Domains**: Banking, Healthcare, Retail, Supply Chain
318
+
319
+ ### Ask About
320
+ - Specific techniques (traceability, prioritization)
321
+ - Industry domains (banking, healthcare)
322
+ - Methodologies (Agile, BABOK)
323
+ - Best practices (stakeholder management, requirements)
324
  """
325
 
326
  # ---------------------------
327
+ # Main Function
328
  # ---------------------------
329
  def ask_ba_assistant(question: str) -> str:
330
  """Main function to handle BA queries"""
 
334
  if not question:
335
  return "Please enter a question about IT-Business Analysis."
336
 
337
+ # Check if BA-related
338
+ is_related, keywords, categories = is_ba_related(question)
339
 
340
  if not is_related:
341
  return """❌ I specialize in IT-Business Analysis topics only.
342
 
343
+ ### βœ… Try Asking About:
344
+
345
+ **Core Concepts**
346
+ β€’ What is requirements gathering?
347
+ β€’ How to manage stakeholders?
348
+ β€’ What is a business case?
349
+
350
+ **Methodologies**
351
+ β€’ Explain Agile methodology
352
+ β€’ What is Scrum?
353
+ β€’ What is BABOK?
354
+
355
+ **Business Domains**
356
+ β€’ Banking and financial services
357
+ β€’ Healthcare IT and HIPAA
358
+ β€’ Retail and e-commerce
359
+
360
+ **Specific Topics**
361
+ β€’ Requirements traceability
362
+ β€’ Stakeholder analysis
363
+ β€’ User stories
364
  """
365
 
366
+ # Try DeepSeek if available
367
  if DEEPSEEK_AVAILABLE:
368
+ ai_response = get_deepseek_response(question)
369
  if ai_response:
370
+ return ai_response + "\n\n---\n*Powered by DeepSeek AI Free Tier*"
371
 
372
  # Fallback to local templates
373
  response = get_local_response(question, keywords, categories)
374
+ return response + "\n\n---\n*Professional Knowledge Base*"
 
 
375
 
376
  # ---------------------------
377
+ # Build Interface
378
  # ---------------------------
379
  def build_app():
380
  """Build the Gradio interface"""
381
 
382
+ status = "🟒 DEEPSEEK AI" if DEEPSEEK_AVAILABLE else "🟑 LOCAL TEMPLATES"
383
 
384
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
 
385
  gr.Markdown(f"""
386
  <div style='text-align:center;'>
387
+ <h1>πŸ“Š Professional IT Business Analysis Assistant</h1>
388
+ <p><i>AI-powered guide for BA concepts and business domains</i></p>
389
+ <p>Version 3.0.0 | Mode: {status}</p>
 
390
  </div>
391
  """)
392
 
 
394
  with gr.Column(scale=2):
395
  question = gr.Textbox(
396
  label="Ask your BA question",
397
+ placeholder="e.g., How to manage stakeholders? What is requirements traceability? Agile vs Waterfall?",
398
  lines=3
399
  )
400
  submit_btn = gr.Button("πŸ” Get Guidance", variant="primary")
 
409
 
410
  gr.Examples(
411
  examples=[
412
+ ["How to manage stakeholders?"],
413
+ ["What is requirements traceability?"],
414
+ ["Explain Agile methodology"],
415
+ ["Banking domain analysis techniques"],
416
+ ["HIPAA compliance requirements"]
417
  ],
418
  inputs=question
419
  )
 
423
  return demo
424
 
425
  # ---------------------------
426
+ # Launch
427
  # ---------------------------
428
  if __name__ == "__main__":
429
  demo = build_app()
430
+ demo.launch(server_name="0.0.0.0", server_port=7860)