zayanomar5 commited on
Commit
5029438
·
verified ·
1 Parent(s): 63d7366

Delete main.py

Browse files
Files changed (1) hide show
  1. main.py +0 -87
main.py DELETED
@@ -1,87 +0,0 @@
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
- from huggingface_hub import hf_hub_download, HfApi
6
-
7
- # cosine_similarity
8
- import torch
9
- from torch.nn.functional import cosine_similarity
10
- import os
11
-
12
- app = Flask(__name__)
13
-
14
- n_gpu_layers = 0
15
- n_batch = 1024
16
-
17
- # تنزيل النموذج باستخدام معالجة الأخطاء
18
- try:
19
- model_path = hf_hub_download(repo_id="repo_name", filename="model_file_name", force_download=True)
20
- except Exception as e:
21
- print(f"Error downloading the model: {e}")
22
- model_path = None
23
-
24
-
25
- if model_path:
26
- llm = LlamaCpp(
27
- model_path=model_path, # path to GGUF file
28
- temperature=0.1,
29
- n_gpu_layers=n_gpu_layers,
30
- n_batch=n_batch,
31
- verbose=True,
32
- n_ctx=4096
33
- )
34
-
35
- model0 = AutoModel.from_pretrained('sentence-transformers/paraphrase-TinyBERT-L6-v2')
36
- model = SentenceTransformer('sentence-transformers/paraphrase-TinyBERT-L6-v2')
37
-
38
- file_size = os.stat('Phi-3-mini-4k-instruct-q4.gguf')
39
- print("model size ====> :", file_size.st_size, "bytes")
40
-
41
- @app.route('/cv', methods=['POST'])
42
- def get_skills():
43
- cv_body = request.json.get('cv_body')
44
-
45
- # Simple inference example
46
- output = llm(
47
- f"\n{cv_body}\nCan you list the skills mentioned in the CV?",
48
- max_tokens=256, # Generate up to 256 tokens
49
- stop=[""],
50
- echo=True, # Whether to echo the prompt
51
- )
52
-
53
- return jsonify({'skills': output})
54
-
55
- @app.get('/')
56
- def health():
57
- return jsonify({'status': 'Worked'})
58
-
59
- @app.route('/compare', methods=['POST'])
60
- def compare():
61
- employee_skills = request.json.get('employee_skills') # string
62
- jobs_skills = request.json.get('jobs_skills') # list of strings
63
-
64
- if not isinstance(jobs_skills, list) or not all(isinstance(skill, str) for skill in jobs_skills):
65
- raise ValueError("jobs_skills must be a list of strings")
66
-
67
- job_embeddings = model.encode(jobs_skills)
68
- employee_embeddings = model.encode(employee_skills)
69
- sim = []
70
- employee_embeddings_tensor = torch.from_numpy(employee_embeddings).unsqueeze(0)
71
- for job_e in job_embeddings:
72
- job_e_tensor = torch.from_numpy(job_e).unsqueeze(0)
73
- sim.append(cosine_similarity(employee_embeddings_tensor, job_e_tensor, dim=1))
74
-
75
- max_sim = max(sim)
76
- index = sim.index(max_sim)
77
- return jsonify({'job': jobs_skills[index]})
78
-
79
- @app.route('/models', methods=['GET'])
80
- def list_models():
81
- hf_api = HfApi()
82
- models = hf_api.list_models()
83
- return jsonify({'models': models})
84
-
85
- if __name__ == '__main__':
86
- app.run()
87
-