Spaces:
Sleeping
Sleeping
File size: 15,235 Bytes
02d400e 38dad88 5782e98 38dad88 3a01954 38dad88 3a01954 06213a1 c3cc1b8 3a01954 c3cc1b8 06213a1 02d400e 38dad88 02d400e |
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 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
import os
from phi.agent import Agent
from phi.tools.firecrawl import FirecrawlTools
from phi.tools.duckduckgo import DuckDuckGo
from phi.model.openai import OpenAIChat
from phi.knowledge.pdf import PDFUrlKnowledgeBase
from phi.embedder.openai import OpenAIEmbedder
from phi.vectordb.lancedb import LanceDb, SearchType
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import helium
from typing import List
from pydantic import BaseModel, Field
from fastapi import UploadFile
from selenium import webdriver
import helium
from selenium.webdriver.chrome.service import Service
# Set paths explicitly
CHROME_PATH = "/usr/bin/chromium-browser"
CHROMEDRIVER_PATH = "/usr/local/bin/chromedriver"
# Configure Chrome options for Hugging Face Spaces
chrome_options = webdriver.ChromeOptions()
chrome_options.binary_location = CHROME_PATH # Manually specify Chromium binary
chrome_options.add_argument("--headless") # Run in headless mode
chrome_options.add_argument("--no-sandbox") # Required for Hugging Face Spaces
chrome_options.add_argument("--disable-dev-shm-usage") # Prevents memory issues
chrome_options.add_argument("--disable-gpu") # Disable GPU acceleration
chrome_options.add_argument("--remote-debugging-port=9222") # Helps debugging
# Initialize Chrome WebDriver with the correct service path
service = Service(CHROMEDRIVER_PATH)
driver = webdriver.Chrome(service=service, options=chrome_options)
# Start Helium using the modified driver
helium.set_driver(driver)
# Load environment variables (API keys, etc.)
from dotenv import load_dotenv
load_dotenv()
#####################################################################################
# PHASE 1 #
#####################################################################################
##############################
# 1️⃣ Company Search Agent #
##############################
company_search_agent = Agent(
name="Company Search Agent",
model=OpenAIChat(id="gpt-4o"),
tools=[DuckDuckGo()],
description="Finds company details based on name using web search.",
instructions=["Always include sources in search results."],
show_tool_calls=True,
markdown=True,
)
def search_company(company_name: str):
query = f"Find detailed company information for {company_name}. Extract its official website, mission, services, and any AI-related initiatives. Prioritize official sources and provide links where available."
return company_search_agent.print_response(query)
##############################
# 2️⃣ Website Scraper Agent #
##############################
firecrawl_agent = Agent(
name="Website Scraper Agent",
tools=[FirecrawlTools(scrape=True, crawl=False)],
description="Extracts content from company websites.",
show_tool_calls=True,
markdown=True,
)
def scrape_website(url: str):
return firecrawl_agent.print_response(f"Extract all relevant business information from {url}, including mission statement, services, case studies, and AI-related content. Provide structured output.")
# Helium for dynamic websites
# chrome_options = webdriver.ChromeOptions()
# chrome_options.add_argument("--headless")
driver = helium.start_chrome(headless=True, options=chrome_options)
def scrape_dynamic_website(url: str):
helium.go_to(url)
text = helium.get_driver().page_source
return text
##############################
# 3️⃣ Text Processing Agent #
##############################
class CompanySummary(BaseModel):
summary: str = Field(..., description="Summarized company details based on user input.")
text_processing_agent = Agent(
model=OpenAIChat(id="gpt-4o"),
description="Summarizes user-written company descriptions.",
response_model=CompanySummary,
)
def process_company_description(text: str):
return text_processing_agent.print_response(f"Summarize the following company description: {text}. Focus on key services, mission, industry, and potential AI use cases where applicable.")
#################################
# 4️⃣ Document Processing Agent #
#################################
# LanceDB for storing extracted knowledge
knowledge_base = PDFUrlKnowledgeBase(
urls=[], # PDFs will be dynamically added
vector_db=LanceDb(
table_name="company_docs",
uri="tmp/lancedb",
search_type=SearchType.vector,
embedder=OpenAIEmbedder(model="text-embedding-3-small"),
),
)
knowledge_base.load(recreate=False)
document_processing_agent = Agent(
model=OpenAIChat(id="gpt-4o"),
knowledge=knowledge_base,
description="Extracts and processes data from uploaded PDFs/PPTs.",
show_tool_calls=True,
markdown=True,
)
def process_uploaded_document(file: UploadFile):
file_path = f"tmp/{file.filename}"
with open(file_path, "wb") as buffer:
buffer.write(file.file.read())
knowledge_base.load(recreate=False)
return document_processing_agent.print_response(f"Analyze and extract key insights from the uploaded document: {file.filename}. Summarize business operations, AI-related discussions, financial details, and relevant strategic insights.")
#####################################################################################
# PHASE 2 #
#####################################################################################
###########################
# Example Usage #
###########################
# if __name__ == "__main__":
# company_name = "Tesla"
# print("Company Search Results:")
# search_company(company_name)
# website_url = "https://www.tesla.com"
# print("\nScraped Website Data:")
# scrape_website(website_url)
# user_description = "We are a renewable energy startup focusing on solar solutions."
# print("\nProcessed Company Description:")
# process_company_description(user_description)
# Example of handling an uploaded file
# process_uploaded_document(uploaded_file)
import os
from phi.agent import Agent
from phi.tools.duckduckgo import DuckDuckGo
from phi.tools.exa import ExaTools
from phi.model.openai import OpenAIChat
from typing import List
from pydantic import BaseModel, Field
# Load environment variables (API keys, etc.)
from dotenv import load_dotenv
load_dotenv()
##############################
# 1️⃣ Industry Trends Agent #
##############################
industry_trends_agent = Agent(
name="Industry Trends Agent",
model=OpenAIChat(id="gpt-4o"),
tools=[ExaTools(include_domains=["cnbc.com", "reuters.com", "bloomberg.com"])],
description="Finds the latest AI advancements in a given industry.",
show_tool_calls=True,
markdown=True,
)
def get_industry_trends(industry: str):
query = f"Find the latest AI advancements, innovations, and emerging technologies in the {industry} sector. Include breakthroughs, adoption trends, and notable implementations by leading companies. Provide references and insights from credible sources."
return industry_trends_agent.print_response(query)
##################################
# 2️⃣ AI Use Case Discovery Agent #
##################################
ai_use_case_agent = Agent(
name="AI Use Case Discovery Agent",
model=OpenAIChat(id="gpt-4o"),
tools=[DuckDuckGo()],
description="Identifies AI applications relevant to a given industry.",
show_tool_calls=True,
markdown=True,
)
def get_ai_use_cases(industry: str):
query = f"Identify the most impactful AI use cases in the {industry} sector. Include real-world applications, automation improvements, cost-saving innovations, and data-driven decision-making processes. Provide case studies and examples of successful AI implementation."
return ai_use_case_agent.print_response(query)
####################################
# 3️⃣ Competitive Analysis Agent #
####################################
competitive_analysis_agent = Agent(
name="Competitive Analysis Agent",
model=OpenAIChat(id="gpt-4o"),
tools=[DuckDuckGo(), ExaTools(include_domains=["techcrunch.com", "forbes.com", "businessinsider.com"])],
description="Analyzes how competitors are using AI in their businesses.",
show_tool_calls=True,
markdown=True,
)
def get_competitor_ai_strategies(company_name: str):
query = f"Analyze how {company_name} is leveraging AI in its business operations. Find recent reports, product innovations, automation strategies, and AI-driven transformations. Highlight competitive advantages gained through AI adoption. Provide references and sources."
return competitive_analysis_agent.print_response(query)
###########################
# Example Usage #
###########################
# if __name__ == "__main__":
# industry = "Healthcare"
# print("Industry Trends:")
# get_industry_trends(industry)
# print("\nAI Use Cases:")
# get_ai_use_cases(industry)
# competitor = "Pfizer"
# print("\nCompetitor AI Strategies:")
# get_competitor_ai_strategies(competitor)
#####################################################################################
# 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 that includes:
1. **AI Opportunities**: Identify key areas where AI can enhance operations, customer experience, or business efficiency.
2. **Technology Fit**: Recommend specific AI tools, models, or methodologies that fit this company's needs.
3. **Implementation Roadmap**: Step-by-step guidance on integrating AI, considering costs, scalability, and ROI.
4. **Future Scalability**: How AI adoption can evolve over time for long-term growth.
Provide structured insights with a logical flow and avoid generic statements. Use industry benchmarks where possible.
"""
return reasoning_agent.print_response(query)
##############################
# 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:
1. **Step-by-step AI Integration**: List phases of AI adoption, from pilot testing to full deployment.
2. **Technology & Infrastructure**: Recommend necessary AI tools, cloud platforms, and software.
3. **Workforce & Training**: Suggest ways to upskill employees for AI adoption.
4. **Risk & Compliance Considerations**: Highlight data security, compliance, and ethical concerns.
5. **KPIs for Success**: Define measurable AI performance indicators.
The output should be detailed, actionable, and specific to the business domain.
"""
return ai_integration_agent.print_response(query)
##############################
# 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:
1. **AI Monetization Strategies**: Explain how AI can create new revenue streams (e.g., AI-driven products, services, or data monetization).
2. **Cost Reduction & Efficiency Gains**: Highlight AI automation that lowers operational costs.
3. **Market Expansion**: Discuss how AI can help enter new markets or scale offerings.
4. **Competitive Positioning**: Compare with industry leaders and suggest differentiation tactics.
Ensure detailed, actionable insights with real-world examples where applicable.
"""
return revenue_growth_agent.print_response(query)
##############################
# 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)
# Convert Markdown to PDF
pdfkit.from_string(markdown_report, f"{company_name}_AI_Report.pdf")
return f"Report generated: {company_name}_AI_Report.pdf"
###########################
# Example Usage #
###########################
# if __name__ == "__main__":
# company_name = "Tesla"
# company_data = "Tesla specializes in electric vehicles and AI-powered self-driving technology."
# industry_trends = "Latest AI advancements in autonomous driving and battery optimization."
# ai_use_cases = "AI used in predictive maintenance, customer behavior analysis, and automation."
# competitor_analysis = "Ford and GM are integrating AI into manufacturing and autonomous vehicle tech."
# print("Generating AI Strategy...")
# ai_strategy = generate_ai_strategy(company_data, industry_trends, ai_use_cases, competitor_analysis)
# print("\nSuggesting AI Integration Plan...")
# ai_integration = suggest_ai_integration(company_data, ai_strategy)
# print("\nIdentifying Revenue Growth Opportunities...")
# revenue_opportunities = identify_revenue_opportunities(company_data, ai_strategy)
# print("\nGenerating Final Report...")
# generate_report(company_name, ai_strategy, ai_integration, revenue_opportunities) |