Yomna35 commited on
Commit
1208e89
1 Parent(s): 151ab9f

Upload 3 files

Browse files
Files changed (3) hide show
  1. main.py +72 -0
  2. main.yml +27 -0
  3. requirements .txt +16 -0
main.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ from langchain_community.llms import LlamaCpp
3
+ from sentence_transformers import SentenceTransformer
4
+ from transformers import AutoTokenizer, AutoModel
5
+
6
+ # cosine_similarity
7
+ import torch
8
+ from torch.nn.functional import cosine_similarity
9
+ import os
10
+ app = Flask(__name__)
11
+
12
+ n_gpu_layers = 0
13
+ n_batch = 1024
14
+
15
+
16
+ llm = LlamaCpp(
17
+ model_path="Phi-3-mini-4k-instruct-q4.gguf", # path to GGUF file
18
+ temperature=0.1,
19
+ n_gpu_layers=n_gpu_layers,
20
+ n_batch=n_batch,
21
+ verbose=True,
22
+ n_ctx=4096
23
+ )
24
+ model0 = AutoModel.from_pretrained('sentence-transformers/paraphrase-TinyBERT-L6-v2')
25
+
26
+ model = SentenceTransformer('sentence-transformers/paraphrase-TinyBERT-L6-v2')
27
+
28
+ file_size = os.stat('Phi-3-mini-4k-instruct-q4.gguf')
29
+ print("model size ====> :", file_size.st_size, "bytes")
30
+
31
+
32
+ @app.route('/cv', methods=['POST'])
33
+ def get_skills():
34
+ cv_body = request.json.get('cv_body')
35
+
36
+ # Simple inference example
37
+ output = llm(
38
+ f"<|user|>\n{cv_body}<|end|>\n<|assistant|>Can you list the skills mentioned in the CV?<|end|>",
39
+ max_tokens=256, # Generate up to 256 tokens
40
+ stop=["<|end|>"],
41
+ echo=True, # Whether to echo the prompt
42
+ )
43
+
44
+ return jsonify({'skills': output})
45
+
46
+ @app.get('/')
47
+ def health():
48
+ return jsonify({'status': 'Worked'})
49
+
50
+ # we will make here post request to compare between lists of skills one has employee just one text and the other has the of jobs has many texts
51
+ # the llm will say the most similar job to the cv
52
+ @app.route('/compare', methods=['POST'])
53
+ def compare():
54
+ employee_skills = request.json.get('employee_skills')# string
55
+ #example: employee_skills = "<|assistant|> Certainly! Based on the provided information, here are the relevant skills listed in my CV:\n\n1. Python programming language proficiency\n2. Java development expertise\n3. Web development experience (including front-end and back-end technologies)\n4. Proficient with machine learning algorithms and frameworks\n5. Strong problem-solving abilities\n6. Excellent communication skills, both written and verbal\n7. Agile methodology adherence\n8. Familiarity with version control systems (e.g., Git)\n9. Experience in designing scalable software architectures\n10. Proficient in testing methodologies such as unit tests, integration tests, and end-to-end tests\n11. Continuous learning mindset to stay updated on the latest technological advancements\n12. Strong collaboration skills for effective teamwork\n\nThese skills enable me to contribute significantly to an employer's objectives by developing innovative features that leverage cutting-edge technology, optimizing software performance through efficient coding practices and algorithmic improvements, enhancing code quality with rigorous testing methodologies, and fostering a collaborative work environment""
56
+ jobs_skills = request.json.get('jobs_skills')
57
+ #example: jobs_skills = ["<|assistant|> Sure! Here are the skills required for the Software Engineer position:\n\n1. Proficiency in Python programming language\n2. Experience with Java development\n3. Knowledge of web development technologies (e.g., HTML, CSS, JavaScript)\n4. Familiarity with machine learning algorithms and frameworks (e.g., TensorFlow, PyTorch)\n5. Strong problem-solving skills\n6. Effective communication abilities\n7. Agile methodology understanding\n8. Version control system expertise (e.g., Git)\n9. Software architecture design experience\n10. Testing methodologies knowledge (unit tests, integration tests, end-to-end tests)\n11. Continuous learning mindset for staying updated on technological advancements\n12. Collaboration skills for effective teamwork\n\nThese skills are essential for the Software Engineer role to contribute to the development of innovative software solutions, optimize performance, ensure code quality, and foster a collaborative work environment.", "<|assistant|> Certainly! Here are the skills required for the Data Scientist position:\n\n1. Proficiency in Python programming language\n2. Experience with data analysis and visualization tools (e.g., Pandas, Matplotlib)\n3. Knowledge of machine learning algorithms and statistical modeling techniques\n4. Strong problem-solving and analytical skills\n5. Effective communication abilities\n6. Agile methodology understanding\n7. Version control system expertise (e.g., Git)\n8. Data preprocessing and cleaning experience\n9. Model evaluation and optimization skills\n10. Continuous learning mindset for staying updated on data science advancements\n11. Collaboration skills for effective teamwork\n\nThese skills are essential for the Data Scientist role to analyze data, develop predictive models, optimize algorithms, and collaborate with cross-functional teams."]
58
+ if not isinstance(jobs_skills, list) or not all(isinstance(skill, str) for skill in jobs_skills):
59
+ raise ValueError("jobs_skills must be a list of strings")
60
+ job_embeddings = model.encode(jobs_skills)
61
+ employee_embeddings = model.encode(employee_skills)
62
+ sim = []
63
+ employee_embeddings_tensor = torch.from_numpy(employee_embeddings).unsqueeze(0)
64
+ for job_e in job_embeddings:
65
+ job_e_tensor = torch.from_numpy(job_e).unsqueeze(0)
66
+ sim.append(cosine_similarity(employee_embeddings_tensor, job_e_tensor,dim=1))
67
+ max_sim = max(sim)
68
+ index = sim.index(max_sim)
69
+ return jsonify({'job': jobs_skills[index]})
70
+
71
+ if __name__ == '__main__':
72
+ app.run()
main.yml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Python application
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+
16
+ - name: Set up Python 3.x
17
+ uses: actions/setup-python@v2
18
+ with:
19
+ python-version: '3.x'
20
+
21
+ - name: Install dependencies
22
+ run: |
23
+ python -m pip install --upgrade pip
24
+ pip install -r requirements.txt
25
+
26
+ - name: Run the app
27
+ run: python app.py
requirements .txt ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ flask
2
+ langchain
3
+ matplotlib
4
+ numpy
5
+ gensim
6
+ scikit-learn
7
+ llama-cpp-python
8
+ huggingface-hub
9
+ langchain
10
+ langchain-experimental
11
+ scipy==1.10.1
12
+ gunicorn
13
+ langchain-community
14
+ sentence-transformers
15
+ torch
16
+ transformers