Spaces:
Sleeping
Sleeping
| 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() | |