hamnamughal's picture
Update app.py
3a2e4f4 verified
import gradio as gr
import pdfplumber
import textstat
import spacy
from transformers import pipeline
import language_tool_python
# Load tools
sentiment_pipeline = pipeline("sentiment-analysis")
nlp = spacy.load("en_core_web_sm")
tool = language_tool_python.LanguageTool('en-US')
def analyze_resume(uploaded_pdf, keywords):
try:
# Read PDF content
with pdfplumber.open(uploaded_pdf.name) as pdf:
text = ""
for page in pdf.pages:
text += page.extract_text() or ""
# Basic stats
word_count = len(text.split())
readability_score = textstat.flesch_reading_ease(text)
# Sentiment
sentiment = sentiment_pipeline(text[:512])[0] # Limit text to avoid overload
# Keyword matching
keyword_list = [kw.strip().lower() for kw in keywords.split(',')]
matched_keywords = [kw for kw in keyword_list if kw in text.lower()]
# NER
doc = nlp(text)
named_entities = [(ent.text, ent.label_) for ent in doc.ents]
# Grammar & Spelling
matches = tool.check(text)
grammar_issues = len(matches)
# Resume grade (mock logic)
resume_grade = "Excellent" if readability_score > 60 and grammar_issues < 5 else "Needs Improvement"
return (
readability_score,
sentiment['label'],
word_count,
f"{len(matched_keywords)} matched: {', '.join(matched_keywords)}",
str(named_entities),
f"{grammar_issues} issues",
resume_grade
)
except Exception as e:
return [f"Error: {str(e)}"] * 7
# Gradio UI
iface = gr.Interface(
fn=analyze_resume,
inputs=[
gr.File(label="Upload Resume (PDF)"),
gr.Textbox(label="Job Keywords (comma-separated)")
],
outputs=[
gr.Textbox(label="Readability Score"),
gr.Textbox(label="Sentiment"),
gr.Textbox(label="Word Count"),
gr.Textbox(label="Keyword Match and Matched Keywords"),
gr.Textbox(label="Named Entities (NER)"),
gr.Textbox(label="Grammar and Spelling Suggestions"),
gr.Textbox(label="Resume Grade")
],
title="Resume Analyzer"
)
iface.launch()