saifeddinemk commited on
Commit
7fb1b05
1 Parent(s): 732403f

Fixed app v2

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -1,20 +1,24 @@
1
- from transformers import AutoTokenizer, pipeline
 
2
  from optimum.intel.openvino import OVModelForCausalLM
3
  import gradio as gr
4
  import json
5
 
6
  # Load OpenVINO GPT-J model for causal language modeling
7
- model_id = "OpenVINO/gpt-j-6b-int4-ov"
8
- tokenizer = AutoTokenizer.from_pretrained(model_id)
9
- model = OVModelForCausalLM.from_pretrained(model_id)
10
 
11
- # Load a quantized summarization model
12
- summarizer_model_id = "OpenVINO/distilbart-cnn-12-6-int8-ov" # Example of a quantized summarization model
13
- summarizer = pipeline("summarization", model=summarizer_model_id)
 
14
 
15
  def summarize_text(text, max_length=100):
16
- summary = summarizer(text, max_length=max_length, min_length=25, do_sample=False)
17
- return summary[0]["summary_text"]
 
 
18
 
19
  def match_cv_to_jobs(cv_text, job_descriptions_text):
20
  debug_info = "Debug Info:\n"
@@ -31,14 +35,14 @@ def match_cv_to_jobs(cv_text, job_descriptions_text):
31
  # Create a prompt to compare the summarized CV with the summarized job descriptions
32
  prompt = (
33
  f"Compare the following job descriptions with this resume. Job Descriptions: {summarized_descriptions}. "
34
- f"Resume: {summarized_cv}. Provide a match score ONLY out of 100 "
35
  )
36
  debug_info += f"\nGenerated Prompt: {prompt}\n"
37
 
38
- # Generate response from the model
39
  inputs = tokenizer(prompt, return_tensors="pt")
40
  try:
41
- outputs = model.generate(**inputs, max_length=200)
42
  response_content = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
43
  debug_info += f"Model Response: {response_content}\n"
44
 
 
1
+ from transformers import AutoTokenizer
2
+ from optimum.intel import INCModelForSeq2SeqLM
3
  from optimum.intel.openvino import OVModelForCausalLM
4
  import gradio as gr
5
  import json
6
 
7
  # Load OpenVINO GPT-J model for causal language modeling
8
+ causal_model_id = "OpenVINO/gpt-j-6b-int4-ov"
9
+ tokenizer = AutoTokenizer.from_pretrained(causal_model_id)
10
+ causal_model = OVModelForCausalLM.from_pretrained(causal_model_id)
11
 
12
+ # Load the Intel quantized summarization model
13
+ summarizer_model_id = "Intel/distilbart-cnn-12-6-int8-dynamic"
14
+ tokenizer_summarizer = AutoTokenizer.from_pretrained(summarizer_model_id)
15
+ int8_model = INCModelForSeq2SeqLM.from_pretrained(summarizer_model_id)
16
 
17
  def summarize_text(text, max_length=100):
18
+ inputs = tokenizer_summarizer(text, return_tensors="pt", max_length=512, truncation=True)
19
+ summary_ids = int8_model.generate(inputs.input_ids, max_length=max_length, min_length=25, do_sample=False)
20
+ summary = tokenizer_summarizer.decode(summary_ids[0], skip_special_tokens=True)
21
+ return summary
22
 
23
  def match_cv_to_jobs(cv_text, job_descriptions_text):
24
  debug_info = "Debug Info:\n"
 
35
  # Create a prompt to compare the summarized CV with the summarized job descriptions
36
  prompt = (
37
  f"Compare the following job descriptions with this resume. Job Descriptions: {summarized_descriptions}. "
38
+ f"Resume: {summarized_cv}. Provide a match score and a brief analysis."
39
  )
40
  debug_info += f"\nGenerated Prompt: {prompt}\n"
41
 
42
+ # Generate response from the causal model
43
  inputs = tokenizer(prompt, return_tensors="pt")
44
  try:
45
+ outputs = causal_model.generate(**inputs, max_length=200)
46
  response_content = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
47
  debug_info += f"Model Response: {response_content}\n"
48