Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,100 +1,177 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
|
|
|
|
|
|
| 3 |
import docx
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def extract_text(file):
|
|
|
|
| 8 |
if file is None:
|
| 9 |
-
return "
|
| 10 |
|
| 11 |
file_name = file.name
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
elif file_name.endswith(".docx"):
|
| 25 |
-
doc = docx.Document(file)
|
| 26 |
-
text = "\n".join([p.text for p in doc.paragraphs])
|
| 27 |
|
| 28 |
-
else:
|
| 29 |
-
return "Unsupported file format. Upload PDF or DOCX."
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
-
return f"Error reading file: {str(e)}"
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
| 38 |
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
|
| 42 |
-
"
|
| 43 |
-
"
|
| 44 |
-
"nlp","git","docker","flask","fastapi"
|
| 45 |
]
|
| 46 |
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
|
| 54 |
|
| 55 |
-
result = f"""
|
| 56 |
-
Resume Score: {score}/100
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
|
|
|
| 60 |
|
| 61 |
-
|
| 62 |
-
• Add more technical skills
|
| 63 |
-
• Include projects
|
| 64 |
-
• Mention measurable achievements
|
| 65 |
-
• Use clear headings
|
| 66 |
-
"""
|
| 67 |
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
|
|
|
| 70 |
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
with gr.Blocks(title="Resume Analyzer") as demo:
|
| 74 |
|
| 75 |
-
gr.Markdown("#
|
| 76 |
-
gr.Markdown("Upload your resume and get instant
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
)
|
| 82 |
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
|
|
|
| 88 |
)
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
inputs=
|
| 93 |
-
outputs=
|
| 94 |
)
|
| 95 |
|
| 96 |
|
| 97 |
-
# --------
|
|
|
|
|
|
|
| 98 |
|
| 99 |
if __name__ == "__main__":
|
| 100 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
import PyPDF2
|
| 5 |
import docx
|
| 6 |
|
| 7 |
+
|
| 8 |
+
# -----------------------------
|
| 9 |
+
# Resume Parsing
|
| 10 |
+
# -----------------------------
|
| 11 |
|
| 12 |
def extract_text(file):
|
| 13 |
+
|
| 14 |
if file is None:
|
| 15 |
+
return ""
|
| 16 |
|
| 17 |
file_name = file.name
|
| 18 |
|
| 19 |
+
if file_name.endswith(".pdf"):
|
| 20 |
+
reader = PyPDF2.PdfReader(file)
|
| 21 |
+
text = ""
|
| 22 |
+
for page in reader.pages:
|
| 23 |
+
text += page.extract_text() or ""
|
| 24 |
+
return text
|
| 25 |
+
|
| 26 |
+
elif file_name.endswith(".docx"):
|
| 27 |
+
doc = docx.Document(file)
|
| 28 |
+
text = "\n".join([p.text for p in doc.paragraphs])
|
| 29 |
+
return text
|
| 30 |
+
|
| 31 |
+
elif file_name.endswith(".txt"):
|
| 32 |
+
return file.read().decode("utf-8")
|
| 33 |
|
| 34 |
+
return ""
|
|
|
|
|
|
|
|
|
|
| 35 |
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
# -----------------------------
|
| 38 |
+
# Simple Resume Analyzer
|
| 39 |
+
# -----------------------------
|
| 40 |
|
| 41 |
+
def analyze_resume(resume_text):
|
|
|
|
| 42 |
|
| 43 |
+
if not resume_text or len(resume_text.strip()) == 0:
|
| 44 |
+
return {
|
| 45 |
+
"score": 0,
|
| 46 |
+
"message": "No resume text detected"
|
| 47 |
+
}
|
| 48 |
|
| 49 |
+
text = resume_text.lower()
|
| 50 |
|
| 51 |
+
technical_keywords = [
|
| 52 |
+
"python","java","c++","machine learning","ai",
|
| 53 |
+
"data","sql","tensorflow","pytorch","pandas",
|
| 54 |
+
"numpy","git","linux"
|
| 55 |
+
]
|
| 56 |
|
| 57 |
+
soft_keywords = [
|
| 58 |
+
"teamwork","communication","leadership",
|
| 59 |
+
"problem solving","adaptability"
|
|
|
|
| 60 |
]
|
| 61 |
|
| 62 |
+
tech_found = [k for k in technical_keywords if k in text]
|
| 63 |
+
soft_found = [k for k in soft_keywords if k in text]
|
| 64 |
+
|
| 65 |
+
score = min(100, (len(tech_found)*8 + len(soft_found)*5))
|
| 66 |
|
| 67 |
+
result = {
|
| 68 |
+
"score": score,
|
| 69 |
+
"technical_skills": tech_found,
|
| 70 |
+
"soft_skills": soft_found,
|
| 71 |
+
"recommendation": "Add more quantified achievements and skills." if score < 50 else "Good resume. Minor improvements recommended."
|
| 72 |
+
}
|
| 73 |
|
| 74 |
+
return result
|
| 75 |
|
|
|
|
|
|
|
| 76 |
|
| 77 |
+
# -----------------------------
|
| 78 |
+
# Export Functions
|
| 79 |
+
# -----------------------------
|
| 80 |
|
| 81 |
+
def export_json(data):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
+
if data is None:
|
| 84 |
+
return None
|
| 85 |
+
|
| 86 |
+
file_path = "analysis.json"
|
| 87 |
+
|
| 88 |
+
with open(file_path,"w") as f:
|
| 89 |
+
json.dump(data,f,indent=4)
|
| 90 |
+
|
| 91 |
+
return file_path
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def export_text(data):
|
| 95 |
+
|
| 96 |
+
if data is None:
|
| 97 |
+
return None
|
| 98 |
+
|
| 99 |
+
file_path = "analysis.txt"
|
| 100 |
+
|
| 101 |
+
with open(file_path,"w") as f:
|
| 102 |
+
f.write(str(data))
|
| 103 |
|
| 104 |
+
return file_path
|
| 105 |
|
| 106 |
+
|
| 107 |
+
# -----------------------------
|
| 108 |
+
# Processing Pipeline
|
| 109 |
+
# -----------------------------
|
| 110 |
+
|
| 111 |
+
def process_resume(file):
|
| 112 |
+
|
| 113 |
+
text = extract_text(file)
|
| 114 |
+
|
| 115 |
+
analysis = analyze_resume(text)
|
| 116 |
+
|
| 117 |
+
return text, analysis
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
# -----------------------------
|
| 121 |
+
# UI
|
| 122 |
+
# -----------------------------
|
| 123 |
|
| 124 |
with gr.Blocks(title="Resume Analyzer") as demo:
|
| 125 |
|
| 126 |
+
gr.Markdown("# AI Resume Analyzer")
|
| 127 |
+
gr.Markdown("Upload your resume and get an instant score.")
|
| 128 |
+
|
| 129 |
+
with gr.Row():
|
| 130 |
|
| 131 |
+
resume_file = gr.File(label="Upload Resume (PDF, DOCX, TXT)")
|
| 132 |
+
|
| 133 |
+
load_btn = gr.Button("Analyze Resume")
|
| 134 |
+
|
| 135 |
+
resume_text = gr.Textbox(
|
| 136 |
+
label="Extracted Resume Text",
|
| 137 |
+
lines=10
|
| 138 |
)
|
| 139 |
|
| 140 |
+
analysis_output = gr.JSON(label="Analysis Result")
|
| 141 |
+
|
| 142 |
+
with gr.Row():
|
| 143 |
+
|
| 144 |
+
export_json_btn = gr.Button("Export JSON")
|
| 145 |
+
export_text_btn = gr.Button("Export Text")
|
| 146 |
+
|
| 147 |
+
download_file = gr.File(label="Download Analysis")
|
| 148 |
+
|
| 149 |
+
# -----------------------------
|
| 150 |
+
# Button Actions
|
| 151 |
+
# -----------------------------
|
| 152 |
+
|
| 153 |
+
load_btn.click(
|
| 154 |
+
process_resume,
|
| 155 |
+
inputs=resume_file,
|
| 156 |
+
outputs=[resume_text, analysis_output]
|
| 157 |
+
)
|
| 158 |
|
| 159 |
+
export_json_btn.click(
|
| 160 |
+
export_json,
|
| 161 |
+
inputs=analysis_output,
|
| 162 |
+
outputs=download_file
|
| 163 |
)
|
| 164 |
|
| 165 |
+
export_text_btn.click(
|
| 166 |
+
export_text,
|
| 167 |
+
inputs=analysis_output,
|
| 168 |
+
outputs=download_file
|
| 169 |
)
|
| 170 |
|
| 171 |
|
| 172 |
+
# -----------------------------
|
| 173 |
+
# Launch
|
| 174 |
+
# -----------------------------
|
| 175 |
|
| 176 |
if __name__ == "__main__":
|
| 177 |
demo.launch()
|