muzakkirhussain011 commited on
Commit
f24d547
·
1 Parent(s): 4e048ae

Add application files

Browse files
Files changed (1) hide show
  1. app.py +96 -24
app.py CHANGED
@@ -1341,16 +1341,13 @@ def chat_with_ai(message: str, history: list) -> tuple:
1341
  response += "To find contacts, go to **Prospects Tab** and run **Find Prospects** again."
1342
  return history + [[message, response]], ""
1343
 
1344
- # Handle "draft email" for a known prospect
1345
- if any(kw in msg_lower for kw in ["draft", "write", "compose", "email to", "create email"]):
1346
  if mentioned_prospect:
1347
  p_name = mentioned_prospect["name"]
1348
  p_name_lower = p_name.lower()
1349
-
1350
- # Check if we already have an email for this prospect
1351
  existing_emails = [e for e in knowledge_base["emails"]
1352
  if p_name_lower in e.get("prospect_company", "").lower()]
1353
-
1354
  if existing_emails:
1355
  email = existing_emails[0]
1356
  response = f"## ✉️ Existing Email Draft for {p_name}\n\n"
@@ -1359,25 +1356,100 @@ def chat_with_ai(message: str, history: list) -> tuple:
1359
  response += f"---\n\n{email.get('body', 'No content')}\n\n"
1360
  response += "---\n\n*This email was drafted during prospect discovery.*"
1361
  else:
1362
- # Generate a template based on prospect info
1363
- contacts = [c for c in knowledge_base["contacts"]
1364
- if p_name_lower in c.get("company", "").lower()]
1365
- contact = contacts[0] if contacts else None
1366
 
1367
- to_email = contact.get("email", "contact@" + p_name.lower().replace(" ", "") + ".com") if contact else f"contact@{p_name.lower().replace(' ', '')}.com"
1368
- contact_name = contact.get("name", "there").split()[0] if contact else "there"
 
 
 
1369
 
1370
- response = f"## ✉️ Email Template for {p_name}\n\n"
1371
- response += f"**To:** {to_email}\n"
1372
- response += f"**Subject:** {client_name} + {p_name}: A Potential Partnership\n\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1373
  response += f"---\n\n"
1374
  response += f"Dear {contact_name},\n\n"
1375
- response += f"I came across {p_name} and was impressed by your work in {mentioned_prospect.get('industry', 'your industry')}.\n\n"
1376
- response += f"{mentioned_prospect.get('summary', '')}\n\n"
1377
- response += f"At {client_name}, we help companies like yours {mentioned_prospect.get('fit_reason', 'grow their business')}.\n\n"
1378
- response += f"Would you be open to a brief call to explore how we might work together?\n\n"
1379
- response += f"Best regards,\n[Your Name]\n{client_name}\n\n"
1380
- response += "---\n\n*This is a template. Customize it before sending.*"
 
 
 
 
 
 
 
 
1381
 
1382
  return history + [[message, response]], ""
1383
 
@@ -1976,11 +2048,11 @@ def create_app():
1976
 
1977
  gr.HTML("""
1978
  <div style="background: var(--bg-tertiary); padding: 12px; border-radius: 8px; margin-bottom: 8px;">
1979
- <strong>✉️ Outreach</strong>
1980
  <ul style="margin: 8px 0 0 0; padding-left: 16px; font-size: 13px;">
1981
- <li>Draft email to [prospect]</li>
1982
- <li>Find contacts at [company]</li>
1983
- <li>Show email for [prospect]</li>
1984
  </ul>
1985
  </div>
1986
  """)
 
1341
  response += "To find contacts, go to **Prospects Tab** and run **Find Prospects** again."
1342
  return history + [[message, response]], ""
1343
 
1344
+ # Handle "show email" - just viewing existing drafts
1345
+ if any(kw in msg_lower for kw in ["show email", "existing email", "what email", "see email", "view email"]):
1346
  if mentioned_prospect:
1347
  p_name = mentioned_prospect["name"]
1348
  p_name_lower = p_name.lower()
 
 
1349
  existing_emails = [e for e in knowledge_base["emails"]
1350
  if p_name_lower in e.get("prospect_company", "").lower()]
 
1351
  if existing_emails:
1352
  email = existing_emails[0]
1353
  response = f"## ✉️ Existing Email Draft for {p_name}\n\n"
 
1356
  response += f"---\n\n{email.get('body', 'No content')}\n\n"
1357
  response += "---\n\n*This email was drafted during prospect discovery.*"
1358
  else:
1359
+ response = f"No existing email drafts found for **{p_name}**."
1360
+ return history + [[message, response]], ""
 
 
1361
 
1362
+ # Handle "draft/write/compose email" - create custom email based on user's request
1363
+ if any(kw in msg_lower for kw in ["draft", "write", "compose", "create email", "email to", "send email", "mail to"]):
1364
+ if mentioned_prospect:
1365
+ p_name = mentioned_prospect["name"]
1366
+ p_name_lower = p_name.lower()
1367
 
