Spaces:
Sleeping
Sleeping
File size: 3,324 Bytes
0259192 8fd7c8e 0259192 150c42e 0259192 8495da4 0259192 150c42e 0259192 150c42e 0259192 8fd7c8e |
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 |
import os
import requests
import streamlit as st
import pandas as pd
# Set API keys
os.environ['OPENAI_API_KEY'] = 'AIzaSyC8tIrUlJcCRnyksbykluUZVvER6ynHQeI'
os.environ['SERPAPI_API_KEY'] = '533b5ecf4f322a3e1fb6c6341fc922267805add7e804f7783949a17175ed2f69'
# Define the directory name for saving CSV files
SAVE_DIR = 'saved_csv_files'
# Ensure the save directory exists
os.makedirs(SAVE_DIR, exist_ok=True)
# Define the functions for your workflow
def industry_research(company_name, industry_name):
query = f"{company_name} {industry_name} AI trends"
params = {
"api_key": os.environ['SERPAPI_API_KEY'],
"q": query,
"num": 5
}
response = requests.get("https://serpapi.com/search.json", params=params)
if response.status_code == 200:
search_results = response.json()
return search_results.get('organic_results', [])
else:
return {"error": response.text}
def summarize_findings(search_results):
findings = []
for result in search_results:
title = result.get('title')
link = result.get('link')
description = f"{title} can be explored further at [this link]({link})."
findings.append(description)
return findings
def save_results_to_csv(results, company_name):
df = pd.DataFrame(results)
csv_file_path = os.path.join(SAVE_DIR, f"{company_name}_research_results.csv")
df.to_csv(csv_file_path, index=False)
return csv_file_path # Return the file path for download
def main():
st.title("Multi-Agent Workflow for AI Use Cases")
# Input fields for company and industry
company_name = st.text_input("Enter the Company Name", "Deloitte")
industry_name = st.text_input("Enter the Industry Name", "Supply Chain Optimization")
if st.button("Research"):
if company_name and industry_name:
# Conduct industry research
research_results = industry_research(company_name, industry_name)
# Display results
if 'error' not in research_results:
st.subheader(f"Market Research Findings for {company_name} in {industry_name} Industry:")
findings = summarize_findings(research_results)
for finding in findings:
st.write(finding)
# Proposed Use Cases Section
st.subheader("Proposed Use Cases")
for i, finding in enumerate(findings):
st.write(f"{i + 1}. Use Case {i + 1}: {finding}")
# Resource Links Section
st.subheader("Resource Links")
for result in research_results:
st.write(f"- [Resource: {result.get('title')}]({result.get('link')})")
# Save results to CSV and provide a download link
csv_file_path = save_results_to_csv(research_results, company_name)
with open(csv_file_path, 'rb') as file:
st.download_button(label="Download CSV", data=file, file_name=os.path.basename(csv_file_path), mime='text/csv')
else:
st.error("Error: " + research_results['error'])
else:
st.warning("Please enter both a company name and an industry name.")
if __name__ == "__main__":
main()
|