Ahmed007 commited on
Commit
6405da4
·
verified ·
1 Parent(s): 1797a34

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +27 -18
main.py CHANGED
@@ -1,37 +1,46 @@
1
  from flask import Flask, request, jsonify
2
  from langchain_community.llms import LlamaCpp
3
- from llama_cpp import Llama
 
 
 
4
 
 
5
 
6
-
7
- import os
8
  app = Flask(__name__)
9
 
10
  n_gpu_layers = 0
11
  n_batch = 1024
12
 
 
13
 
14
- llm = Llama(
15
- model_path="Phi-3-mini-4k-instruct-q4.gguf", # path to GGUF file
16
- n_gpu_layers=0, # The number of layers to offload to GPU, if you have GPU acceleration available. Set to 0 if no GPU acceleration is available on your system.
 
 
 
 
 
17
  )
18
 
19
- file_size = os.stat('Phi-3-mini-4k-instruct-q4.gguf')
20
- print("model size ====> :", file_size.st_size, "bytes")
21
-
22
-
23
  @app.route('/', methods=['POST'])
24
  def get_skills():
25
  cv_body = request.json.get('cv_body')
26
 
27
- # Simple inference example
28
- output = llm(
29
- f"<|user|>\n{cv_body}<|end|>\n<|assistant|>Can you list the skills mentioned in the CV?<|end|>",
30
- max_tokens=256, # Generate up to 256 tokens
31
- stop=["<|end|>"],
32
- )
 
 
 
 
 
33
 
34
- return jsonify({'skills': output['choices'][0]['text']})
35
 
36
  if __name__ == '__main__':
37
- app.run()
 
1
  from flask import Flask, request, jsonify
2
  from langchain_community.llms import LlamaCpp
3
+ from langchain.callbacks.manager import CallbackManager
4
+ from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
5
+ from langchain.prompts import PromptTemplate
6
+ from langchain.schema.output_parser import StrOutputParser
7
 
8
+ # from langchain.llms import LlamaCpp
9
 
 
 
10
  app = Flask(__name__)
11
 
12
  n_gpu_layers = 0
13
  n_batch = 1024
14
 
15
+ callback_manager = CallbackManager([StreamingStdOutCallbackHandler()])
16
 
17
+ llm = LlamaCpp(
18
+ model_path="phi-2.Q4_K_M.gguf",
19
+ temperature=0.1,
20
+ n_gpu_layers=n_gpu_layers,
21
+ n_batch=n_batch,
22
+ callback_manager=callback_manager,
23
+ verbose=True,
24
+ n_ctx=2048
25
  )
26
 
 
 
 
 
27
  @app.route('/', methods=['POST'])
28
  def get_skills():
29
  cv_body = request.json.get('cv_body')
30
 
31
+ template = """Instruct:
32
+ Take a deep breath to deep understand, and don't this cv vc = {cv_body} . to answer this question and instructions </s>
33
+ \nOutput:"""
34
+
35
+ prompt = PromptTemplate(template=template, input_variables=["text"])
36
+ chain = prompt | llm | StrOutputParser()
37
+
38
+ ans = chain.invoke({"question": "What are his best skills? write in points","cv_body":cv_body},
39
+ config={
40
+ # "callbacks": [ConsoleCallbackHandler()]
41
+ })
42
 
43
+ return jsonify({'skills': ans})
44
 
45
  if __name__ == '__main__':
46
+ app.run()