1368
+ # Get contact info
1369
+ contacts = [c for c in knowledge_base["contacts"]
1370
+ if p_name_lower in c.get("company", "").lower()
1371
+ or c.get("company", "").lower() in p_name_lower]
1372
+ contact = contacts[0] if contacts else None
1373
+ to_email = contact.get("email", f"contact@{p_name.lower().replace(' ', '')}.com") if contact else f"contact@{p_name.lower().replace(' ', '')}.com"
1374
+ contact_name = contact.get("name", "").split()[0] if contact and contact.get("name") else "there"
1375
+ contact_title = contact.get("title", "") if contact else ""
1376
+
1377
+ # Extract specific details from user's message
1378
+ import re
1379
+
1380
+ # Check if this is a meeting request
1381
+ is_meeting_request = any(kw in msg_lower for kw in ["meeting", "call", "demo", "schedule", "appointment"])
1382
+
1383
+ # Extract date/time info
1384
+ date_match = re.search(r'(\d{1,2}(?:st|nd|rd|th)?\s+(?:jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)[a-z]*\s+\d{4}|\w+day(?:\s+next\s+week)?|\d{1,2}[/-]\d{1,2}[/-]\d{2,4})', msg_lower)
1385
+ time_match = re.search(r'(\d{1,2}:\d{2}|\d{1,2}\s*(?:am|pm))', msg_lower)
1386
+ duration_match = re.search(r'(\d+)\s*(?:min|minute|hour)', msg_lower)
1387
+
1388
+ date_str = date_match.group(1).title() if date_match else ""
1389
+ time_str = time_match.group(1) if time_match else ""
1390
+ duration_str = duration_match.group(0) if duration_match else ""
1391
+
1392
+ # Extract the purpose/topic from the message
1393
+ # Remove common words to find the custom content
1394
+ custom_content = message
1395
+ for word in ["draft", "write", "compose", "email", "mail", "to", p_name.lower(), "asking", "that", "can", "we", "a", "an", "the", "for", "about"]:
1396
+ custom_content = re.sub(rf'\b{word}\b', '', custom_content, flags=re.IGNORECASE)
1397
+ custom_content = ' '.join(custom_content.split()).strip()
1398
+
1399
+ # Generate custom email based on context
1400
+ response = f"## ✉️ Custom Email Draft for {p_name}\n\n"
1401
+ response += f"**To:** {to_email}\n"
1402
+
1403
+ if is_meeting_request:
1404
+ # Meeting request email
1405
+ subject = f"Meeting Request: {client_name} x {p_name}"
1406
+ if date_str:
1407
+ subject = f"Meeting Request for {date_str} - {client_name} x {p_name}"
1408
+ response += f"**Subject:** {subject}\n\n"
1409
+ response += f"---\n\n"
1410
+ response += f"Dear {contact_name},\n\n"
1411
+ response += f"I hope this email finds you well.\n\n"
1412
+ response += f"I'm reaching out from {client_name} regarding a potential collaboration with {p_name}. "
1413
+ response += f"Based on our research, we believe there's a strong synergy between our companies, "
1414
+ response += f"particularly in the {mentioned_prospect.get('industry', 'your industry')} space.\n\n"
1415
+
1416
+ if date_str or time_str or duration_str:
1417
+ response += f"I would like to propose a meeting"
1418
+ if date_str:
1419
+ response += f" on **{date_str}**"
1420
+ if time_str:
1421
+ response += f" at **{time_str}**"
1422
+ if duration_str:
1423
+ response += f" for **{duration_str}**"
1424
+ response += f" to discuss how {client_name} can help {p_name} achieve its goals.\n\n"
1425
+ else:
1426
+ response += f"Would you be available for a brief call this week to discuss how {client_name} can support {p_name}'s growth?\n\n"
1427
+
1428
+ response += f"During our conversation, I'd love to explore:\n"
1429
+ response += f"- How {client_name}'s solutions align with {p_name}'s current initiatives\n"
1430
+ response += f"- Specific ways we can add value to your {mentioned_prospect.get('industry', 'business')}\n"
1431
+ response += f"- Next steps for a potential partnership\n\n"
1432
+ response += f"Please let me know if this time works for you, or suggest an alternative that fits your schedule.\n\n"
1433
+ else:
1434
+ # General outreach with custom content
1435
+ subject = f"{client_name} + {p_name}: Let's Connect"
1436
+ response += f"**Subject:** {subject}\n\n"
1437
  response += f"---\n\n"
1438
  response += f"Dear {contact_name},\n\n"
1439
+ response += f"I'm reaching out from {client_name} regarding {p_name}.\n\n"
1440
+ if custom_content:
1441
+ response += f"{custom_content}\n\n"
1442
+ response += f"Based on our research into {p_name}'s work in {mentioned_prospect.get('industry', 'your industry')}, "
1443
+ response += f"we believe {client_name} can provide significant value.\n\n"
1444
+ response += f"**About {p_name}:** {mentioned_prospect.get('summary', '')}\n\n"
1445
+ response += f"**Why we're reaching out:** {mentioned_prospect.get('fit_reason', 'We see great potential for collaboration.')}\n\n"
1446
+ response += f"Would you be open to a conversation about how we can work together?\n\n"
1447
+
1448
+ response += f"Best regards,\n"
1449
+ response += f"[Your Name]\n"
1450
+ response += f"{client_name}\n\n"
1451
+ response += f"---\n\n"
1452
+ response += f"*📝 This is a custom draft based on your request. Edit as needed before sending.*"
1453
 
1454
  return history + [[message, response]], ""
1455
 
 
2048
 
2049
  gr.HTML("""
2050
  <div style="background: var(--bg-tertiary); padding: 12px; border-radius: 8px; margin-bottom: 8px;">
2051
+ <strong>✉️ Custom Emails</strong>
2052
  <ul style="margin: 8px 0 0 0; padding-left: 16px; font-size: 13px;">
2053
+ <li>Draft meeting email to [prospect] for Wednesday at 3pm</li>
2054
+ <li>Write email to [prospect] about partnership</li>
2055
+ <li>Show existing email for [prospect]</li>
2056
  </ul>
2057
  </div>
2058
  """)