Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,26 +10,16 @@ import subprocess
|
|
| 10 |
from huggingface_hub import hf_hub_download
|
| 11 |
from llama_cpp import Llama
|
| 12 |
|
| 13 |
-
|
|
|
|
| 14 |
|
| 15 |
-
# hf_hub_download(
|
| 16 |
-
# repo_id="QuantFactory/Meta-Llama-3-8B-Instruct-GGUF",
|
| 17 |
-
# filename="Meta-Llama-3-8B-Instruct.Q8_0.gguf",
|
| 18 |
-
# local_dir = "./models"
|
| 19 |
-
# )
|
| 20 |
|
| 21 |
hf_hub_download(
|
| 22 |
-
repo_id=
|
| 23 |
-
filename=
|
| 24 |
local_dir = "./models"
|
| 25 |
)
|
| 26 |
|
| 27 |
-
# hf_hub_download(
|
| 28 |
-
# repo_id="leafspark/Meta-Llama-3.1-405B-Instruct-GGUF",
|
| 29 |
-
# filename="Llama-3.1-405B-Instruct.Q2_K.gguf",
|
| 30 |
-
# local_dir = "./models"
|
| 31 |
-
# )
|
| 32 |
-
|
| 33 |
def process_document(pdf_path):
|
| 34 |
extracted_pages = extract_pages(pdf_path)
|
| 35 |
page2content = {}
|
|
@@ -77,15 +67,11 @@ def txt_to_html(text):
|
|
| 77 |
html_content += "</body></html>"
|
| 78 |
return html_content
|
| 79 |
|
| 80 |
-
def craft_cv(llm, cv_text,
|
| 81 |
-
|
| 82 |
output = llm.create_chat_completion(
|
| 83 |
messages=[
|
| 84 |
-
{"
|
| 85 |
-
{
|
| 86 |
-
"role": "user",
|
| 87 |
-
"content": cv_text
|
| 88 |
-
}
|
| 89 |
],
|
| 90 |
max_tokens=maxtokens,
|
| 91 |
temperature=temperature
|
|
@@ -95,21 +81,20 @@ def craft_cv(llm, cv_text, prompt, maxtokens, temperature, top_probability):
|
|
| 95 |
return cv_text, output
|
| 96 |
|
| 97 |
@spaces.GPU(duration=150)
|
| 98 |
-
def pdf_to_text(cv_file,
|
| 99 |
page2content = process_document(cv_file)
|
| 100 |
cv_text = ""
|
| 101 |
for page_id in page2content:
|
| 102 |
cv_text += page2content[page_id] + ' '
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
crafted_cv
|
| 112 |
-
return cv_text, crafted_cv
|
| 113 |
|
| 114 |
temp_slider = gr.Slider(minimum=0, maximum=2, value=0.9, label="Temperature Value")
|
| 115 |
prob_slider = gr.Slider(minimum=0, maximum=1, value=0.95, label="Max Probability Value")
|
|
@@ -120,7 +105,7 @@ output_text = gr.Textbox()
|
|
| 120 |
iface = gr.Interface(
|
| 121 |
fn=pdf_to_text,
|
| 122 |
inputs=[cv_file, prompt_text],
|
| 123 |
-
outputs=['text'
|
| 124 |
title='Craft CV',
|
| 125 |
description="This application assists to customize CV based on input job description",
|
| 126 |
theme=gr.themes.Soft(),
|
|
|
|
| 10 |
from huggingface_hub import hf_hub_download
|
| 11 |
from llama_cpp import Llama
|
| 12 |
|
| 13 |
+
repo_id = "srijaydeshpande/CVCRaft"
|
| 14 |
+
model_id = "cvcraft.gguf"
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
hf_hub_download(
|
| 18 |
+
repo_id=repo_id,
|
| 19 |
+
filename=model_id,
|
| 20 |
local_dir = "./models"
|
| 21 |
)
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
def process_document(pdf_path):
|
| 24 |
extracted_pages = extract_pages(pdf_path)
|
| 25 |
page2content = {}
|
|
|
|
| 67 |
html_content += "</body></html>"
|
| 68 |
return html_content
|
| 69 |
|
| 70 |
+
def craft_cv(llm, cv_text, job_description, maxtokens, temperature, top_probability):
|
| 71 |
+
instruction = "Given input CV and job description. Please revise the CV according to the given job description and output the revised CV."
|
| 72 |
output = llm.create_chat_completion(
|
| 73 |
messages=[
|
| 74 |
+
{"from": "user", "value": instruction + ' Input CV: ' + cv_text + ' , Job Description: ' + job_description},
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
],
|
| 76 |
max_tokens=maxtokens,
|
| 77 |
temperature=temperature
|
|
|
|
| 81 |
return cv_text, output
|
| 82 |
|
| 83 |
@spaces.GPU(duration=150)
|
| 84 |
+
def pdf_to_text(cv_file, job_description, maxtokens=2048, temperature=0, top_probability=0.95):
|
| 85 |
page2content = process_document(cv_file)
|
| 86 |
cv_text = ""
|
| 87 |
for page_id in page2content:
|
| 88 |
cv_text += page2content[page_id] + ' '
|
| 89 |
+
llm = Llama(
|
| 90 |
+
model_path="models/" + model_id,
|
| 91 |
+
flash_attn=True,
|
| 92 |
+
n_gpu_layers=81,
|
| 93 |
+
n_batch=1024,
|
| 94 |
+
n_ctx=8192,
|
| 95 |
+
)
|
| 96 |
+
cv_text, crafted_cv = craft_cv(llm, cv_text, job_description, maxtokens, temperature, top_probability)
|
| 97 |
+
return crafted_cv
|
|
|
|
| 98 |
|
| 99 |
temp_slider = gr.Slider(minimum=0, maximum=2, value=0.9, label="Temperature Value")
|
| 100 |
prob_slider = gr.Slider(minimum=0, maximum=1, value=0.95, label="Max Probability Value")
|
|
|
|
| 105 |
iface = gr.Interface(
|
| 106 |
fn=pdf_to_text,
|
| 107 |
inputs=[cv_file, prompt_text],
|
| 108 |
+
outputs=['text'],
|
| 109 |
title='Craft CV',
|
| 110 |
description="This application assists to customize CV based on input job description",
|
| 111 |
theme=gr.themes.Soft(),
|