Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,128 +1,147 @@
|
|
| 1 |
-
import gradio as gr
|
| 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 |
-
resume_path_or_text = resume_file_or_text
|
| 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 |
-
label="
|
| 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 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
demo.launch(theme=gr.themes.Soft())
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
from resume_agent import full_app, scanner_app
|
| 4 |
+
|
| 5 |
+
def step1_analyze(job_input, resume_file_or_text):
|
| 6 |
+
"""
|
| 7 |
+
Step 1: Runs ONLY the Scanner to find gaps.
|
| 8 |
+
Output goes to the 'Human Feedback' box for you to edit.
|
| 9 |
+
"""
|
| 10 |
+
# Handle File vs Text Input
|
| 11 |
+
resume_path_or_text = ""
|
| 12 |
+
if hasattr(resume_file_or_text, "name"):
|
| 13 |
+
resume_path_or_text = resume_file_or_text.name
|
| 14 |
+
else:
|
| 15 |
+
resume_path_or_text = resume_file_or_text
|
| 16 |
+
|
| 17 |
+
# Prepare Inputs
|
| 18 |
+
inputs = {
|
| 19 |
+
"job_description": job_input,
|
| 20 |
+
"original_resume": resume_path_or_text,
|
| 21 |
+
"resume_text": "",
|
| 22 |
+
"job_text": "",
|
| 23 |
+
"missing_skills": ""
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
try:
|
| 27 |
+
# Run the partial "Scanner Graph"
|
| 28 |
+
result = scanner_app.invoke(inputs)
|
| 29 |
+
# Return the missing skills list so you can see/edit it
|
| 30 |
+
return result['missing_skills']
|
| 31 |
+
|
| 32 |
+
except Exception as e:
|
| 33 |
+
return f"Error during scan: {str(e)}"
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def step2_optimize(job_input, resume_file_or_text, user_notes):
|
| 37 |
+
"""
|
| 38 |
+
Step 2: Runs the Full Optimizer + Document Generator.
|
| 39 |
+
It returns text previews AND file paths for the PDFs.
|
| 40 |
+
"""
|
| 41 |
+
# 1. Handle File vs Text Input
|
| 42 |
+
resume_path_or_text = ""
|
| 43 |
+
if hasattr(resume_file_or_text, "name"):
|
| 44 |
+
resume_path_or_text = resume_file_or_text.name
|
| 45 |
+
else:
|
| 46 |
+
resume_path_or_text = resume_file_or_text
|
| 47 |
+
|
| 48 |
+
# 2. Prepare Inputs
|
| 49 |
+
inputs = {
|
| 50 |
+
"job_description": job_input,
|
| 51 |
+
"original_resume": resume_path_or_text,
|
| 52 |
+
"human_notes": user_notes, # Uses your edited feedback
|
| 53 |
+
|
| 54 |
+
# Initialize empty fields for the state
|
| 55 |
+
"resume_text": "", "job_text": "", "optimized_resume": "",
|
| 56 |
+
"feedback": "", "score": 0, "iteration": 0,
|
| 57 |
+
"cover_letter": "", "resume_pdf_path": "", "cover_letter_pdf_path": ""
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
try:
|
| 61 |
+
# Run the "Full Graph" (Improver -> Reviewer -> PDF Gen)
|
| 62 |
+
final_state = full_app.invoke(inputs)
|
| 63 |
+
|
| 64 |
+
# Extract Results
|
| 65 |
+
opt_resume_text = final_state.get('optimized_resume', "Error generating resume.")
|
| 66 |
+
score_text = f"Score: {final_state.get('score', 0)}/100"
|
| 67 |
+
feedback_text = final_state.get('feedback', 'No feedback provided.')
|
| 68 |
+
|
| 69 |
+
# Get PDF Paths
|
| 70 |
+
resume_pdf = final_state.get('resume_pdf_path')
|
| 71 |
+
cover_pdf = final_state.get('cover_letter_pdf_path')
|
| 72 |
+
|
| 73 |
+
return opt_resume_text, score_text, feedback_text, resume_pdf, cover_pdf
|
| 74 |
+
|
| 75 |
+
except Exception as e:
|
| 76 |
+
return f"Error: {str(e)}", "Error", "Error", None, None
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
# --- BUILD THE USER INTERFACE ---
|
| 80 |
+
|
| 81 |
+
with gr.Blocks(title="AI Resume Agent") as demo:
|
| 82 |
+
gr.Markdown("# AI Resume Optimizer")
|
| 83 |
+
gr.Markdown("An Agentic workflow: **Scan** for gaps, **Edit** the plan, then **Generate** professional PDFs.")
|
| 84 |
+
|
| 85 |
+
with gr.Row():
|
| 86 |
+
# --- LEFT COLUMN (Inputs) ---
|
| 87 |
+
with gr.Column(scale=1):
|
| 88 |
+
job_in = gr.Textbox(
|
| 89 |
+
label="1. Job Description (URL or Text)",
|
| 90 |
+
placeholder="Paste Job Text OR a Link (https://...)",
|
| 91 |
+
lines=3
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
resume_in = gr.File(
|
| 95 |
+
label="2. Upload Resume (PDF)",
|
| 96 |
+
file_types=[".pdf"],
|
| 97 |
+
type="filepath"
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
# Action Button 1
|
| 101 |
+
btn_analyze = gr.Button("Step 1: Find Missing Skills", variant="secondary")
|
| 102 |
+
|
| 103 |
+
notes_in = gr.Textbox(
|
| 104 |
+
label="3. Missing Skills & Context (Editable)",
|
| 105 |
+
placeholder="Click 'Step 1' to see missing skills here. \nThen DELETE skills you don't have, or ADD context like 'I used this in my internship...'",
|
| 106 |
+
lines=10,
|
| 107 |
+
interactive=True
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
# Action Button 2
|
| 111 |
+
btn_optimize = gr.Button("Step 2: Generate Optimized Resume", variant="primary")
|
| 112 |
+
|
| 113 |
+
# --- RIGHT COLUMN (Outputs) ---
|
| 114 |
+
with gr.Column(scale=1):
|
| 115 |
+
score_out = gr.Label(label="Match Score")
|
| 116 |
+
feedback_out = gr.Textbox(label="Critique Summary", lines=4)
|
| 117 |
+
|
| 118 |
+
# Text Preview - REMOVED 'show_copy_button' to fix crash
|
| 119 |
+
resume_out = gr.Textbox(
|
| 120 |
+
label="Final Resume (Text Preview)",
|
| 121 |
+
lines=15
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
# PDF Download Area
|
| 125 |
+
gr.Markdown("### 📥 Download Documents")
|
| 126 |
+
with gr.Row():
|
| 127 |
+
pdf_resume_out = gr.File(label="Optimized Resume PDF")
|
| 128 |
+
pdf_cover_out = gr.File(label="Cover Letter PDF")
|
| 129 |
+
|
| 130 |
+
# --- WIRING THE BUTTONS ---
|
| 131 |
+
|
| 132 |
+
# 1. Analyze Button -> Updates the 'notes_in' box
|
| 133 |
+
btn_analyze.click(
|
| 134 |
+
fn=step1_analyze,
|
| 135 |
+
inputs=[job_in, resume_in],
|
| 136 |
+
outputs=[notes_in]
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
# 2. Optimize Button -> Returns Text + PDF Files
|
| 140 |
+
btn_optimize.click(
|
| 141 |
+
fn=step2_optimize,
|
| 142 |
+
inputs=[job_in, resume_in, notes_in],
|
| 143 |
+
outputs=[resume_out, score_out, feedback_out, pdf_resume_out, pdf_cover_out]
|
| 144 |
+
)
|
| 145 |
+
|
| 146 |
+
if __name__ == "__main__":
|
| 147 |
demo.launch(theme=gr.themes.Soft())
|