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

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +12 -5
main.py CHANGED
@@ -2,26 +2,26 @@ 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, HfHubError
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 HfHubError 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
@@ -76,5 +76,12 @@ def compare():
76
  index = sim.index(max_sim)
77
  return jsonify({'job': jobs_skills[index]})
78
 
 
 
 
 
 
 
79
  if __name__ == '__main__':
80
  app.run()
 
 
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
 
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
+