Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -1,88 +1,44 @@
|
|
1 |
from flask import Flask, request, jsonify
|
2 |
-
import os
|
3 |
from langchain.llms import LlamaCpp
|
4 |
from langchain.callbacks.manager import CallbackManager
|
|
|
5 |
from langchain.prompts import PromptTemplate
|
6 |
from langchain.schema.output_parser import StrOutputParser
|
7 |
|
8 |
-
|
9 |
app = Flask(__name__)
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
# Disable GPU usage
|
16 |
-
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
|
17 |
-
|
18 |
-
# Callback manager setup
|
19 |
-
callback_manager = CallbackManager([])
|
20 |
-
|
21 |
-
# Creating LlamaCpp instance
|
22 |
-
llm = LlamaCpp(
|
23 |
-
model_path="phi-2.Q4_K_M.gguf",
|
24 |
-
temperature=0.1,
|
25 |
-
n_gpu_layers=0,
|
26 |
-
n_batch=1024,
|
27 |
-
callback_manager=callback_manager,
|
28 |
-
verbose=True,
|
29 |
-
n_ctx=2048
|
30 |
-
)
|
31 |
|
32 |
-
|
33 |
-
templates = {
|
34 |
-
"work_experience": """Instruction:
|
35 |
-
Extract and summarize the work experience mentioned in the CV provided below. Focus solely on the details related to work history, including job titles, companies, and duration.
|
36 |
-
Text: {text}
|
37 |
-
Question: {question}
|
38 |
-
Output:""",
|
39 |
-
|
40 |
-
"certification": """Instruction:
|
41 |
-
Extract and summarize the certification history mentioned in the CV provided below. Include details such as degrees earned, institutions attended, and graduation years.
|
42 |
-
Text: {text}
|
43 |
-
Question: {question}
|
44 |
-
Output:""",
|
45 |
-
|
46 |
-
"contact_info": """Instruction:
|
47 |
-
Extract and provide the contact information mentioned in the CV provided below. Include details such as phone number, email address, and any other relevant contact links.
|
48 |
-
Text: {text}
|
49 |
-
Question: {question}
|
50 |
-
Output:""",
|
51 |
-
|
52 |
-
"skills": """Instruction:
|
53 |
-
Focus solely on extracting the skills mentioned in the text below, excluding any other details or context. Your answer should consist of concise skills.
|
54 |
-
Text: {text}
|
55 |
-
Question: {question}
|
56 |
-
Output:"""
|
57 |
-
}
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
64 |
|
65 |
-
|
66 |
-
return jsonify({"error": "Both 'question' and 'text' fields are required."}), 400
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
template_key = "certification"
|
72 |
-
elif question == "Please extract the contact information mentioned in the CV once.":
|
73 |
-
template_key = "contact_info"
|
74 |
-
elif question == "What are the 6 skills? Please provide a concise short answer of the only(skills) mentioned in the text without repeating the answer.":
|
75 |
-
template_key = "skills"
|
76 |
-
else:
|
77 |
-
return jsonify({"error": "Invalid question provided."}), 400
|
78 |
|
79 |
-
prompt = PromptTemplate(template=
|
80 |
chain = prompt | llm | StrOutputParser()
|
81 |
-
response = chain.invoke({"question": question, "text": text})
|
82 |
|
83 |
-
|
|
|
|
|
|
|
84 |
|
|
|
85 |
|
86 |
if __name__ == '__main__':
|
87 |
-
|
88 |
-
app.run( port= 8000)
|
|
|
1 |
from flask import Flask, request, jsonify
|
|
|
2 |
from langchain.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 |
app = Flask(__name__)
|
9 |
|
10 |
+
@app.route('/', methods=['POST'])
|
11 |
+
def get_skills():
|
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 |
+
cv_body = request.json.get('cv_body')
|
|
|
28 |
|
29 |
+
template = """Instruct:
|
30 |
+
Take a deep breath to deep understand, and don't this cv vc = {cv_body} . to answer this question and instructions </s> {question}
|
31 |
+
\nOutput:"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
+
prompt = PromptTemplate(template=template, input_variables=["question","text"])
|
34 |
chain = prompt | llm | StrOutputParser()
|
|
|
35 |
|
36 |
+
ans = chain.invoke({"question": "What are his best skills? write in points","text":cv_body},
|
37 |
+
config={
|
38 |
+
# "callbacks": [ConsoleCallbackHandler()]
|
39 |
+
})
|
40 |
|
41 |
+
return jsonify({'skills': ans})
|
42 |
|
43 |
if __name__ == '__main__':
|
44 |
+
app.run()
|
|