Spaces:
Sleeping
Sleeping
File size: 8,509 Bytes
93b4009 98b6a0d 93b4009 78c8377 93b4009 d6d0f4f 93b4009 a29bad8 93b4009 5f86230 93b4009 5f86230 93b4009 d6d0f4f 93b4009 98b6a0d d6d0f4f 5f86230 d6d0f4f 98b6a0d 93b4009 98b6a0d 93b4009 98b6a0d 93b4009 98b6a0d 93b4009 98b6a0d 93b4009 98b6a0d a5fb864 98b6a0d df979e2 98b6a0d df979e2 98b6a0d 93b4009 df979e2 98b6a0d 93b4009 98b6a0d 0b9c323 93b4009 98b6a0d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | import os
from phi.agent import Agent
from phi.model.openai import OpenAIChat
import openai
import markdown2
import pdfkit
from datetime import datetime
from bni_agent import get_bni_benefits
from rag_agent import recommend_bni_connections
# Load environment variables (API keys, etc.)
from dotenv import load_dotenv
load_dotenv()
#####################################################################################
# PHASE 3 #
#####################################################################################
##############################
# 1️⃣ Reasoning Agent #
##############################
reasoning_agent = Agent(
name="Reasoning Agent",
model=OpenAIChat(id="gpt-4o"),
description="Processes all collected data and generates structured AI adoption strategies.",
show_tool_calls=True,
markdown=True,
)
def generate_ai_strategy(company_data: str, industry_trends: str) -> str:
"""Generates a structured AI adoption strategy based on company details and industry insights."""
query = f"""
You are an AI business strategist analyzing a company's AI adoption potential. Given:
- **Company Overview:** {company_data}
- **Industry Trends:** {industry_trends}
Generate a structured AI strategy including:
1. Key AI Opportunities
"""
response = reasoning_agent.run(query)
return response.content # Returns the generated AI strategy
##############################
# 2️⃣ AI Integration Advisor #
##############################
# ai_integration_agent = Agent(
# name="AI Integration Advisor",
# model=OpenAIChat(id="gpt-4o"),
# description="Suggests AI implementation strategies based on industry insights and company operations.",
# show_tool_calls=True,
# markdown=True,
# )
# def suggest_ai_integration(company_data: str, ai_strategy: str) -> str:
# """Suggests a structured AI implementation plan."""
# query = f"""
# Based on the AI adoption strategy:
# - **Company Context:** {company_data}
# - **AI Strategy Summary:** {ai_strategy}
# Provide a structured AI implementation plan including:
# 1. Step-by-step AI adoption process
# 2. Required AI Technologies & Infrastructure
# 3. Workforce training & AI skill development
# 4. Risk considerations (data security, compliance, ethical AI)
# 5. Key performance indicators (KPIs) for AI success.
# """
# response = ai_integration_agent.run(query)
# return response.content # Returns AI integration plan
##############################
# 3️⃣ Revenue Growth Agent #
##############################
revenue_growth_agent = Agent(
name="Revenue Growth Agent",
model=OpenAIChat(id="gpt-4o"),
description="Identifies AI-driven opportunities to enhance revenue and efficiency.",
show_tool_calls=True,
markdown=True,
)
def identify_revenue_opportunities(company_data: str, ai_strategy: str) -> str:
"""Identifies AI-driven revenue generation opportunities for a business."""
query = f"""
You are an AI business analyst identifying practical AI-driven revenue growth opportunities for:
Company Overview: {company_data}
AI Strategy: {ai_strategy}
Provide a concise, single-paragraph summary covering:
AI-based Monetization Strategies – How can the company create new revenue streams using AI?
Cost Reduction & Operational Efficiency – How can AI streamline operations and reduce costs?
Market Expansion – How can AI open new markets or customer segments?
Competitive Positioning – How can AI help differentiate the company from competitors?
Keep it short, crisp, and actionable, avoiding complex or unnecessary details.
"""
response = revenue_growth_agent.run(query)
return response.content # Returns revenue opportunities
##############################
# 4️⃣ BNI Agent: Membership Benefits #
##############################
def get_bni_membership_benefits(company_data: str) -> str:
"""Fetches BNI membership benefits tailored to the user's company."""
return get_bni_benefits(company_data)
##############################
# 5️⃣ BNI RAG Agent: Pearl Chapter Connections #
##############################
def get_bni_recommendations(company_data: str) -> str:
"""Recommends relevant BNI Pearl Chapter members based on the user's company data."""
return recommend_bni_connections(company_data)
##############################
# 6️⃣ Report Generation Agent #
##############################
# Ensure your OpenAI API key is set in your environment variables
openai.api_key = os.getenv("OPENAI_API_KEY")
def generate_report(company_name: str, company_data: str,
ai_strategy: str,
revenue_opportunities: str,
bni_benefits: str,
bni_connections: str) -> str:
"""
Generates a structured AI strategy report in PDF format using `pdfkit`.
"""
# 📝 **Step 1: Prepare the Report Content**
report_content = f"""
# AI Strategy Report for {company_name}
## 1️⃣ Company Overview
{company_data}
## 2️⃣ How BNI Can Help Your Business
{bni_benefits}
## 3️⃣ Recommended BNI Pearl Chapter Connections
{bni_connections}
## 4️⃣ AI Adoption Strategy
{ai_strategy}
## 5️⃣ Revenue Growth Opportunities
{revenue_opportunities}
"""
# 🎯 **Step 2: Use OpenAI GPT-4o-mini to Format Markdown**
response = openai.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You are an expert in formatting business reports in Markdown."},
{"role": "user", "content": f"Format the following report in well-structured Markdown. Use bold headings, bullet points, and clear sections. Ensure the text is concise, professional, and structured for readability. Do not include any emojis or unnecessary text:\n\n{report_content}"}
],
max_tokens=5000,
temperature=0.5,
)
enhanced_markdown = response.choices[0].message.content # Extract the formatted response
# 🖼 **Step 3: Convert Enhanced Markdown to HTML**
html_report = markdown2.markdown(enhanced_markdown)
# 📄 **Step 4: Define the HTML Template with Styling**
html_template = f"""
<html>
<head>
<style>
body {{
font-family: 'Times New Roman', serif;
margin: 50px;
position: relative;
}}
.watermark {{
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 100px;
color: rgba(200, 200, 200, 0.2);
z-index: -1;
user-select: none;
}}
.outline {{
border: 2px solid #000;
padding: 20px;
margin-bottom: 20px;
}}
h1, h2, h3, h4, h5, h6 {{
color: #333;
}}
p {{
font-size: 14pt;
line-height: 1.6;
color: #000;
}}
.footer {{
position: fixed;
bottom: 20px;
left: 0;
width: 100%;
text-align: center;
font-size: 12pt;
color: #555;
border-top: 1px solid #ccc;
padding-top: 10px;
}}
</style>
</head>
<body>
<div class="watermark">Giant Analytics</div>
<div class="outline">
{html_report}
</div>
<div class="footer">
🚀 Powered by <strong>Giant Analytics</strong> | Contact Us: (+91) 96533 20500
</div>
</body>
</html>
"""
# 📌 **Step 5: Generate the PDF**
current_date = datetime.now().strftime("%Y-%m-%d")
pdf_filename = f"{company_name}_AI_Report_{current_date}.pdf"
# Path to wkhtmltopdf executable (Make sure it's installed)
path_to_wkhtmltopdf = '/usr/bin/wkhtmltopdf' # Update this path if different
config = pdfkit.configuration(wkhtmltopdf=path_to_wkhtmltopdf)
# Convert HTML to PDF
pdfkit.from_string(html_template, pdf_filename, configuration=config)
return pdf_filename # Returns the generated PDF filename
|