Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,108 +1,85 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import requests
|
| 3 |
-
import
|
| 4 |
-
import
|
| 5 |
-
|
| 6 |
-
# Set API keys
|
| 7 |
-
os.environ['OPENAI_API_KEY'] = 'AIzaSyC8tIrUlJcCRnyksbykluUZVvER6ynHQeI'
|
| 8 |
-
os.environ['SERPAPI_API_KEY'] = '533b5ecf4f322a3e1fb6c6341fc922267805add7e804f7783949a17175ed2f69'
|
| 9 |
-
|
| 10 |
-
# Define the
|
| 11 |
-
|
| 12 |
-
os.
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
"
|
| 22 |
-
"
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
if
|
| 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 |
-
# 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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|