Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,114 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
with gr.Sidebar():
|
| 5 |
-
gr.Markdown("#
|
| 6 |
-
gr.Markdown("
|
| 7 |
-
button = gr.LoginButton("Sign in")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
gr.load("models/mistralai/Mistral-7B-Instruct-v0.3", accept_token=button, provider="together")
|
| 9 |
-
|
| 10 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import PyPDF2
|
| 3 |
+
import docx
|
| 4 |
+
from io import BytesIO
|
| 5 |
+
import json
|
| 6 |
+
from mistral_inference import MistralInference # Hypothetical API wrapper for Mistral model
|
| 7 |
|
| 8 |
+
# Function to extract text from PDF
|
| 9 |
+
def extract_text_from_pdf(file):
|
| 10 |
+
pdf_reader = PyPDF2.PdfReader(file)
|
| 11 |
+
text = ""
|
| 12 |
+
for page in pdf_reader.pages:
|
| 13 |
+
text += page.extract_text()
|
| 14 |
+
return text
|
| 15 |
+
|
| 16 |
+
# Function to extract text from Word document
|
| 17 |
+
def extract_text_from_docx(file):
|
| 18 |
+
doc = docx.Document(file)
|
| 19 |
+
text = "\n".join([para.text for para in doc.paragraphs])
|
| 20 |
+
return text
|
| 21 |
+
|
| 22 |
+
# Function to process uploaded file based on type
|
| 23 |
+
def process_uploaded_file(file):
|
| 24 |
+
if file.name.endswith(".pdf"):
|
| 25 |
+
return extract_text_from_pdf(file)
|
| 26 |
+
elif file.name.endswith(".docx"):
|
| 27 |
+
return extract_text_from_docx(file)
|
| 28 |
+
else:
|
| 29 |
+
raise ValueError("Unsupported file format. Please upload a PDF or Word document.")
|
| 30 |
+
|
| 31 |
+
# Hypothetical Mistral API wrapper (replace with actual API call)
|
| 32 |
+
class MistralInference:
|
| 33 |
+
def __init__(self, model="mistralai/Mistral-7B-Instruct-v0.3", provider="together"):
|
| 34 |
+
self.model = model
|
| 35 |
+
self.provider = provider
|
| 36 |
+
|
| 37 |
+
def analyze(self, resume_text, job_description):
|
| 38 |
+
# Simulated prompt to Mistral model
|
| 39 |
+
prompt = f"""
|
| 40 |
+
Analyze the following resume against the job description for ATS compatibility.
|
| 41 |
+
Provide a detailed breakdown of ATS parameters (keywords, formatting, skills match, experience relevance, education)
|
| 42 |
+
and assign a score out of 100 for each, along with an overall score. Return the result in JSON format.
|
| 43 |
+
|
| 44 |
+
Resume:
|
| 45 |
+
{resume_text}
|
| 46 |
+
|
| 47 |
+
Job Description:
|
| 48 |
+
{job_description}
|
| 49 |
+
"""
|
| 50 |
+
|
| 51 |
+
# Simulated response (replace with actual API call)
|
| 52 |
+
response = {
|
| 53 |
+
"ats_analysis": {
|
| 54 |
+
"keywords": {
|
| 55 |
+
"score": 85,
|
| 56 |
+
"details": "Key terms like 'Python', 'Machine Learning' found, missing 'AWS'."
|
| 57 |
+
},
|
| 58 |
+
"formatting": {
|
| 59 |
+
"score": 90,
|
| 60 |
+
"details": "Simple layout, readable by ATS, no complex tables."
|
| 61 |
+
},
|
| 62 |
+
"skills_match": {
|
| 63 |
+
"score": 80,
|
| 64 |
+
"details": "Strong match for programming skills, lacks cloud skills."
|
| 65 |
+
},
|
| 66 |
+
"experience_relevance": {
|
| 67 |
+
"score": 75,
|
| 68 |
+
"details": "Relevant experience in data science, but duration slightly short."
|
| 69 |
+
},
|
| 70 |
+
"education": {
|
| 71 |
+
"score": 95,
|
| 72 |
+
"details": "Matches required degree in Computer Science."
|
| 73 |
+
},
|
| 74 |
+
"overall_score": 85
|
| 75 |
+
}
|
| 76 |
+
}
|
| 77 |
+
return json.dumps(response, indent=2)
|
| 78 |
+
|
| 79 |
+
# Main function to analyze resume
|
| 80 |
+
def analyze_resume(file, job_description):
|
| 81 |
+
try:
|
| 82 |
+
resume_text = process_uploaded_file(file)
|
| 83 |
+
mistral = MistralInference()
|
| 84 |
+
result = mistral.analyze(resume_text, job_description)
|
| 85 |
+
return result
|
| 86 |
+
except Exception as e:
|
| 87 |
+
return json.dumps({"error": str(e)}, indent=2)
|
| 88 |
+
|
| 89 |
+
# Gradio interface
|
| 90 |
+
with gr.Blocks(fill_height=True, title="Smart ATS Resume Analyzer") as demo:
|
| 91 |
with gr.Sidebar():
|
| 92 |
+
gr.Markdown("# Smart ATS Resume Analyzer")
|
| 93 |
+
gr.Markdown("Upload your resume (PDF/Word) and enter a job description to get an ATS compatibility score.")
|
| 94 |
+
button = gr.LoginButton("Sign in with Hugging Face")
|
| 95 |
+
|
| 96 |
+
with gr.Row():
|
| 97 |
+
with gr.Column(scale=1):
|
| 98 |
+
resume_upload = gr.File(label="Upload Resume (PDF or Word)", file_types=[".pdf", ".docx"])
|
| 99 |
+
job_desc = gr.Textbox(label="Job Description", lines=10, placeholder="Paste the job description here...")
|
| 100 |
+
submit_btn = gr.Button("Analyze Resume")
|
| 101 |
+
with gr.Column(scale=2):
|
| 102 |
+
output = gr.JSON(label="ATS Analysis Result")
|
| 103 |
+
|
| 104 |
+
# Connect the button to the analysis function
|
| 105 |
+
submit_btn.click(
|
| 106 |
+
fn=analyze_resume,
|
| 107 |
+
inputs=[resume_upload, job_desc],
|
| 108 |
+
outputs=output
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
# Load Mistral model (hypothetical, adjust based on actual integration)
|
| 112 |
gr.load("models/mistralai/Mistral-7B-Instruct-v0.3", accept_token=button, provider="together")
|
| 113 |
+
|
| 114 |
demo.launch()
|