mgbam commited on
Commit
30543fe
Β·
verified Β·
1 Parent(s): 54707ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -45
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
- # πŸ”₯ ADVANCED API CALL FUNCTION
18
  # ------------------------------------------------------------------------------
19
  def call_groq_api(messages, temperature=0.7):
20
- """Handles API calls to Groq for chat-based completions with robust error handling."""
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 or DOCX resumes."""
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-Powered Resume Parsing
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 well-formatted professional resume."""
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
- Create a structured, ATS-friendly resume using:
103
  {candidate_data}
104
-
105
- Ensure:
106
- - Clear sections (Personal Info, Experience, Education, Skills)
107
- - Professional formatting
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-Powered Job Assistant", layout="wide")
117
  st.title("πŸš€ AI-Powered Resume & Cover Letter Generator")
118
- st.markdown("#### Generate a **Resume** or a **Cover Letter** using **Llama 3.3-70B** powered by **Groq AI**.")
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 = parse_resume(resume_text)
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)