Spaces:
Sleeping
Sleeping
| import os | |
| import gradio as gr | |
| from textwrap import dedent | |
| import google.generativeai as genai | |
| # Tool import | |
| from crewai.tools.gemini_tools import GeminiSearchTools | |
| from langchain.tools.yahoo_finance_news import YahooFinanceNewsTool | |
| from crewai.tools.browser_tools import BrowserTools | |
| from crewai.tools.sec_tools import SECTools | |
| # Google Langchain | |
| from langchain_google_genai import GoogleGenerativeAI | |
| #Crew imports | |
| from crewai import Agent, Task, Crew, Process | |
| # Retrieve API Key from Environment Variable | |
| GOOGLE_AI_STUDIO = os.environ.get('GOOGLE_API_KEY') | |
| # Ensure the API key is available | |
| if not GOOGLE_AI_STUDIO: | |
| raise ValueError("API key not found. Please set the GOOGLE_AI_STUDIO2 environment variable.") | |
| # Set gemini_llm | |
| gemini_llm = GoogleGenerativeAI(model="gemini-pro", google_api_key=GOOGLE_AI_STUDIO) | |
| # Base Example with Gemini Search | |
| def crewai_process(research_topic): | |
| # Define your agents with roles and goals | |
| researcher = Agent( | |
| role='Senior Research Analyst', | |
| goal=f'Uncover cutting-edge developments in {research_topic}', | |
| backstory="""You are a Senior Research Analyst at a leading think tank. | |
| Your expertise lies in identifying emerging trends. You have a knack for dissecting complex data and presenting | |
| actionable insights.""", | |
| verbose=True, | |
| allow_delegation=False, | |
| llm = gemini_llm, | |
| tools=[ | |
| GeminiSearchTools.gemini_search | |
| ] | |
| ) | |
| writer = Agent( | |
| role='Tech Content Strategist', | |
| goal='Craft compelling content on tech advancements', | |
| backstory="""You are a renowned Tech Social Media Content Writer and Strategist, known for your insightful | |
| and engaging articles on technology and innovation. With a deep understanding of | |
| the tech industry and how people are impacted by it, you transform complex concepts into compelling narratives.""", | |
| verbose=True, | |
| allow_delegation=True, | |
| llm = gemini_llm | |
| # Add tools and other optional parameters as needed | |
| ) | |
| # Create tasks for your agents | |
| task1 = Task( | |
| description=f"""Conduct a comprehensive analysis of the latest advancements in {research_topic}. | |
| Compile your findings in a detailed report. Your final answer MUST be a full analysis report""", | |
| agent=researcher | |
| ) | |
| task2 = Task( | |
| description="""Using the insights from the researcher's report, develop an engaging blog | |
| post that highlights the most significant advancements. | |
| Your post should be informative yet accessible, catering to a tech-savvy audience. | |
| Aim for a narrative that captures the essence of these breakthroughs and their | |
| implications for the future. Your final answer MUST be the full blog post of at least 3 paragraphs.""", | |
| agent=writer | |
| ) | |
| # Instantiate your crew with a sequential process | |
| crew = Crew( | |
| agents=[researcher, writer], | |
| tasks=[task1, task2], | |
| verbose=2, | |
| process=Process.sequential | |
| ) | |
| # Get your crew to work! | |
| result = crew.kickoff() | |
| return result | |
| # Create a Gradio interface | |
| iface = gr.Interface( | |
| fn=crewai_process, | |
| inputs=gr.Textbox(lines=2, placeholder="Enter Research Topic Here..."), | |
| outputs="text", | |
| title="CrewAI on Gemini (Blog Post Writer)", | |
| description="Input a research topic to get a comprehensive analysis (in logs) and a blog post draft (in output). To learn more connect with Mike Lively on LinkedIn at https://www.linkedin.com/in/awsmulticloud/ or join his cloud Meetup at https://www.meetup.com/florence-aws-user-group-meetup/" | |
| ) | |
| # Launch the interface | |
| iface.launch() | |