Johnny commited on
Commit
2600a8c
·
1 Parent(s): 30b3b49

added app.py crewai.py database.py requirements.txt multi_agent folder

Browse files
app.py CHANGED
@@ -1,33 +1,24 @@
1
  import streamlit as st
2
  import requests
3
- import redis
4
- import psycopg2
5
 
6
- # Redis Connection
7
- redis_client = redis.Redis(host='redis-19703.c289.us-west-1-2.ec2.redns.redis-cloud.com', port=19703, db=0, decode_responses=True)
8
 
9
- # PostgreSQL Connection
10
- conn = psycopg2.connect(database="screening_db", user="user", password="password", host="localhost", port="5432")
11
- cursor = conn.cursor()
12
 
13
- HF_API_URL = "https://api-inference.huggingface.co/models/your-hf-model-id"
14
 
15
- st.title("AI Candidate Screening")
16
-
17
- resume_text = st.text_area("Paste Candidate Resume")
18
-
19
- if st.button("Analyze Resume"):
20
- cache_key = f"resume:{resume_text[:20]}" # Hash first 20 chars
21
- cached_response = redis_client.get(cache_key)
22
 
23
- if cached_response:
24
- st.write("Cached Response:", cached_response)
25
- else:
26
- response = requests.post(HF_API_URL, json={"inputs": resume_text}).json()
27
- redis_client.set(cache_key, response, ex=3600) # Cache for 1 hour
 
28
 
29
- # Store result in PostgreSQL
30
- cursor.execute("INSERT INTO screenings (resume_text, result) VALUES (%s, %s)", (resume_text, response))
31
- conn.commit()
32
 
33
- st.write("AI Response:", response)
 
1
  import streamlit as st
2
  import requests
3
+ from database import save_resume_data
4
+ from crewai import ResumeAgents
5
 
6
+ st.title("AI-Powered Resume Screening")
 
7
 
8
+ uploaded_files = st.file_uploader("Upload Resumes", accept_multiple_files=True, type=["pdf", "txt"])
 
 
9
 
10
+ job_description = st.text_area("Enter Job Description")
11
 
12
+ if st.button("Process Resumes"):
13
+ results = []
 
 
 
 
 
14
 
15
+ for uploaded_file in uploaded_files:
16
+ resume_text = uploaded_file.read().decode("utf-8")
17
+ parsed_details = ResumeAgents.parse_resume(resume_text)
18
+ ranking_score = ResumeAgents.rank_resume(parsed_details, job_description)
19
+
20
+ save_resume_data(resume_text, parsed_details, ranking_score)
21
 
22
+ results.append(f"Resume: {uploaded_file.name}\nRank: {ranking_score}\nDetails: {parsed_details}")
 
 
23
 
