ir_agent / utils /talking_points.py
yekkala's picture
Upload 7 files
96de966 verified
"""
Generate management talking points for investor relations.
Uses free HuggingFace models with rule-based fallback.
"""
import re
from transformers import pipeline
_generator = None
def get_generator(model_name="google/flan-t5-base"):
"""Load text2text generation pipeline with fallback."""
global _generator
if _generator is None:
try:
_generator = pipeline(
"text2text-generation",
model=model_name,
device=-1 # CPU only for free deployment
)
except Exception:
_generator = None
return _generator
def rule_based_talking_points(content, company_name, memo_style=False):
"""Fallback: Generate structured talking points using rules."""
lines = [l.strip() for l in content.split('\n') if l.strip()]
if memo_style:
# Memo format
talking_points = ["### Executive Summary\n"]
talking_points.append(f"This memo outlines key strategic considerations and talking points for {company_name}.\n")
talking_points.append("### Key Points\n")
for i, line in enumerate(lines[:8], 1):
if line and not line.startswith('#'):
talking_points.append(f"{i}. {line}")
talking_points.append("\n### Strategic Priorities\n")
# Extract action-oriented items
action_words = ['invest', 'launch', 'expand', 'acquire', 'focus', 'pursue', 'grow']
for line in lines:
line_lower = line.lower()
if any(word in line_lower for word in action_words):
talking_points.append(f"- {line}")
talking_points.append("\n### Investor Considerations\n")
talking_points.append("- Emphasize long-term strategic value creation")
talking_points.append("- Highlight competitive advantages and market positioning")
talking_points.append("- Address key risks and mitigation strategies")
else:
# Earnings call format
talking_points = ["### Opening Remarks\n"]
talking_points.append(f"Thank you for joining {company_name}'s earnings call today. I'd like to highlight our strong performance and strategic progress.\n")
talking_points.append("### Performance Highlights\n")
# Extract positive metrics
positive_lines = []
for line in lines:
line_lower = line.lower()
if any(word in line_lower for word in ['growth', 'beat', 'up', 'increase', 'strong', 'success', 'achievement', 'launch']):
positive_lines.append(line)
for line in positive_lines[:5]:
talking_points.append(f"- {line}")
talking_points.append("\n### Strategic Initiatives\n")
talking_points.append("- Continue investing in innovation and product development")
talking_points.append("- Expand market presence and customer base")
talking_points.append("- Drive operational efficiency and margin improvement")
talking_points.append("- Pursue strategic opportunities for growth")
# Extract challenges and address them
challenge_lines = []
for line in lines:
line_lower = line.lower()
if any(word in line_lower for word in ['challenge', 'delay', 'headwind', 'pressure']):
challenge_lines.append(line)
if challenge_lines:
talking_points.append("\n### Addressing Challenges\n")
for line in challenge_lines[:3]:
talking_points.append(f"- {line}")
talking_points.append(f" - *Mitigation*: Proactive management and contingency planning in place")
talking_points.append("\n### Looking Forward\n")
# Extract guidance
guidance_lines = []
for line in lines:
line_lower = line.lower()
if any(word in line_lower for word in ['guidance', 'expect', 'outlook', 'forecast', 'target']):
guidance_lines.append(line)
if guidance_lines:
for line in guidance_lines:
talking_points.append(f"- {line}")
else:
talking_points.append("- We remain confident in our strategic direction and growth trajectory")
talking_points.append("- Focused on executing our roadmap and delivering shareholder value")
talking_points.append("\n### Closing\n")
talking_points.append(f"Thank you for your continued support. We're excited about {company_name}'s future and look forward to your questions.")
return "\n".join(talking_points)
def generate_talking_points(content, company_name, model_name="google/flan-t5-base", memo_style=False):
"""
Generate management talking points for investor communications.
Args:
content: Source content (quarter summary, context, etc.)
company_name: Name of the company
model_name: HuggingFace model to use
memo_style: If True, format as memo; if False, format as earnings call script
Returns:
Formatted talking points
"""
generator = get_generator(model_name)
if generator is None:
# Use rule-based fallback
return rule_based_talking_points(content, company_name, memo_style)
# Use AI model
if memo_style:
prompt = f"""Create executive talking points for an investor memo about {company_name}.
Context:
{content[:2000]}
Generate professional talking points with:
1. Executive summary
2. Key strategic points
3. Investment considerations
Talking Points:"""
else:
prompt = f"""Create management talking points for {company_name}'s earnings call.
Content:
{content[:2000]}
Generate structured talking points with:
1. Opening remarks
2. Performance highlights
3. Strategic initiatives
4. Addressing challenges
5. Forward outlook
6. Closing remarks
Talking Points:"""
try:
result = generator(
prompt,
max_length=512,
min_length=100,
do_sample=True,
temperature=0.7,
top_p=0.9
)
talking_points = result[0]['generated_text']
return talking_points
except Exception as e:
# Fallback to rule-based on any error
return rule_based_talking_points(content, company_name, memo_style)