Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -14,10 +14,10 @@ GROQ_ENDPOINT = "https://api.groq.com/openai/v1/chat/completions"
|
|
14 |
GROQ_MODEL = "llama-3.3-70b-versatile"
|
15 |
|
16 |
# ------------------------------------------------------------------------------
|
17 |
-
# π₯
|
18 |
# ------------------------------------------------------------------------------
|
19 |
def call_groq_api(messages, temperature=0.7):
|
20 |
-
"""Handles API calls to Groq
|
21 |
headers = {
|
22 |
"Authorization": f"Bearer {GROQ_API_KEY}",
|
23 |
"Content-Type": "application/json"
|
@@ -40,7 +40,7 @@ def call_groq_api(messages, temperature=0.7):
|
|
40 |
# π FILE PROCESSING (PDF / DOCX)
|
41 |
# ------------------------------------------------------------------------------
|
42 |
def extract_resume_text(file_obj):
|
43 |
-
"""Extracts text from PDF
|
44 |
file_bytes = file_obj.read()
|
45 |
file_obj.seek(0)
|
46 |
ext = os.path.splitext(file_obj.name)[-1].lower()
|
@@ -53,40 +53,10 @@ def extract_resume_text(file_obj):
|
|
53 |
return file_bytes.decode("utf-8", errors="ignore")
|
54 |
|
55 |
# ------------------------------------------------------------------------------
|
56 |
-
# π― AI-
|
57 |
-
# ------------------------------------------------------------------------------
|
58 |
-
def parse_resume(resume_text):
|
59 |
-
"""Extracts structured JSON resume details using Groq's Llama 3.3 model."""
|
60 |
-
messages = [
|
61 |
-
{"role": "system", "content": "You are a resume parsing expert. Extract structured data."},
|
62 |
-
{"role": "user", "content": f"Extract structured data from this resume:\n{resume_text}\n\nOutput as JSON."}
|
63 |
-
]
|
64 |
-
return call_groq_api(messages, temperature=0.4)
|
65 |
-
|
66 |
-
# ------------------------------------------------------------------------------
|
67 |
-
# βοΈ AI-Powered Cover Letter Generator
|
68 |
-
# ------------------------------------------------------------------------------
|
69 |
-
def generate_cover_letter(candidate_json, job_description):
|
70 |
-
"""Generates a professional cover letter using structured candidate data."""
|
71 |
-
date_str = datetime.today().strftime("%d - %b - %Y")
|
72 |
-
messages = [
|
73 |
-
{"role": "system", "content": "You are a top-tier career advisor. Write persuasive cover letters."},
|
74 |
-
{"role": "user", "content": f"""
|
75 |
-
Generate a professional cover letter using:
|
76 |
-
- Candidate Profile: {candidate_json}
|
77 |
-
- Job Description: {job_description}
|
78 |
-
- Date: {date_str}
|
79 |
-
|
80 |
-
The cover letter should be engaging, personalized, and formatted professionally.
|
81 |
-
"""}
|
82 |
-
]
|
83 |
-
return call_groq_api(messages, temperature=0.5)
|
84 |
-
|
85 |
-
# ------------------------------------------------------------------------------
|
86 |
-
# π AI-Powered Resume Creator
|
87 |
# ------------------------------------------------------------------------------
|
88 |
def generate_resume(first_name, last_name, location, work_experience, school_experience, skills):
|
89 |
-
"""Generates a
|
90 |
candidate_data = json.dumps({
|
91 |
"first_name": first_name,
|
92 |
"last_name": last_name,
|
@@ -97,31 +67,51 @@ def generate_resume(first_name, last_name, location, work_experience, school_exp
|
|
97 |
}, indent=2)
|
98 |
|
99 |
messages = [
|
100 |
-
{"role": "system", "content": "You are a professional resume writer."},
|
101 |
{"role": "user", "content": f"""
|
102 |
-
|
103 |
{candidate_data}
|
104 |
-
|
105 |
-
Ensure:
|
106 |
-
-
|
107 |
-
-
|
108 |
-
- A compelling summary if possible.
|
109 |
"""}
|
110 |
]
|
111 |
return call_groq_api(messages, temperature=0.5)
|
112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
# ------------------------------------------------------------------------------
|
114 |
# π¨ STREAMLIT UI DESIGN
|
115 |
# ------------------------------------------------------------------------------
|
116 |
-
st.set_page_config(page_title="AI
|
117 |
st.title("π AI-Powered Resume & Cover Letter Generator")
|
118 |
-
st.markdown("
|
119 |
|
120 |
tabs = st.tabs(["π Cover Letter Generator", "π Resume Creator"])
|
121 |
|
122 |
# ----- COVER LETTER GENERATOR -----
|
123 |
with tabs[0]:
|
124 |
st.header("π Cover Letter Generator")
|
|
|
125 |
resume_file = st.file_uploader("Upload Your Resume", type=["pdf", "docx", "txt"])
|
126 |
job_description = st.text_area("Paste Job Description", height=200)
|
127 |
|
@@ -129,7 +119,7 @@ with tabs[0]:
|
|
129 |
if resume_file and job_description.strip():
|
130 |
with st.spinner("β¨ Processing resume..."):
|
131 |
resume_text = extract_resume_text(resume_file)
|
132 |
-
candidate_json =
|
133 |
cover_letter = generate_cover_letter(candidate_json, job_description)
|
134 |
st.success("β
Cover Letter Generated!")
|
135 |
st.text_area("π Your Cover Letter:", cover_letter, height=300)
|
|
|
14 |
GROQ_MODEL = "llama-3.3-70b-versatile"
|
15 |
|
16 |
# ------------------------------------------------------------------------------
|
17 |
+
# π₯ API HANDLER FOR GROQ AI
|
18 |
# ------------------------------------------------------------------------------
|
19 |
def call_groq_api(messages, temperature=0.7):
|
20 |
+
"""Handles API calls to Groq's Llama 3.3 model with robust error handling."""
|
21 |
headers = {
|
22 |
"Authorization": f"Bearer {GROQ_API_KEY}",
|
23 |
"Content-Type": "application/json"
|
|
|
40 |
# π FILE PROCESSING (PDF / DOCX)
|
41 |
# ------------------------------------------------------------------------------
|
42 |
def extract_resume_text(file_obj):
|
43 |
+
"""Extracts text from uploaded resumes (PDF, DOCX, TXT)."""
|
44 |
file_bytes = file_obj.read()
|
45 |
file_obj.seek(0)
|
46 |
ext = os.path.splitext(file_obj.name)[-1].lower()
|
|
|
53 |
return file_bytes.decode("utf-8", errors="ignore")
|
54 |
|
55 |
# ------------------------------------------------------------------------------
|
56 |
+
# π― AI-POWERED RESUME GENERATION
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
# ------------------------------------------------------------------------------
|
58 |
def generate_resume(first_name, last_name, location, work_experience, school_experience, skills):
|
59 |
+
"""Generates a structured, ATS-friendly resume."""
|
60 |
candidate_data = json.dumps({
|
61 |
"first_name": first_name,
|
62 |
"last_name": last_name,
|
|
|
67 |
}, indent=2)
|
68 |
|
69 |
messages = [
|
70 |
+
{"role": "system", "content": "You are a professional resume writer specializing in ATS optimization."},
|
71 |
{"role": "user", "content": f"""
|
72 |
+
Generate a **highly professional**, **ATS-optimized resume** using the following structured information:
|
73 |
{candidate_data}
|
74 |
+
|
75 |
+
- Ensure proper formatting: Name, Contact, Summary, Experience, Education, Skills, Certifications.
|
76 |
+
- Use industry best practices.
|
77 |
+
- Format each job with measurable achievements.
|
|
|
78 |
"""}
|
79 |
]
|
80 |
return call_groq_api(messages, temperature=0.5)
|
81 |
|
82 |
+
# ------------------------------------------------------------------------------
|
83 |
+
# βοΈ AI-POWERED COVER LETTER GENERATION
|
84 |
+
# ------------------------------------------------------------------------------
|
85 |
+
def generate_cover_letter(candidate_json, job_description):
|
86 |
+
"""Generates a compelling cover letter using structured candidate details."""
|
87 |
+
date_str = datetime.today().strftime("%d - %b - %Y")
|
88 |
+
messages = [
|
89 |
+
{"role": "system", "content": "You are a top-tier career advisor. Write highly persuasive cover letters."},
|
90 |
+
{"role": "user", "content": f"""
|
91 |
+
Generate a **professional cover letter** using:
|
92 |
+
- Candidate Profile: {candidate_json}
|
93 |
+
- Job Description: {job_description}
|
94 |
+
- Date: {date_str}
|
95 |
+
|
96 |
+
- Ensure **persuasion**, **tailored content**, and **measurable achievements**.
|
97 |
+
- Format: **Introduction, Key Skills, Experience Alignment, Closing**.
|
98 |
+
"""}
|
99 |
+
]
|
100 |
+
return call_groq_api(messages, temperature=0.6)
|
101 |
+
|
102 |
# ------------------------------------------------------------------------------
|
103 |
# π¨ STREAMLIT UI DESIGN
|
104 |
# ------------------------------------------------------------------------------
|
105 |
+
st.set_page_config(page_title="AI Resume & Cover Letter Generator", layout="wide")
|
106 |
st.title("π AI-Powered Resume & Cover Letter Generator")
|
107 |
+
st.markdown("### Create a **perfect ATS-friendly Resume** and **tailored Cover Letter** using **Groq AI (Llama 3.3-70B)**")
|
108 |
|
109 |
tabs = st.tabs(["π Cover Letter Generator", "π Resume Creator"])
|
110 |
|
111 |
# ----- COVER LETTER GENERATOR -----
|
112 |
with tabs[0]:
|
113 |
st.header("π Cover Letter Generator")
|
114 |
+
|
115 |
resume_file = st.file_uploader("Upload Your Resume", type=["pdf", "docx", "txt"])
|
116 |
job_description = st.text_area("Paste Job Description", height=200)
|
117 |
|
|
|
119 |
if resume_file and job_description.strip():
|
120 |
with st.spinner("β¨ Processing resume..."):
|
121 |
resume_text = extract_resume_text(resume_file)
|
122 |
+
candidate_json = generate_resume("First", "Last", "Houston, TX", "Experience", "Education", "Skills")
|
123 |
cover_letter = generate_cover_letter(candidate_json, job_description)
|
124 |
st.success("β
Cover Letter Generated!")
|
125 |
st.text_area("π Your Cover Letter:", cover_letter, height=300)
|