24
+ st.write("\n\n".join(results))
crewai.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from crewai import Crew, Agent, Task
2
+ from huggingface_hub import InferenceClient
3
+ import os
4
+
5
+ HF_API_URL = "https://api-inference.huggingface.co/models/YOUR_MODEL"
6
+ HF_API_KEY = "your_api_key"
7
+
8
+ client = InferenceClient(token=HF_API_KEY)
9
+
10
+ class ResumeAgents:
11
+ @staticmethod
12
+ def parse_resume(resume_text):
13
+ """Agent to extract key resume details"""
14
+ prompt = f"Extract skills, experience, and education from this resume:\n{resume_text}"
15
+ response = client.text_generation(prompt)
16
+ return response
17
+
18
+ @staticmethod
19
+ def rank_resume(resume_details, job_description):
20
+ """Agent to rank the resume against the job description"""
21
+ prompt = f"Rank this resume based on the job description:\nJob: {job_description}\nResume: {resume_details}"
22
+ response = client.text_generation(prompt)
23
+ return response
24
+
25
+ @staticmethod
26
+ def recommend_candidates(resume_rankings):
27
+ """Agent to recommend the best candidates"""
28
+ prompt = f"Recommend the top candidates based on rankings:\n{resume_rankings}"
29
+ response = client.text_generation(prompt)
30
+ return response
database.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import psycopg2
2
+ from sqlalchemy import create_engine
3
+
4
+ DATABASE_URL = "postgresql://user:password@localhost:5432/resumes_db"
5
+
6
+ engine = create_engine(DATABASE_URL)
7
+
8
+ def save_resume_data(resume_text, parsed_details, ranking_score):
9
+ """Save parsed resume details and ranking score to DB"""
10
+ with engine.connect() as conn:
11
+ conn.execute(
12
+ "INSERT INTO resumes (resume_text, parsed_details, ranking_score) VALUES (%s, %s, %s)",
13
+ (resume_text, parsed_details, ranking_score)
14
+ )
multi_crew/.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ .env
2
+ __pycache__/
3
+ .DS_Store
multi_crew/README.md ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # LatestAiDevelopment Crew
2
+
3
+ Welcome to the LatestAiDevelopment Crew project, powered by [crewAI](https://crewai.com). This template is designed to help you set up a multi-agent AI system with ease, leveraging the powerful and flexible framework provided by crewAI. Our goal is to enable your agents to collaborate effectively on complex tasks, maximizing their collective intelligence and capabilities.
4
+
5
+ ## Installation
6
+
7
+ Ensure you have Python >=3.10 <3.13 installed on your system. This project uses [UV](https://docs.astral.sh/uv/) for dependency management and package handling, offering a seamless setup and execution experience.
8
+
9
+ First, if you haven't already, install uv:
10
+
11
+ ```bash
12
+ pip install uv
13
+ ```
14
+
15
+ Next, navigate to your project directory and install the dependencies:
16
+
17
+ (Optional) Lock the dependencies and install them by using the CLI command:
18
+ ```bash
19
+ crewai install
20
+ ```
21
+ ### Customizing
22
+
23
+ **Add your `OPENAI_API_KEY` into the `.env` file**
24
+
25
+ - Modify `src/latest_ai_development/config/agents.yaml` to define your agents
26
+ - Modify `src/latest_ai_development/config/tasks.yaml` to define your tasks
27
+ - Modify `src/latest_ai_development/crew.py` to add your own logic, tools and specific args
28
+ - Modify `src/latest_ai_development/main.py` to add custom inputs for your agents and tasks
29
+
30
+ ## Running the Project
31
+
32
+ To kickstart your crew of AI agents and begin task execution, run this from the root folder of your project:
33
+
34
+ ```bash
35
+ $ crewai run
36
+ ```
37
+
38
+ This command initializes the latest-ai-development Crew, assembling the agents and assigning them tasks as defined in your configuration.
39
+
40
+ This example, unmodified, will run the create a `report.md` file with the output of a research on LLMs in the root folder.
41
+
42
+ ## Understanding Your Crew
43
+
44
+ The latest-ai-development Crew is composed of multiple AI agents, each with unique roles, goals, and tools. These agents collaborate on a series of tasks, defined in `config/tasks.yaml`, leveraging their collective skills to achieve complex objectives. The `config/agents.yaml` file outlines the capabilities and configurations of each agent in your crew.
45
+
46
+ ## Support
47
+
48
+ For support, questions, or feedback regarding the LatestAiDevelopment Crew or crewAI.
49
+ - Visit our [documentation](https://docs.crewai.com)
50
+ - Reach out to us through our [GitHub repository](https://github.com/joaomdmoura/crewai)
51
+ - [Join our Discord](https://discord.com/invite/X4JWnZnxPb)
52
+ - [Chat with our docs](https://chatg.pt/DWjSBZn)
53
+
54
+ Let's create wonders together with the power and simplicity of crewAI.
multi_crew/pyproject.toml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "latest_ai_development"
3
+ version = "0.1.0"
4
+ description = "latest-ai-development using crewAI"
5
+ authors = [{ name = "Your Name", email = "you@example.com" }]
6
+ requires-python = ">=3.10,<3.13"
7
+ dependencies = [
8
+ "crewai[tools]>=0.105.0,<1.0.0"
9
+ ]
10
+
11
+ [project.scripts]
12
+ latest_ai_development = "latest_ai_development.main:run"
13
+ run_crew = "latest_ai_development.main:run"
14
+ train = "latest_ai_development.main:train"
15
+ replay = "latest_ai_development.main:replay"
16
+ test = "latest_ai_development.main:test"
17
+
18
+ [build-system]
19
+ requires = ["hatchling"]
20
+ build-backend = "hatchling.build"
21
+
22
+ [tool.crewai]
23
+ type = "crew"
multi_crew/src/latest_ai_development/__init__.py ADDED
File without changes
multi_crew/src/latest_ai_development/config/agents.yaml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ researcher:
2
+ role: >
3
+ {topic} Senior Data Researcher
4
+ goal: >
5
+ Uncover cutting-edge developments in {topic}
6
+ backstory: >
7
+ You're a seasoned researcher with a knack for uncovering the latest
8
+ developments in {topic}. Known for your ability to find the most relevant
9
+ information and present it in a clear and concise manner.
10
+
11
+ reporting_analyst:
12
+ role: >
13
+ {topic} Reporting Analyst
14
+ goal: >
15
+ Create detailed reports based on {topic} data analysis and research findings
16
+ backstory: >
17
+ You're a meticulous analyst with a keen eye for detail. You're known for
18
+ your ability to turn complex data into clear and concise reports, making
19
+ it easy for others to understand and act on the information you provide.
multi_crew/src/latest_ai_development/config/tasks.yaml ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ research_task:
2
+ description: >
3
+ Conduct a thorough research about {topic}
4
+ Make sure you find any interesting and relevant information given
5
+ the current year is {current_year}.
6
+ expected_output: >
7
+ A list with 10 bullet points of the most relevant information about {topic}
8
+ agent: researcher
9
+
10
+ reporting_task:
11
+ description: >
12
+ Review the context you got and expand each topic into a full section for a report.
13
+ Make sure the report is detailed and contains any and all relevant information.
14
+ expected_output: >
15
+ A fully fledged report with the main topics, each with a full section of information.
16
+ Formatted as markdown without '```'
17
+ agent: reporting_analyst
multi_crew/src/latest_ai_development/crew.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from crewai import Agent, Crew, Process, Task
2
+ from crewai.project import CrewBase, agent, crew, task
3
+
4
+ # If you want to run a snippet of code before or after the crew starts,
5
+ # you can use the @before_kickoff and @after_kickoff decorators
6
+ # https://docs.crewai.com/concepts/crews#example-crew-class-with-decorators
7
+
8
+ @CrewBase
9
+ class LatestAiDevelopment():
10
+ """LatestAiDevelopment crew"""
11
+
12
+ # Learn more about YAML configuration files here:
13
+ # Agents: https://docs.crewai.com/concepts/agents#yaml-configuration-recommended
14
+ # Tasks: https://docs.crewai.com/concepts/tasks#yaml-configuration-recommended
15
+ agents_config = 'config/agents.yaml'
16
+ tasks_config = 'config/tasks.yaml'
17
+
18
+ # If you would like to add tools to your agents, you can learn more about it here:
19
+ # https://docs.crewai.com/concepts/agents#agent-tools
20
+ @agent
21
+ def researcher(self) -> Agent:
22
+ return Agent(
23
+ config=self.agents_config['researcher'],
24
+ verbose=True
25
+ )
26
+
27
+ @agent
28
+ def reporting_analyst(self) -> Agent:
29
+ return Agent(
30
+ config=self.agents_config['reporting_analyst'],
31
+ verbose=True
32
+ )
33
+
34
+ # To learn more about structured task outputs,
35
+ # task dependencies, and task callbacks, check out the documentation:
36
+ # https://docs.crewai.com/concepts/tasks#overview-of-a-task
37
+ @task
38
+ def research_task(self) -> Task:
39
+ return Task(
40
+ config=self.tasks_config['research_task'],
41
+ )
42
+
43
+ @task
44
+ def reporting_task(self) -> Task:
45
+ return Task(
46
+ config=self.tasks_config['reporting_task'],
47
+ output_file='report.md'
48
+ )
49
+
50
+ @crew
51
+ def crew(self) -> Crew:
52
+ """Creates the LatestAiDevelopment crew"""
53
+ # To learn how to add knowledge sources to your crew, check out the documentation:
54
+ # https://docs.crewai.com/concepts/knowledge#what-is-knowledge
55
+
56
+ return Crew(
57
+ agents=self.agents, # Automatically created by the @agent decorator
58
+ tasks=self.tasks, # Automatically created by the @task decorator
59
+ process=Process.sequential,
60
+ verbose=True,
61
+ # process=Process.hierarchical, # In case you wanna use that instead https://docs.crewai.com/how-to/Hierarchical/
62
+ )
multi_crew/src/latest_ai_development/main.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ import sys
3
+ import warnings
4
+
5
+ from datetime import datetime
6
+
7
+ from latest_ai_development.crew import LatestAiDevelopment
8
+
9
+ warnings.filterwarnings("ignore", category=SyntaxWarning, module="pysbd")
10
+
11
+ # This main file is intended to be a way for you to run your
12
+ # crew locally, so refrain from adding unnecessary logic into this file.
13
+ # Replace with inputs you want to test with, it will automatically
14
+ # interpolate any tasks and agents information
15
+
16
+ def run():
17
+ """
18
+ Run the crew.
19
+ """
20
+ inputs = {
21
+ 'topic': 'AI LLMs',
22
+ 'current_year': str(datetime.now().year)
23
+ }
24
+
25
+ try:
26
+ LatestAiDevelopment().crew().kickoff(inputs=inputs)
27
+ except Exception as e:
28
+ raise Exception(f"An error occurred while running the crew: {e}")
29
+
30
+
31
+ def train():
32
+ """
33
+ Train the crew for a given number of iterations.
34
+ """
35
+ inputs = {
36
+ "topic": "AI LLMs"
37
+ }
38
+ try:
39
+ LatestAiDevelopment().crew().train(n_iterations=int(sys.argv[1]), filename=sys.argv[2], inputs=inputs)
40
+
41
+ except Exception as e:
42
+ raise Exception(f"An error occurred while training the crew: {e}")
43
+
44
+ def replay():
45
+ """
46
+ Replay the crew execution from a specific task.
47
+ """
48
+ try:
49
+ LatestAiDevelopment().crew().replay(task_id=sys.argv[1])
50
+
51
+ except Exception as e:
52
+ raise Exception(f"An error occurred while replaying the crew: {e}")
53
+
54
+ def test():
55
+ """
56
+ Test the crew execution and returns the results.
57
+ """
58
+ inputs = {
59
+ "topic": "AI LLMs",
60
+ "current_year": str(datetime.now().year)
61
+ }
62
+ try:
63
+ LatestAiDevelopment().crew().test(n_iterations=int(sys.argv[1]), openai_model_name=sys.argv[2], inputs=inputs)
64
+
65
+ except Exception as e:
66
+ raise Exception(f"An error occurred while testing the crew: {e}")
multi_crew/src/latest_ai_development/tools/__init__.py ADDED
File without changes
multi_crew/src/latest_ai_development/tools/custom_tool.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from crewai.tools import BaseTool
2
+ from typing import Type
3
+ from pydantic import BaseModel, Field
4
+
5
+
6
+ class MyCustomToolInput(BaseModel):
7
+ """Input schema for MyCustomTool."""
8
+ argument: str = Field(..., description="Description of the argument.")
9
+
10
+ class MyCustomTool(BaseTool):
11
+ name: str = "Name of my tool"
12
+ description: str = (
13
+ "Clear description for what this tool is useful for, your agent will need this information to use it."
14
+ )
15
+ args_schema: Type[BaseModel] = MyCustomToolInput
16
+
17
+ def _run(self, argument: str) -> str:
18
+ # Implementation goes here
19
+ return "this is an example of a tool output, ignore it and move along."