Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,65 +1,39 @@
|
|
1 |
-
import openai # β
Correct: lowercase 'openai' module from PyPI
|
2 |
-
from keybert.llm import OpenAI as KeyBERTOpenAI
|
3 |
import os
|
|
|
4 |
import gradio as gr
|
5 |
-
import
|
6 |
-
import PyPDF2
|
7 |
-
from keybert.llm import OpenAI
|
8 |
from keybert import KeyLLM
|
9 |
|
10 |
-
#
|
11 |
api_key = os.environ.get("OPENAI_API_KEY")
|
12 |
-
|
13 |
-
# β
Set up OpenAI client
|
14 |
openai.api_key = api_key
|
15 |
client = openai
|
16 |
|
17 |
-
#
|
18 |
llm = KeyBERTOpenAI(client)
|
19 |
kw_model = KeyLLM(llm)
|
20 |
|
21 |
-
#
|
22 |
-
def
|
23 |
-
if file is None:
|
24 |
-
return ""
|
25 |
-
ext = file.name.split('.')[-1].lower()
|
26 |
-
if ext == 'pdf':
|
27 |
-
reader = PyPDF2.PdfReader(file)
|
28 |
-
return "\n".join([page.extract_text() for page in reader.pages if page.extract_text()])
|
29 |
-
elif ext == 'docx':
|
30 |
-
return docx2txt.process(file.name)
|
31 |
-
else:
|
32 |
-
return "Unsupported file format."
|
33 |
-
|
34 |
-
# Function to extract keywords using KeyLLM
|
35 |
-
def extract_keywords_from_resume(job_desc, resume_file, analyze_with_jd):
|
36 |
-
resume_text = extract_text(resume_file)
|
37 |
if not resume_text.strip():
|
38 |
-
return "
|
39 |
-
|
40 |
-
# Create combined document if analysis is requested
|
41 |
-
document = job_desc + "\n\n" + resume_text if analyze_with_jd and job_desc else resume_text
|
42 |
|
43 |
-
|
44 |
-
keywords = kw_model.extract_keywords([
|
45 |
return ", ".join(keywords[0]) if keywords else "No keywords found."
|
46 |
|
47 |
-
# Gradio UI
|
48 |
with gr.Blocks() as demo:
|
49 |
with gr.Row():
|
50 |
with gr.Column():
|
51 |
analyze_checkbox = gr.Checkbox(label="Analyze with Job Description", value=True)
|
52 |
-
job_desc = gr.Textbox(label="Job Description", lines=6)
|
53 |
-
|
54 |
with gr.Column():
|
55 |
-
output_keywords = gr.Textbox(label="Extracted Keywords", lines=
|
56 |
-
|
57 |
-
resume_file.change(fn=extract_keywords_from_resume,
|
58 |
-
inputs=[job_desc, resume_file, analyze_checkbox],
|
59 |
-
outputs=output_keywords)
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
|
65 |
demo.launch()
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
import openai
|
3 |
import gradio as gr
|
4 |
+
from keybert.llm import OpenAI as KeyBERTOpenAI
|
|
|
|
|
5 |
from keybert import KeyLLM
|
6 |
|
7 |
+
# π Load API key from Hugging Face Secrets
|
8 |
api_key = os.environ.get("OPENAI_API_KEY")
|
|
|
|
|
9 |
openai.api_key = api_key
|
10 |
client = openai
|
11 |
|
12 |
+
# π§ Initialize KeyLLM
|
13 |
llm = KeyBERTOpenAI(client)
|
14 |
kw_model = KeyLLM(llm)
|
15 |
|
16 |
+
# π§ Extract keywords from pasted text
|
17 |
+
def extract_keywords(job_desc, resume_text, analyze_with_jd):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
if not resume_text.strip():
|
19 |
+
return "Please paste your resume text."
|
|
|
|
|
|
|
20 |
|
21 |
+
text = job_desc + "\n\n" + resume_text if analyze_with_jd and job_desc else resume_text
|
22 |
+
keywords = kw_model.extract_keywords([text], check_vocab=True)
|
23 |
return ", ".join(keywords[0]) if keywords else "No keywords found."
|
24 |
|
25 |
+
# ποΈ Gradio UI
|
26 |
with gr.Blocks() as demo:
|
27 |
with gr.Row():
|
28 |
with gr.Column():
|
29 |
analyze_checkbox = gr.Checkbox(label="Analyze with Job Description", value=True)
|
30 |
+
job_desc = gr.Textbox(label="Job Description", lines=6, placeholder="Paste job description here...")
|
31 |
+
resume_text = gr.Textbox(label="Resume Text", lines=12, placeholder="Paste resume content here...")
|
32 |
with gr.Column():
|
33 |
+
output_keywords = gr.Textbox(label="Extracted Keywords", lines=12)
|
|
|
|
|
|
|
|
|
34 |
|
35 |
+
# Trigger keyword extraction when any input changes
|
36 |
+
job_desc.change(fn=extract_keywords, inputs=[job_desc, resume_text, analyze_checkbox], outputs=output_keywords)
|
37 |
+
resume_text.change(fn=extract_keywords, inputs=[job_desc, resume_text, analyze_checkbox], outputs=output_keywords)
|
38 |
|
39 |
demo.launch()
|