Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,6 @@ import fitz # PyMuPDF
|
|
| 3 |
from fastapi import FastAPI
|
| 4 |
import docx
|
| 5 |
import re
|
| 6 |
-
import os
|
| 7 |
|
| 8 |
def extract_text_from_pdf(file):
|
| 9 |
doc = fitz.open(stream=file.read(), filetype="pdf")
|
|
@@ -27,8 +26,7 @@ def extract_info(text):
|
|
| 27 |
data["name"] = name_match.group(1).strip() if name_match else ""
|
| 28 |
data["email"] = email_match.group(0) if email_match else ""
|
| 29 |
data["phone"] = phone_match.group(0) if phone_match else ""
|
| 30 |
-
|
| 31 |
-
# Rough extraction for keywords
|
| 32 |
skill_keywords = ["Python", "Java", "C++", "NLP", "Machine Learning", "Data Science", "SQL", "React"]
|
| 33 |
found_skills = [skill for skill in skill_keywords if skill.lower() in text.lower()]
|
| 34 |
data["skills"] = found_skills
|
|
@@ -44,23 +42,35 @@ def process_resume(file):
|
|
| 44 |
return {"error": "Unsupported file format"}
|
| 45 |
|
| 46 |
extracted_data = extract_info(text)
|
| 47 |
-
return extracted_data
|
| 48 |
|
| 49 |
-
with gr.Blocks(css="body { max-width:
|
| 50 |
-
gr.Markdown("
|
| 51 |
-
gr.Markdown("Upload a **PDF** or **DOCX** resume. Extracted info will appear below in JSON.")
|
| 52 |
|
| 53 |
with gr.Row():
|
| 54 |
-
with gr.Column():
|
| 55 |
-
file_input = gr.File(label="Upload Resume")
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
| 58 |
|
| 59 |
-
|
|
|
|
| 60 |
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from fastapi import FastAPI
|
| 4 |
import docx
|
| 5 |
import re
|
|
|
|
| 6 |
|
| 7 |
def extract_text_from_pdf(file):
|
| 8 |
doc = fitz.open(stream=file.read(), filetype="pdf")
|
|
|
|
| 26 |
data["name"] = name_match.group(1).strip() if name_match else ""
|
| 27 |
data["email"] = email_match.group(0) if email_match else ""
|
| 28 |
data["phone"] = phone_match.group(0) if phone_match else ""
|
| 29 |
+
|
|
|
|
| 30 |
skill_keywords = ["Python", "Java", "C++", "NLP", "Machine Learning", "Data Science", "SQL", "React"]
|
| 31 |
found_skills = [skill for skill in skill_keywords if skill.lower() in text.lower()]
|
| 32 |
data["skills"] = found_skills
|
|
|
|
| 42 |
return {"error": "Unsupported file format"}
|
| 43 |
|
| 44 |
extracted_data = extract_info(text)
|
| 45 |
+
return extracted_data, "β
Resume processed successfully!"
|
| 46 |
|
| 47 |
+
with gr.Blocks(title="Smart Resume Parser - JSON Edition", css="body { max-width: 1100px; margin: auto; }") as demo:
|
| 48 |
+
gr.Markdown("## π Smart Resume Parser β Extract structured info from PDF/DOCX (Deployable API)")
|
|
|
|
| 49 |
|
| 50 |
with gr.Row():
|
| 51 |
+
with gr.Column(scale=1):
|
| 52 |
+
file_input = gr.File(label="π Upload Resume (PDF or DOCX)")
|
| 53 |
+
with gr.Row():
|
| 54 |
+
analyze_button = gr.Button("π Parse Resume", variant="primary")
|
| 55 |
+
reset_button = gr.Button("β»οΈ Reset", variant="stop")
|
| 56 |
+
status_box = gr.Textbox(label="π Status", value="β³ Waiting for input...", interactive=False)
|
| 57 |
|
| 58 |
+
with gr.Column(scale=2):
|
| 59 |
+
output_json = gr.JSON(label="π§ Extracted Resume Data")
|
| 60 |
|
| 61 |
+
# State for reset
|
| 62 |
+
reset_flag = gr.State(False)
|
| 63 |
+
|
| 64 |
+
analyze_button.click(
|
| 65 |
+
fn=process_resume,
|
| 66 |
+
inputs=[file_input],
|
| 67 |
+
outputs=[output_json, status_box]
|
| 68 |
+
)
|
| 69 |
|
| 70 |
+
reset_button.click(
|
| 71 |
+
fn=lambda: (None, "β³ Waiting for input..."),
|
| 72 |
+
inputs=[],
|
| 73 |
+
outputs=[output_json, status_box]
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
app = gr.mount_gradio_app(app=FastAPI(), blocks=demo, path="/")
|