Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ import torch
|
|
4 |
from transformers import pipeline
|
5 |
import pandas as pd
|
6 |
from huggingface_hub import login
|
|
|
7 |
|
8 |
# Function to login using Hugging Face API token
|
9 |
def login_with_token(hf_token):
|
@@ -15,7 +16,6 @@ def login_with_token(hf_token):
|
|
15 |
return f"Error: {str(e)}"
|
16 |
|
17 |
# Load the model for Named Entity Recognition (NER)
|
18 |
-
# You can replace 'dbmdz/bert-large-cased-finetuned-conll03-english' with any other model if needed
|
19 |
nlp = pipeline("ner", model="dbmdz/bert-large-cased-finetuned-conll03-english", framework="pt")
|
20 |
|
21 |
def extract_text_from_pdf(pdf_file):
|
@@ -68,9 +68,15 @@ def batch_process_resumes(pdf_files):
|
|
68 |
|
69 |
# Convert to DataFrame
|
70 |
df = pd.DataFrame(all_resumes)
|
|
|
|
|
|
|
|
|
71 |
# Save to Excel
|
72 |
-
df.to_excel(
|
73 |
-
|
|
|
|
|
74 |
|
75 |
# Gradio interface
|
76 |
with gr.Blocks() as demo:
|
@@ -85,6 +91,9 @@ with gr.Blocks() as demo:
|
|
85 |
# Output for results
|
86 |
output = gr.Textbox(label="Result")
|
87 |
|
|
|
|
|
|
|
88 |
# Process button that triggers the login and resume parsing
|
89 |
process_button = gr.Button("Process Resumes")
|
90 |
|
@@ -93,15 +102,15 @@ with gr.Blocks() as demo:
|
|
93 |
# Attempt to log in with provided token
|
94 |
login_message = login_with_token(hf_token)
|
95 |
|
96 |
-
# If login is successful, process resumes
|
97 |
if "Error" not in login_message:
|
98 |
-
|
99 |
-
return login_message + "\
|
100 |
else:
|
101 |
-
return login_message
|
102 |
|
103 |
# Set up the button click event
|
104 |
-
process_button.click(process_resumes, inputs=[hf_token_input, file_input], outputs=output)
|
105 |
|
106 |
# Launch the Gradio interface
|
107 |
demo.launch()
|
|
|
4 |
from transformers import pipeline
|
5 |
import pandas as pd
|
6 |
from huggingface_hub import login
|
7 |
+
import os
|
8 |
|
9 |
# Function to login using Hugging Face API token
|
10 |
def login_with_token(hf_token):
|
|
|
16 |
return f"Error: {str(e)}"
|
17 |
|
18 |
# Load the model for Named Entity Recognition (NER)
|
|
|
19 |
nlp = pipeline("ner", model="dbmdz/bert-large-cased-finetuned-conll03-english", framework="pt")
|
20 |
|
21 |
def extract_text_from_pdf(pdf_file):
|
|
|
68 |
|
69 |
# Convert to DataFrame
|
70 |
df = pd.DataFrame(all_resumes)
|
71 |
+
|
72 |
+
# Define the file path for the Excel file
|
73 |
+
output_file = "/tmp/parsed_resumes.xlsx"
|
74 |
+
|
75 |
# Save to Excel
|
76 |
+
df.to_excel(output_file, index=False)
|
77 |
+
|
78 |
+
# Return the path to the file for download
|
79 |
+
return output_file
|
80 |
|
81 |
# Gradio interface
|
82 |
with gr.Blocks() as demo:
|
|
|
91 |
# Output for results
|
92 |
output = gr.Textbox(label="Result")
|
93 |
|
94 |
+
# File output for the download link
|
95 |
+
download_link = gr.File(label="Download Excel File", file_count=1)
|
96 |
+
|
97 |
# Process button that triggers the login and resume parsing
|
98 |
process_button = gr.Button("Process Resumes")
|
99 |
|
|
|
102 |
# Attempt to log in with provided token
|
103 |
login_message = login_with_token(hf_token)
|
104 |
|
105 |
+
# If login is successful, process resumes and generate the download link
|
106 |
if "Error" not in login_message:
|
107 |
+
excel_file_path = batch_process_resumes(pdf_files)
|
108 |
+
return login_message + "\nExcel file with parsed resumes is ready for download.", excel_file_path
|
109 |
else:
|
110 |
+
return login_message, None
|
111 |
|
112 |
# Set up the button click event
|
113 |
+
process_button.click(process_resumes, inputs=[hf_token_input, file_input], outputs=[output, download_link])
|
114 |
|
115 |
# Launch the Gradio interface
|
116 |
demo.launch()
|