From 1bc4bf20d696208b319b4eea48d7ac85f99c601c Mon Sep 17 00:00:00 2001 From: taltaf913 Date: Sat, 8 Mar 2025 18:49:40 +0000 Subject: [PATCH 1/2] Initial commit From ec6b2e36685797446a662be6ca4d4c0b8b4d5348 Mon Sep 17 00:00:00 2001 From: taltaf913 Date: Sat, 8 Mar 2025 18:49:41 +0000 Subject: [PATCH 2/2] Pending changes exported from your codespace --- agents/.python-version | 1 + agents/README.md | 0 agents/crew_zaai/main.py | 6 ++ agents/crew_zaai/pyproject.toml | 7 ++ .../src/crew_zaai/config/agents.yaml | 13 ++-- .../crew_zaai/src/crew_zaai/config/tasks.yaml | 27 ++++--- agents/crew_zaai/src/crew_zaai/crew.py | 13 ++-- agents/crew_zaai/src/crew_zaai/main.py | 19 ----- .../crew_zaai/src/crew_zaai/streamlit_app.py | 56 ++++++++++++++ .../crew_zaai/src/crew_zaai/tools/youtube.py | 2 +- agents/crew_zaai/src/streamlit_app.py | 76 +++++++++++++++++++ agents/main.py | 6 ++ agents/pyproject.toml | 10 +++ agents/uv.lock | 19 +++++ 14 files changed, 214 insertions(+), 41 deletions(-) create mode 100644 agents/.python-version create mode 100644 agents/README.md create mode 100644 agents/crew_zaai/main.py create mode 100644 agents/crew_zaai/pyproject.toml delete mode 100644 agents/crew_zaai/src/crew_zaai/main.py create mode 100644 agents/crew_zaai/src/crew_zaai/streamlit_app.py create mode 100644 agents/crew_zaai/src/streamlit_app.py create mode 100644 agents/main.py create mode 100644 agents/pyproject.toml create mode 100644 agents/uv.lock diff --git a/agents/.python-version b/agents/.python-version new file mode 100644 index 0000000..c8cfe39 --- /dev/null +++ b/agents/.python-version @@ -0,0 +1 @@ +3.10 diff --git a/agents/README.md b/agents/README.md new file mode 100644 index 0000000..e69de29 diff --git a/agents/crew_zaai/main.py b/agents/crew_zaai/main.py new file mode 100644 index 0000000..7094402 --- /dev/null +++ b/agents/crew_zaai/main.py @@ -0,0 +1,6 @@ +def main(): + print("Hello from crew-zaai!") + + +if __name__ == "__main__": + main() diff --git a/agents/crew_zaai/pyproject.toml b/agents/crew_zaai/pyproject.toml new file mode 100644 index 0000000..17a0ea4 --- /dev/null +++ b/agents/crew_zaai/pyproject.toml @@ -0,0 +1,7 @@ +[project] +name = "crew-zaai" +version = "0.1.0" +description = "Add your description here" +readme = "README.md" +requires-python = ">=3.10" +dependencies = [] diff --git a/agents/crew_zaai/src/crew_zaai/config/agents.yaml b/agents/crew_zaai/src/crew_zaai/config/agents.yaml index 9cef032..494d9a4 100644 --- a/agents/crew_zaai/src/crew_zaai/config/agents.yaml +++ b/agents/crew_zaai/src/crew_zaai/config/agents.yaml @@ -19,12 +19,13 @@ summarizer: You're known for your ability to summarize and retrive facts, references, quotes and recommend the most useful surprising information about the {topic}. -blog_writer: +linkedin_post_writer: role: > - {topic} Blog Writer + {topic} LinkedIn Engagement Specialist goal: > - Create detailed blog posts based on {topic} research findings + Craft high-impact LinkedIn posts about {topic} to maximize engagement and professional reach.Note: Please shorten your post and try again. Max 3000 characters backstory: > - You're a meticulous writer with a keen eye for detail. - You're known for your ability to turn complex topics into clear and concise blog posts, - making it easy for others to understand and act on the information you provide. + You are a seasoned social media strategist with a specialty in LinkedIn. + You understand the nuances of the LinkedIn algorithm and what content resonates with professionals. + Your expertise lies in creating concise, engaging posts that spark conversations, build thought leadership, and expand professional networks around key topics. + Note: Please shorten your post and try again. Max 3000 characters diff --git a/agents/crew_zaai/src/crew_zaai/config/tasks.yaml b/agents/crew_zaai/src/crew_zaai/config/tasks.yaml index 9c87282..545002a 100644 --- a/agents/crew_zaai/src/crew_zaai/config/tasks.yaml +++ b/agents/crew_zaai/src/crew_zaai/config/tasks.yaml @@ -2,10 +2,10 @@ research_task: description: > Conduct a thorough research about {topic} Make sure you find any interesting and relevant youtube links given - the current year is 2024. + the current year is 2025. expected_output: > A list with youtube URLs that cover {topic} and the respective description - with the most relevant information about {topic}. Ignore any links that don't + with the most relevant information about {topic}. and do have subtitles enabled.Ignore any links that don't start with "https://www.youtube.com". agent: researcher @@ -22,12 +22,19 @@ summarize_task: write_task: description: > - Review the context you got and expand each topic into a full section for a blog post. - Make sure the blog post is detailed and contains any and all relevant information. - The blog post must contain an introduction, a body, a code example and a conclusion section. + Review the context you got and craft engaging LinkedIn posts for each key topic. + Each post should be concise, insightful, and tailored for a professional audience on LinkedIn. + The LinkedIn post series must include an introductory post, several posts covering each main topic, a post with a code example (if relevant and simplified for LinkedIn), and a concluding post. expected_output: > - A fully-fledged blog post with the main topics, each presented as a complete section of information. - Format it as HTML without using '```'. Make it look like a professional tech blog website, - including a navbar, menu, and styling. Incorporate YouTube links as clickable references within - the text and at the end. - agent: blog_writer + A series of structured LinkedIn post drafts, one for each topic. + Format each post as text, optimized for LinkedIn's platform. + Note: Please shorten your post and try again. Max 3000 characters. + Focus on: + - Engaging opening lines to grab attention. + - Concise bullet points or short paragraphs for key information. + - Relevant hashtags for discoverability. + - A professional yet approachable tone. + - A clear call to action or question to encourage engagement (optional). + Avoid using '```' and aim for a professional, LinkedIn-style presentation. + agent: linkedin_post_writer # Agent designed to write LinkedIn posts + diff --git a/agents/crew_zaai/src/crew_zaai/crew.py b/agents/crew_zaai/src/crew_zaai/crew.py index 38ac0c2..6f86658 100644 --- a/agents/crew_zaai/src/crew_zaai/crew.py +++ b/agents/crew_zaai/src/crew_zaai/crew.py @@ -1,8 +1,11 @@ -import os from crewai import Agent, Crew, Process, Task from crewai.project import CrewBase, agent, crew, task -from crew_zaai.src.crew_zaai.tools.searx import SearxSearchTool -from crew_zaai.src.crew_zaai.tools.youtube import YouTubeTranscriptTool +import sys +import os +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) # Add current directory of crew.py to path +sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) # Add parent directory (src) to path, assuming 'tools' is in 'src' +from tools.searx import SearxSearchTool +from tools.youtube import YouTubeTranscriptTool @CrewBase @@ -31,8 +34,8 @@ def summarizer(self) -> Agent: ) @agent - def blog_writer(self) -> Agent: - return Agent(config=self.agents_config["blog_writer"], verbose=True) + def linkedin_post_writer(self) -> Agent: + return Agent(config=self.agents_config["linkedin_post_writer"], verbose=True) @task def research_task(self) -> Task: diff --git a/agents/crew_zaai/src/crew_zaai/main.py b/agents/crew_zaai/src/crew_zaai/main.py deleted file mode 100644 index 8ef1f62..0000000 --- a/agents/crew_zaai/src/crew_zaai/main.py +++ /dev/null @@ -1,19 +0,0 @@ -import warnings - -from crew_zaai.src.crew_zaai.crew import CrewZaai -from dotenv import load_dotenv - - -warnings.filterwarnings("ignore", category=SyntaxWarning, module="pysbd") -load_dotenv() - - -def run(): - """Run the crew.""" - - inputs = {"topic": "AI Agents"} - CrewZaai().crew().kickoff(inputs=inputs) - - -if __name__ == "__main__": - run() diff --git a/agents/crew_zaai/src/crew_zaai/streamlit_app.py b/agents/crew_zaai/src/crew_zaai/streamlit_app.py new file mode 100644 index 0000000..9c94af2 --- /dev/null +++ b/agents/crew_zaai/src/crew_zaai/streamlit_app.py @@ -0,0 +1,56 @@ +import streamlit as st +import warnings +from dotenv import load_dotenv +from src.crew_zaai.crew import CrewZaai +import sys +import os + +# Assuming your crew.py and CrewZaai class are correctly set up in crew_zaai package +# Get the directory where your streamlit_app.py is located +current_dir = os.path.dirname(os.path.abspath(__file__)) +src_dir = os.path.join(current_dir, "src") # Assuming 'src' is in the same directory as streamlit_app.py +if os.path.exists(src_dir): + sys.path.insert(0, src_dir) # Add 'src' directory to Python path +else: + src_dir_parent = os.path.dirname(current_dir) # Check if 'src' is in the parent directory + src_dir_parent_check = os.path.join(src_dir_parent, "src") + if os.path.exists(src_dir_parent_check): + sys.path.insert(0, src_dir_parent_check) # Add parent 'src' if found + else: + print(f"Warning: 'src' directory not found in '{current_dir}' or parent directory. Import errors may occur.") + + +warnings.filterwarnings("ignore", category=SyntaxWarning, module="pysbd") +load_dotenv() + +def run_crew_zaai(topic): + """Runs the CrewZaai crew with the given topic and returns the output.""" + try: + crew_instance = CrewZaai() # Instantiate CrewZaai class + crew = crew_instance.crew() # Get the crew object + result = crew.kickoff(inputs={"topic": topic}) # Run kickoff and capture the result + return result + except Exception as e: + return {"error": f"An error occurred while running the crew: {e}"} + +def main(): + st.title("CrewZaai AI Agent Runner") + + topic = st.text_input("Enter a Topic for the AI Agents to Explore:", "AI Agents 2024") + + if st.button("Run Crew"): + if not topic: + st.warning("Please enter a topic.") + else: + with st.spinner(text="Running CrewZaai..."): + output = run_crew_zaai(topic) + + st.subheader("CrewZaai Output:") + if "error" in output: + st.error(output["error"]) + else: + # Assuming the output is a dictionary or string that can be displayed + st.write(output) # You might need to format this output better depending on its structure + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/agents/crew_zaai/src/crew_zaai/tools/youtube.py b/agents/crew_zaai/src/crew_zaai/tools/youtube.py index 90a28e9..f04cc49 100644 --- a/agents/crew_zaai/src/crew_zaai/tools/youtube.py +++ b/agents/crew_zaai/src/crew_zaai/tools/youtube.py @@ -64,7 +64,7 @@ def _run( Runs the YouTubeTranscriptTool with the given parameters. Args: - video_url (list[str]): The list of YouTube video URLs to fetch the transcript for. + video_url (list[str]): The list of YouTube video URLs to fetch the transcript for and do have subtitles enabled. language (Optional[str]): The language code for the transcript (e.g., 'en' for English). Returns: diff --git a/agents/crew_zaai/src/streamlit_app.py b/agents/crew_zaai/src/streamlit_app.py new file mode 100644 index 0000000..de3ed8c --- /dev/null +++ b/agents/crew_zaai/src/streamlit_app.py @@ -0,0 +1,76 @@ +import streamlit as st +import warnings +from dotenv import load_dotenv +from crew_zaai.crew import CrewZaai +import sys +import os +import json + +# Assuming your crew.py and CrewZaai class are correctly set up in crew_zaai package +# Get the directory where your streamlit_app.py is located +current_dir = os.path.dirname(os.path.abspath(__file__)) +src_dir = os.path.join(current_dir, "src") # Assuming 'src' is in the same directory as streamlit_app.py +if os.path.exists(src_dir): + sys.path.insert(0, src_dir) # Add 'src' directory to Python path +else: + src_dir_parent = os.path.dirname(current_dir) # Check if 'src' is in the parent directory + src_dir_parent_check = os.path.join(src_dir_parent, "src") + if os.path.exists(src_dir_parent_check): + sys.path.insert(0, src_dir_parent_check) # Add parent 'src' if found + else: + print(f"Warning: 'src' directory not found in '{current_dir}' or parent directory. Import errors may occur.") + + +warnings.filterwarnings("ignore", category=SyntaxWarning, module="pysbd") +load_dotenv() + +def run_crew_zaai(topic): + """Runs the CrewZaai crew with the given topic and returns the output.""" + try: + crew_instance = CrewZaai() # Instantiate CrewZaai class + crew = crew_instance.crew() # Get the crew object + result = crew.kickoff(inputs={"topic": topic}) # Run kickoff and capture the result + return result + except Exception as e: + return {"error": f"An error occurred while running the crew: {e}"} + +def main(): + st.title("Multi Agents AI for research/Summarizer and Linkindin post") # Updated title + + topic = st.text_input("Enter a Topic for the AI Agents to Explore:", "Agentic AI 2025") + + if st.button("Button"): + if not topic: + st.warning("Please enter a topic.") + else: + with st.spinner(text="Running ..."): + output = run_crew_zaai(topic) + + st.subheader("Task Outputs:") # Updated subheader + + if "error" in output: + st.error(output["error"]) + else: + if isinstance(output, dict) and "tasks_output" in output: + tasks_output_list = output["tasks_output"] # Get the list of TaskOutput objects + + for i, task_output in enumerate(tasks_output_list): + st.subheader(f"Task {i+1}: {task_output.summary}") # Display task summary as subheader + + try: + # Try to parse task_output.raw as JSON (dictionary) + raw_dict = json.loads(task_output.raw) + st.json(raw_dict) # Display as JSON if parsing is successful + except json.JSONDecodeError: + # If JSON parsing fails, display as plain text + st.text_area(f"Task {i+1} Output (Plain Text)", value=task_output.raw, height=1500) + except TypeError: # Handle cases where task_output.raw might not be a string + st.text_area(f"Task {i+1} Output (Plain Text, Non-String Raw)", value=str(task_output.raw), height=1500) + + + else: + st.write(output) # Fallback to raw output if format is unexpected + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/agents/main.py b/agents/main.py new file mode 100644 index 0000000..5f053a8 --- /dev/null +++ b/agents/main.py @@ -0,0 +1,6 @@ +def main(): + print("Hello from agents!") + + +if __name__ == "__main__": + main() diff --git a/agents/pyproject.toml b/agents/pyproject.toml new file mode 100644 index 0000000..58f3ad4 --- /dev/null +++ b/agents/pyproject.toml @@ -0,0 +1,10 @@ +[project] +name = "agents" +version = "0.1.0" +description = "Add your description here" +readme = "README.md" +requires-python = ">=3.10" +dependencies = [] + +[tool.uv.workspace] +members = ["crew_zaai"] diff --git a/agents/uv.lock b/agents/uv.lock new file mode 100644 index 0000000..3b6878e --- /dev/null +++ b/agents/uv.lock @@ -0,0 +1,19 @@ +version = 1 +revision = 1 +requires-python = ">=3.10" + +[manifest] +members = [ + "agents", + "crew-zaai", +] + +[[package]] +name = "agents" +version = "0.1.0" +source = { virtual = "." } + +[[package]] +name = "crew-zaai" +version = "0.1.0" +source = { virtual = "crew_zaai" }