ruslanmv commited on
Commit
3751b1c
·
verified ·
1 Parent(s): b3c76ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -1,8 +1,8 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import PyPDF2
4
- import docx
5
  import io
 
6
 
7
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
 
@@ -14,10 +14,10 @@ def extract_text_from_pdf(pdf_file):
14
  return text
15
 
16
  def extract_text_from_docx(docx_file):
17
- doc = docx.Document(io.BytesIO(docx_file))
18
  return "\n".join([para.text for para in doc.paragraphs])
19
 
20
- def parse_cv(file):
21
  if file is None:
22
  return "Please upload a CV file."
23
 
@@ -31,7 +31,7 @@ def parse_cv(file):
31
  else:
32
  return "Unsupported file format. Please upload a PDF or DOCX file."
33
 
34
- prompt = f"Analyze the following CV and generate a professional summary and improvement suggestions:\n\n{text}"
35
  response = client.text_generation(prompt, max_tokens=512)
36
  return response
37
 
@@ -87,12 +87,13 @@ with demo:
87
  )
88
 
89
  with gr.Tab("CV Analyzer"):
90
- gr.Markdown("### Upload your CV (PDF or DOCX) to receive a professional analysis.")
91
  file_input = gr.File(label="Upload CV", type="file")
 
92
  output_text = gr.Textbox(label="CV Analysis Report", lines=10)
93
  analyze_button = gr.Button("Analyze CV")
94
 
95
- analyze_button.click(parse_cv, inputs=file_input, outputs=output_text)
96
 
97
  if __name__ == "__main__":
98
- demo.launch()
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
  import PyPDF2
 
4
  import io
5
+ from docx import Document # Fix the import issue
6
 
7
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
 
 
14
  return text
15
 
16
  def extract_text_from_docx(docx_file):
17
+ doc = Document(io.BytesIO(docx_file)) # Fixed import usage
18
  return "\n".join([para.text for para in doc.paragraphs])
19
 
20
+ def parse_cv(file, job_description):
21
  if file is None:
22
  return "Please upload a CV file."
23
 
 
31
  else:
32
  return "Unsupported file format. Please upload a PDF or DOCX file."
33
 
34
+ prompt = f"Analyze the following CV against the job description provided. Provide a summary, an assessment of fit, and a score from 0 to 10.\n\nJob Description:\n{job_description}\n\nCandidate CV:\n{text}"
35
  response = client.text_generation(prompt, max_tokens=512)
36
  return response
37
 
 
87
  )
88
 
89
  with gr.Tab("CV Analyzer"):
90
+ gr.Markdown("### Upload your CV (PDF or DOCX) and provide the job description to receive a professional analysis and suitability score.")
91
  file_input = gr.File(label="Upload CV", type="file")
92
+ job_desc_input = gr.Textbox(label="Job Description", lines=5)
93
  output_text = gr.Textbox(label="CV Analysis Report", lines=10)
94
  analyze_button = gr.Button("Analyze CV")
95
 
96
+ analyze_button.click(parse_cv, inputs=[file_input, job_desc_input], outputs=output_text)
97
 
98
  if __name__ == "__main__":
99
+ demo.launch()