Spaces:
Sleeping
Sleeping
File size: 2,965 Bytes
f7f5e9a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | import gradio as gr
from groq import Groq
from pypdf import PdfReader
import docx
# Paste your Groq API key here
GROQ_API_KEY = "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"
client = Groq(api_key=GROQ_API_KEY)
def extract_text_from_pdf(file_path):
reader = PdfReader(file_path)
text = ""
for page in reader.pages:
page_text = page.extract_text()
if page_text:
text += page_text + "\n"
return text
def extract_text_from_docx(file_path):
document = docx.Document(file_path)
text = ""
for paragraph in document.paragraphs:
text += paragraph.text + "\n"
return text
def analyze_resume(resume_file, job_role):
try:
if GROQ_API_KEY == "GROQ KEY":
return "Please paste your actual Groq API key."
if resume_file is None:
return "Please upload a resume."
if job_role is None or job_role.strip() == "":
return "Please enter a target job role."
file_path = resume_file.name
if file_path.lower().endswith(".pdf"):
resume_text = extract_text_from_pdf(file_path)
elif file_path.lower().endswith(".docx"):
resume_text = extract_text_from_docx(file_path)
else:
return "Please upload only PDF or DOCX file."
if resume_text.strip() == "":
return "Could not extract text from the resume. Try another PDF/DOCX file."
prompt = f"""
You are an expert HR recruiter and career advisor.
Analyze the following resume for this target role:
Target Role:
{job_role}
Resume:
{resume_text}
Give the output in this exact format:
1. Overall Resume Summary
2. Key Strengths
3. Skill Gaps
4. Missing Keywords
5. Job Fit Score out of 100
6. Resume Improvement Suggestions
7. Suggested Professional Summary
8. Interview Preparation Topics
Use simple, clear, and professional language.
"""
response = client.chat.completions.create(
model="llama-3.1-8b-instant",
messages=[
{
"role": "user",
"content": prompt
}
],
temperature=0.3,
max_tokens=900
)
return response.choices[0].message.content
except Exception as e:
return "Error occurred: " + str(e)
demo = gr.Interface(
fn=analyze_resume,
inputs=[
gr.File(
label="Upload Resume",
file_types=[".pdf", ".docx"]
),
gr.Textbox(
label="Target Job Role",
placeholder="Example: Assistant Professor in ECE, Data Scientist, AI Engineer"
)
],
outputs=gr.Textbox(
lines=22,
label="Resume Analysis Report"
),
title="AI Resume Analyzer",
description="Upload your resume and enter a target job role. The app analyzes strengths, gaps, keywords, and job-fit score."
)
demo.launch(share=True, debug=True) |