Spaces:
Sleeping
Sleeping
| import os | |
| from phi.agent import Agent | |
| from phi.model.openai import OpenAIChat | |
| from typing import List | |
| from pydantic import BaseModel, Field | |
| import markdown2 | |
| import pdfkit | |
| # 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, ai_use_cases: str, competitor_analysis: str): | |
| query = f""" | |
| You are an AI business strategist analyzing a company's potential AI adoption. Given the following: | |
| - **Company Overview:** {company_data} | |
| - **Industry Trends:** {industry_trends} | |
| - **AI Use Cases:** {ai_use_cases} | |
| - **Competitor AI Strategies:** {competitor_analysis} | |
| Generate a structured AI adoption strategy including key opportunities, recommended AI tools, implementation roadmap, and future scalability. | |
| """ | |
| response = reasoning_agent.run(query) | |
| return response.content | |
| ############################## | |
| # 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): | |
| query = f""" | |
| Based on the AI adoption strategy: | |
| - **Company Context:** {company_data} | |
| - **AI Strategy Summary:** {ai_strategy} | |
| Provide a structured AI implementation plan including step-by-step integration, required technologies, workforce training, risk considerations, and key performance indicators. | |
| """ | |
| response = ai_integration_agent.run(query) | |
| return response.content | |
| ############################## | |
| # 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): | |
| query = f""" | |
| You are an AI business analyst tasked with identifying AI-driven revenue growth opportunities for: | |
| - **Company Overview:** {company_data} | |
| - **AI Strategy:** {ai_strategy} | |
| Provide AI monetization strategies, cost-saving efficiencies, market expansion possibilities, and competitive positioning tactics. | |
| """ | |
| response = revenue_growth_agent.run(query) | |
| return response.content # Return the revenue opportunities | |
| ############################## | |
| # 4️⃣ Report Generation Agent # | |
| ############################## | |
| def generate_report(company_name: str, ai_strategy: str, ai_integration: str, revenue_opportunities: str): | |
| report_content = f""" | |
| # AI Strategy Report for {company_name} | |
| ## AI Adoption Strategy | |
| {ai_strategy} | |
| ## AI Implementation Plan | |
| {ai_integration} | |
| ## Revenue Growth Opportunities | |
| {revenue_opportunities} | |
| """ | |
| # Convert to Markdown | |
| markdown_report = markdown2.markdown(report_content) | |
| # Define the path to wkhtmltopdf configuration | |
| config = pdfkit.configuration(wkhtmltopdf="/usr/bin/wkhtmltopdf") | |
| # Convert Markdown to PDF | |
| pdf_filename = f"{company_name}_AI_Report.pdf" | |
| pdfkit.from_string(markdown_report, pdf_filename) | |
| return pdf_filename | |