Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import requests
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import streamlit as st
|
| 5 |
+
|
| 6 |
+
# Set API keys
|
| 7 |
+
os.environ['OPENAI_API_KEY'] = 'AIzaSyC8tIrUlJcCRnyksbykluUZVvER6ynHQeI'
|
| 8 |
+
os.environ['SERPAPI_API_KEY'] = '533b5ecf4f322a3e1fb6c6341fc922267805add7e804f7783949a17175ed2f69'
|
| 9 |
+
|
| 10 |
+
# Define the directory to save CSV files
|
| 11 |
+
SAVE_DIR = r'C:\Users\satya\DeloitteResearchAgent' # Absolute directory to save CSV files
|
| 12 |
+
os.makedirs(SAVE_DIR, exist_ok=True) # Create directory if it doesn't exist
|
| 13 |
+
|
| 14 |
+
def industry_research(company_name, industry_name):
|
| 15 |
+
"""Fetch AI trends and use cases for the specified company and industry."""
|
| 16 |
+
query_trends = f"{company_name} {industry_name} AI trends"
|
| 17 |
+
query_use_cases = f"{company_name} {industry_name} AI use cases"
|
| 18 |
+
|
| 19 |
+
params = {
|
| 20 |
+
"api_key": os.environ['SERPAPI_API_KEY'],
|
| 21 |
+
"q": query_trends,
|
| 22 |
+
"num": 5
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
response_trends = requests.get("https://serpapi.com/search.json", params=params)
|
| 26 |
+
if response_trends.status_code == 200:
|
| 27 |
+
trends_results = response_trends.json().get('organic_results', [])
|
| 28 |
+
else:
|
| 29 |
+
trends_results = {"error": response_trends.text}
|
| 30 |
+
|
| 31 |
+
params['q'] = query_use_cases # Update query for use cases
|
| 32 |
+
response_use_cases = requests.get("https://serpapi.com/search.json", params=params)
|
| 33 |
+
if response_use_cases.status_code == 200:
|
| 34 |
+
use_cases_results = response_use_cases.json().get('organic_results', [])
|
| 35 |
+
else:
|
| 36 |
+
use_cases_results = {"error": response_use_cases.text}
|
| 37 |
+
|
| 38 |
+
return trends_results, use_cases_results
|
| 39 |
+
|
| 40 |
+
def summarize_trends(trends_results):
|
| 41 |
+
"""Summarize industry trends from the search results."""
|
| 42 |
+
trends = []
|
| 43 |
+
for result in trends_results:
|
| 44 |
+
title = result.get('title')
|
| 45 |
+
link = result.get('link')
|
| 46 |
+
description = f"{title} can be explored further at [this link]({link})."
|
| 47 |
+
trends.append({"Title": title, "Link": link, "Description": description})
|
| 48 |
+
return trends
|
| 49 |
+
|
| 50 |
+
def propose_use_cases(use_cases_results):
|
| 51 |
+
"""Propose use cases based on search results."""
|
| 52 |
+
use_cases = []
|
| 53 |
+
for result in use_cases_results:
|
| 54 |
+
title = result.get('title')
|
| 55 |
+
link = result.get('link')
|
| 56 |
+
description = f"Consider implementing: {title}. More details can be found at [this link]({link})."
|
| 57 |
+
use_cases.append({"Title": title, "Link": link, "Description": description})
|
| 58 |
+
return use_cases
|
| 59 |
+
|
| 60 |
+
def save_results_to_csv(findings, company_name):
|
| 61 |
+
"""Save the findings to a CSV file and return the filename."""
|
| 62 |
+
df = pd.DataFrame(findings)
|
| 63 |
+
filename = os.path.join(SAVE_DIR, f"{company_name}_research_results.csv") # Save to the specified directory
|
| 64 |
+
df.to_csv(filename, index=False)
|
| 65 |
+
return filename
|
| 66 |
+
|
| 67 |
+
def main():
|
| 68 |
+
st.title("Multi-Agent Workflow for AI Use Cases")
|
| 69 |
+
|
| 70 |
+
# Input fields for company and industry
|
| 71 |
+
company_name = st.text_input("Enter the Company Name", "Deloitte")
|
| 72 |
+
industry_name = st.text_input("Enter the Industry Name", "Supply Chain Optimization")
|
| 73 |
+
|
| 74 |
+
if st.button("Research"):
|
| 75 |
+
if company_name and industry_name:
|
| 76 |
+
# Conduct industry research
|
| 77 |
+
trends_results, use_cases_results = industry_research(company_name, industry_name)
|
| 78 |
+
|
| 79 |
+
# Display results
|
| 80 |
+
if 'error' not in trends_results and 'error' not in use_cases_results:
|
| 81 |
+
st.subheader(f"Industry Trends for {company_name} in {industry_name}:")
|
| 82 |
+
trends = summarize_trends(trends_results)
|
| 83 |
+
for trend in trends:
|
| 84 |
+
st.write(trend["Description"])
|
| 85 |
+
|
| 86 |
+
# Propose Use Cases Section
|
| 87 |
+
st.subheader("Proposed Use Cases")
|
| 88 |
+
use_cases = propose_use_cases(use_cases_results)
|
| 89 |
+
for i, use_case in enumerate(use_cases):
|
| 90 |
+
st.write(f"{i + 1}. Use Case {i + 1}: {use_case['Description']}")
|
| 91 |
+
|
| 92 |
+
# Resource Links Section
|
| 93 |
+
st.subheader("Resource Links")
|
| 94 |
+
for result in trends_results + use_cases_results:
|
| 95 |
+
st.write(f"- [Resource: {result.get('title')}]({result.get('link')})")
|
| 96 |
+
|
| 97 |
+
# Save results to CSV
|
| 98 |
+
combined_findings = trends + use_cases # Combine both findings
|
| 99 |
+
csv_filename = save_results_to_csv(combined_findings, company_name)
|
| 100 |
+
st.success(f"Results saved to {csv_filename} in the directory '{SAVE_DIR}'.")
|
| 101 |
+
|
| 102 |
+
else:
|
| 103 |
+
st.error("Error: " + (trends_results.get('error') or use_cases_results.get('error')))
|
| 104 |
+
else:
|
| 105 |
+
st.warning("Please enter both a company name and an industry name.")
|
| 106 |
+
|
| 107 |
+
if __name__ == "__main__":
|
| 108 |
+
main()
|