Ahmed007 commited on
Commit
ea91e61
1 Parent(s): 095d427

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +68 -40
main.py CHANGED
@@ -1,41 +1,69 @@
1
- from flask import Flask, request, jsonify
2
- from langchain_community.llms import LlamaCpp
3
- import os
4
- app = Flask(__name__)
5
-
6
- n_gpu_layers = 0
7
- n_batch = 1024
8
-
9
-
10
- llm = LlamaCpp(
11
- model_path="Phi-3-mini-4k-instruct-q4.gguf", # path to GGUF file
12
- temperature=0.1,
13
- n_gpu_layers=n_gpu_layers,
14
- n_batch=n_batch,
15
- verbose=True,
16
- n_ctx=4096
17
- )
18
- file_size = os.stat('Phi-3-mini-4k-instruct-q4.gguf')
19
- print("model size ====> :", file_size.st_size, "bytes")
20
-
21
-
22
- @app.route('/cv', methods=['POST'])
23
- def get_skills():
24
- cv_body = request.json.get('cv_body')
25
-
26
- # Simple inference example
27
- output = llm(
28
- f"<|user|>\n{cv_body}<|end|>\n<|assistant|>Can you list the skills mentioned in the CV?<|end|>",
29
- max_tokens=256, # Generate up to 256 tokens
30
- stop=["<|end|>"],
31
- echo=True, # Whether to echo the prompt
32
- )
33
-
34
- return jsonify({'skills': output})
35
-
36
- @app.get('/')
37
- def health():
38
- return jsonify({'status': 'Worked'})
39
-
40
- if __name__ == '__main__':
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  app.run()
 
1
+ from flask import Flask, request, jsonify
2
+ from langchain_community.llms import LlamaCpp
3
+ from sentence_transformers import SentenceTransformer
4
+ # cosine_similarity
5
+ import torch
6
+ from torch.nn.functional import cosine_similarity
7
+ import os
8
+ app = Flask(__name__)
9
+
10
+ n_gpu_layers = 0
11
+ n_batch = 1024
12
+
13
+
14
+ llm = LlamaCpp(
15
+ model_path="Phi-3-mini-4k-instruct-q4.gguf", # path to GGUF file
16
+ temperature=0.1,
17
+ n_gpu_layers=n_gpu_layers,
18
+ n_batch=n_batch,
19
+ verbose=True,
20
+ n_ctx=4096
21
+ )
22
+
23
+ model = SentenceTransformer('sentence-transformers/paraphrase-TinyBERT-L6-v2')
24
+
25
+ file_size = os.stat('Phi-3-mini-4k-instruct-q4.gguf')
26
+ print("model size ====> :", file_size.st_size, "bytes")
27
+
28
+
29
+ @app.route('/cv', methods=['POST'])
30
+ def get_skills():
31
+ cv_body = request.json.get('cv_body')
32
+
33
+ # Simple inference example
34
+ output = llm(
35
+ f"<|user|>\n{cv_body}<|end|>\n<|assistant|>Can you list the skills mentioned in the CV?<|end|>",
36
+ max_tokens=256, # Generate up to 256 tokens
37
+ stop=["<|end|>"],
38
+ echo=True, # Whether to echo the prompt
39
+ )
40
+
41
+ return jsonify({'skills': output})
42
+
43
+ @app.get('/')
44
+ def health():
45
+ return jsonify({'status': 'Worked'})
46
+
47
+ # 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
48
+ # the llm will say the most similar job to the cv
49
+ @app.route('/compare', methods=['POST'])
50
+ def compare():
51
+ employee_skills = request.json.get('employee_skills')# string
52
+ #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""
53
+ jobs_skills = request.json.get('jobs_skills')
54
+ #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."]
55
+ if not isinstance(jobs_skills, list) or not all(isinstance(skill, str) for skill in jobs_skills):
56
+ raise ValueError("jobs_skills must be a list of strings")
57
+ job_embeddings = model.encode(jobs_skills)
58
+ employee_embeddings = model.encode(employee_skills)
59
+ sim = []
60
+ employee_embeddings_tensor = torch.from_numpy(employee_embeddings).unsqueeze(0)
61
+ for job_e in job_embeddings:
62
+ job_e_tensor = torch.from_numpy(job_e).unsqueeze(0)
63
+ sim.append(cosine_similarity(employee_embeddings_tensor, job_e_tensor,dim=1))
64
+ max_sim = max(sim)
65
+ index = sim.index(max_sim)
66
+ return jsonify({'job': jobs_skills[index]})
67
+
68
+ if __name__ == '__main__':
69
  app.run()