Satyam0077 commited on
Commit
0259192
·
verified ·
1 Parent(s): 60fcdc2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -108
app.py CHANGED
@@ -1,108 +1,85 @@
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()
 
1
+ import os
2
+ import requests
3
+ import streamlit as st
4
+ import pandas as pd
5
+
6
+ # Set API keys
7
+ os.environ['OPENAI_API_KEY'] = 'AIzaSyC8tIrUlJcCRnyksbykluUZVvER6ynHQeI'
8
+ os.environ['SERPAPI_API_KEY'] = '533b5ecf4f322a3e1fb6c6341fc922267805add7e804f7783949a17175ed2f69'
9
+
10
+ # Define the path for saving CSV files
11
+ HUGGING_FACE_FOLDER = 'https://huggingface.co/spaces/Satyam0077/MultiAgentWorkflowAI/tree/main' # Update this to your actual Hugging Face directory
12
+ SAVE_DIR = os.path.join(HUGGING_FACE_FOLDER, 'DeloitteResearchAgent')
13
+
14
+ # Ensure the save directory exists
15
+ os.makedirs(SAVE_DIR, exist_ok=True)
16
+
17
+ # Define the functions for your workflow
18
+ def industry_research(company_name, industry_name):
19
+ query = f"{company_name} {industry_name} AI trends"
20
+ params = {
21
+ "api_key": os.environ['SERPAPI_API_KEY'],
22
+ "q": query,
23
+ "num": 5
24
+ }
25
+ response = requests.get("https://serpapi.com/search.json", params=params)
26
+ if response.status_code == 200:
27
+ search_results = response.json()
28
+ return search_results.get('organic_results', [])
29
+ else:
30
+ return {"error": response.text}
31
+
32
+ def summarize_findings(search_results):
33
+ findings = []
34
+ for result in search_results:
35
+ title = result.get('title')
36
+ link = result.get('link')
37
+ description = f"{title} can be explored further at [this link]({link})."
38
+ findings.append(description)
39
+ return findings
40
+
41
+ def save_results_to_csv(results, company_name):
42
+ df = pd.DataFrame(results)
43
+ csv_file_path = os.path.join(SAVE_DIR, f"{company_name}_research_results.csv")
44
+ df.to_csv(csv_file_path, index=False)
45
+ st.success(f"Results saved to {csv_file_path}")
46
+
47
+ def main():
48
+ st.title("Multi-Agent Workflow for AI Use Cases")
49
+
50
+ # Input fields for company and industry
51
+ company_name = st.text_input("Enter the Company Name", "Deloitte")
52
+ industry_name = st.text_input("Enter the Industry Name", "Supply Chain Optimization")
53
+
54
+ if st.button("Research"):
55
+ if company_name and industry_name:
56
+ # Conduct industry research
57
+ research_results = industry_research(company_name, industry_name)
58
+
59
+ # Display results
60
+ if 'error' not in research_results:
61
+ st.subheader(f"Market Research Findings for {company_name} in {industry_name} Industry:")
62
+ findings = summarize_findings(research_results)
63
+ for finding in findings:
64
+ st.write(finding)
65
+
66
+ # Proposed Use Cases Section
67
+ st.subheader("Proposed Use Cases")
68
+ for i, finding in enumerate(findings):
69
+ st.write(f"{i + 1}. Use Case {i + 1}: {finding}")
70
+
71
+ # Resource Links Section
72
+ st.subheader("Resource Links")
73
+ for result in research_results:
74
+ st.write(f"- [Resource: {result.get('title')}]({result.get('link')})")
75
+
76
+ # Save results to CSV
77
+ save_results_to_csv(research_results, company_name)
78
+
79
+ else:
80
+ st.error("Error: " + research_results['error'])
81
+ else:
82
+ st.warning("Please enter both a company name and an industry name.")
83
+
84
+ if __name__ == "__main__":
85
+ main()