sandrocalzada commited on
Commit
3defb2b
verified
1 Parent(s): d997b75

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -28
app.py CHANGED
@@ -3,48 +3,40 @@ from docx import Document
3
  import io
4
 
5
  def read_docx(file_bytes):
6
- # Use BytesIO to convert binary data to a file-like object for python-docx
7
  file_like_object = io.BytesIO(file_bytes)
8
  document = Document(file_like_object)
9
- doc_text = []
10
-
11
- for paragraph in document.paragraphs:
12
- doc_text.append(paragraph.text)
13
-
14
- # Join all text pieces and lower the case
15
  return '\n'.join(doc_text).lower()
16
 
17
  def analyze_cv(cv_file, desired_role, expected_salary):
18
- # Define salary ranges for different roles
19
  salary_ranges = {
20
- "Desarrollador": (30000, 60000),
21
- "Dise帽ador": (25000, 50000),
22
- "Gerente": (40000, 80000)
23
  }
24
 
25
- # Read the content of the CV using the read_docx function
26
  cv_content = read_docx(cv_file)
27
-
28
- # Check if the desired role is mentioned in the CV
29
- if desired_role.lower() in cv_content:
30
- # Check if the expected salary is within the range for the role
31
  salary_range = salary_ranges.get(desired_role, (0, 0))
32
- if salary_range[0] <= int(expected_salary) <= salary_range[1]:
33
- result = "El candidato es elegible para la posici贸n."
34
- else:
35
- result = "El candidato no es elegible debido a las expectativas salariales."
 
 
 
 
36
  else:
37
  result = "El candidato no es elegible debido a la falta de experiencia relevante."
38
-
39
  return result
40
 
41
- # Define the Gradio interface with aesthetic enhancements
42
  iface = gr.Interface(
43
  fn=analyze_cv,
44
  inputs=[
45
- gr.File(label="Sube un CV", type="binary"), # Set to binary to handle .docx files
46
  gr.Textbox(label="Nombre del rol o posici贸n a cubrir", placeholder="Ejemplo: Desarrollador BI"),
47
- gr.Textbox(label="Expectativa salarial", placeholder="Ejemplo: 50000"), # Adjusted placeholder to a more realistic salary expectation
48
  ],
49
  outputs=gr.Textbox(label="Resultado de la elegibilidad"),
50
  title="An谩lisis autom谩tico de CV",
@@ -56,9 +48,8 @@ iface = gr.Interface(
56
  .gr-file { border-color: #007BFF; }
57
  .gr-button { background-color: #007BFF; color: white; }
58
  .gr-output-text { font-size: 16px; }
59
- """,
60
- share=True # Set share=True to create a public link
61
  )
62
 
63
- # Launch the application
64
- iface.launch()
 
3
  import io
4
 
5
  def read_docx(file_bytes):
 
6
  file_like_object = io.BytesIO(file_bytes)
7
  document = Document(file_like_object)
8
+ doc_text = [paragraph.text for paragraph in document.paragraphs]
 
 
 
 
 
9
  return '\n'.join(doc_text).lower()
10
 
11
  def analyze_cv(cv_file, desired_role, expected_salary):
 
12
  salary_ranges = {
13
+ "desarrollador": (30000, 60000),
14
+ "dise帽ador": (25000, 50000),
15
+ "gerente": (40000, 80000)
16
  }
17
 
 
18
  cv_content = read_docx(cv_file)
19
+ desired_role = desired_role.lower()
20
+ if desired_role in cv_content:
 
 
21
  salary_range = salary_ranges.get(desired_role, (0, 0))
22
+ try:
23
+ expected_salary = int(expected_salary)
24
+ if salary_range[0] <= expected_salary <= salary_range[1]:
25
+ result = "El candidato es elegible para la posici贸n."
26
+ else:
27
+ result = "El candidato no es elegible debido a las expectativas salariales."
28
+ except ValueError:
29
+ result = "Por favor, ingrese un valor num茅rico v谩lido para la expectativa salarial."
30
  else:
31
  result = "El candidato no es elegible debido a la falta de experiencia relevante."
 
32
  return result
33
 
 
34
  iface = gr.Interface(
35
  fn=analyze_cv,
36
  inputs=[
37
+ gr.File(label="Sube un CV", type="binary"),
38
  gr.Textbox(label="Nombre del rol o posici贸n a cubrir", placeholder="Ejemplo: Desarrollador BI"),
39
+ gr.Textbox(label="Expectativa salarial", placeholder="Ejemplo: 50000"),
40
  ],
41
  outputs=gr.Textbox(label="Resultado de la elegibilidad"),
42
  title="An谩lisis autom谩tico de CV",
 
48
  .gr-file { border-color: #007BFF; }
49
  .gr-button { background-color: #007BFF; color: white; }
50
  .gr-output-text { font-size: 16px; }
51
+ """
 
52
  )
53
 
54
+ # Launch the application with share=True to create a public link
55
+ iface.launch(share=True)