zayanomar5 commited on
Commit
709996c
·
verified ·
1 Parent(s): 74a6363

Upload 6 files

Browse files
Files changed (6) hide show
  1. Dockerfile +32 -0
  2. README.md +10 -0
  3. gitattributes +35 -0
  4. main.py +72 -0
  5. main.yml +27 -0
  6. requirements.txt +16 -0
Dockerfile ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
+ # you will also find guides on how best to write your Dockerfile
3
+
4
+ FROM python:3.9
5
+
6
+ WORKDIR /code
7
+
8
+ COPY ./requirements.txt /code/requirements.txt
9
+
10
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
11
+
12
+ RUN wget https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-gguf/resolve/main/Phi-3-mini-4k-instruct-q4.gguf
13
+
14
+ Run git clone "https://huggingface.co/sentence-transformers/paraphrase-TinyBERT-L6-v2"
15
+
16
+ RUN mkdir /.cache
17
+
18
+ RUN chmod 777 /.cache
19
+
20
+ # RUN mkdir /.cache/huggingface
21
+
22
+ # RUN mkdir /.cache/huggingface/hub
23
+
24
+ # RUN mkdir /.cache/huggingface/hub/models--sentence-transformers--paraphrase-TinyBERT-L6-v2
25
+
26
+ # RUN mkdir /.cache/huggingface/hub/models--sentence-transformers--paraphrase-TinyBERT-L6-v2/blobs
27
+
28
+ # RUN mkdir /.cache/huggingface/hub/models--sentence-transformers--paraphrase-TinyBERT-L6-v2/snapshots
29
+
30
+ COPY . .
31
+
32
+ CMD ["gunicorn", "-b", "0.0.0.0:7860", "--timeout", "300", "main:app"]
README.md ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Cv
3
+ emoji: 🚀
4
+ colorFrom: blue
5
+ colorTo: red
6
+ sdk: docker
7
+ pinned: false
8
+ ---
9
+
10
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
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