srijaydeshpande commited on
Commit
5cbefa7
·
verified ·
1 Parent(s): 5a95e37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -33
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
- model_name = "Meta-Llama-3-70B-Instruct-Q3_K_M.gguf"
 
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="bartowski/Meta-Llama-3-70B-Instruct-GGUF",
23
- filename=model_name,
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, prompt, maxtokens, temperature, top_probability):
81
- task = 'Please modify the CV text according the following job description: '
82
  output = llm.create_chat_completion(
83
  messages=[
84
- {"role": "assistant", "content": task + prompt},
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, prompt, maxtokens=2048, temperature=0, top_probability=0.95):
99
  page2content = process_document(cv_file)
100
  cv_text = ""
101
  for page_id in page2content:
102
  cv_text += page2content[page_id] + ' '
103
- # llm = Llama(
104
- # model_path="models/" + model_name,
105
- # flash_attn=True,
106
- # n_gpu_layers=81,
107
- # n_batch=1024,
108
- # n_ctx=8192,
109
- # )
110
- # cv_text, crafted_cv = craft_cv(llm, cv_text, prompt, maxtokens, temperature, top_probability)
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', '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(),