Deshnni04 commited on
Commit
40ee024
Β·
verified Β·
1 Parent(s): 517d78f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +148 -0
app.py ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ import PyPDF2
4
+ import docx
5
+ import google.generativeai as genai
6
+
7
+ # Configure Gemini API
8
+ GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
9
+ genai.configure(api_key=GEMINI_API_KEY)
10
+
11
+ # Streamlit Page Setup
12
+ st.set_page_config(page_title="Resume Analyzer & Job Matcher", page_icon="🧠", layout="wide")
13
+
14
+ # πŸ’… Custom Styling
15
+ st.markdown("""
16
+ <style>
17
+ body {
18
+ background-color: #f5f8fa;
19
+ }
20
+ .main-title {
21
+ font-size: 40px;
22
+ font-weight: bold;
23
+ color: #2c3e50;
24
+ text-align: center;
25
+ margin-top: 10px;
26
+ }
27
+ .sub-title {
28
+ font-size: 18px;
29
+ color: #7f8c8d;
30
+ text-align: center;
31
+ margin-bottom: 30px;
32
+ }
33
+ .section-card {
34
+ background-color: #ffffff;
35
+ border-radius: 12px;
36
+ padding: 20px;
37
+ box-shadow: 0 4px 12px rgba(0,0,0,0.1);
38
+ margin-top: 20px;
39
+ }
40
+ .success-banner {
41
+ background: linear-gradient(to right, #27ae60, #2ecc71);
42
+ color: white;
43
+ font-size: 16px;
44
+ padding: 12px;
45
+ text-align: center;
46
+ border-radius: 8px;
47
+ margin-top: 30px;
48
+ }
49
+ </style>
50
+ """, unsafe_allow_html=True)
51
+
52
+ # 🧠 Titles
53
+ st.markdown('<h1 class="main-title">🧠 Resume Analyzer & Job Matcher</h1>', unsafe_allow_html=True)
54
+ st.markdown('<p class="sub-title">AI-Powered Career Insights from Your Resume</p>', unsafe_allow_html=True)
55
+
56
+ # πŸ“‚ Upload Section
57
+ uploaded_file = st.file_uploader("πŸ“„ Upload your Resume (.pdf or .docx)", type=["pdf", "docx"])
58
+
59
+ # πŸ“„ Resume Text Extraction
60
+ def extract_resume_text(file_path, file_type):
61
+ text = ""
62
+ if file_type == "pdf":
63
+ with open(file_path, "rb") as f:
64
+ reader = PyPDF2.PdfReader(f)
65
+ for page in reader.pages:
66
+ text += page.extract_text() + "\n"
67
+ elif file_type == "docx":
68
+ doc = docx.Document(file_path)
69
+ for para in doc.paragraphs:
70
+ text += para.text + "\n"
71
+ return text.strip()
72
+
73
+ # πŸ€– Analyze Resume
74
+ def analyze_resume(text):
75
+ prompt = f"""
76
+ You are an AI Resume Consultant. Based on the following resume details:
77
+ {text}
78
+
79
+ Respond in this format:
80
+ [Job Roles]
81
+ - Job Role 1
82
+ - Job Role 2
83
+
84
+ [Missing Skills]
85
+ - Skill: Suggestion
86
+
87
+ [Resume Tips]
88
+ - Tip 1
89
+ - Tip 2
90
+ """
91
+ model = genai.GenerativeModel("gemini-1.5-pro-latest")
92
+ response = model.generate_content(prompt)
93
+ return response.text.strip()
94
+
95
+ # 🧠 Main Logic
96
+ if uploaded_file:
97
+ file_type = uploaded_file.name.split(".")[-1]
98
+ file_path = f"temp_resume.{file_type}"
99
+
100
+ with open(file_path, "wb") as f:
101
+ f.write(uploaded_file.read())
102
+
103
+ st.success("βœ… Resume uploaded successfully!")
104
+
105
+ with st.spinner("πŸ” Extracting and analyzing your resume..."):
106
+ resume_text = extract_resume_text(file_path, file_type)
107
+ if not resume_text:
108
+ st.error("❌ No text could be extracted. Try uploading a different file.")
109
+ else:
110
+ result = analyze_resume(resume_text)
111
+
112
+ os.remove(file_path)
113
+
114
+ # βœ… Parsed Output
115
+ if result:
116
+ st.markdown("### πŸ“Œ Results")
117
+ st.markdown('<div class="section-card">', unsafe_allow_html=True)
118
+
119
+ # Tabs for categorized output
120
+ tab1, tab2, tab3 = st.tabs(["πŸ’Ό Job Matches", "πŸ” Missing Skills", "πŸ“ Resume Tips"])
121
+ job_roles, skills, tips = "", "", ""
122
+ if "[Job Roles]" in result:
123
+ sections = result.split("[")
124
+ for section in sections:
125
+ if section.startswith("Job Roles]"):
126
+ job_roles = section.replace("Job Roles]", "").strip()
127
+ elif section.startswith("Missing Skills]"):
128
+ skills = section.replace("Missing Skills]", "").strip()
129
+ elif section.startswith("Resume Tips]"):
130
+ tips = section.replace("Resume Tips]", "").strip()
131
+
132
+ with tab1:
133
+ st.markdown("#### πŸ’Ό Suitable Job Roles")
134
+ st.markdown(job_roles or "No job roles found.")
135
+
136
+ with tab2:
137
+ st.markdown("#### πŸ” Missing Skills & Recommendations")
138
+ st.markdown(skills or "No missing skills found.")
139
+
140
+ with tab3:
141
+ st.markdown("#### πŸ“ Resume Improvement Tips")
142
+ st.markdown(tips or "No resume tips provided.")
143
+
144
+ st.markdown("</div>", unsafe_allow_html=True)
145
+ st.markdown('<div class="success-banner">🎯 Resume analyzed! Take the next step in your career. πŸš€</div>', unsafe_allow_html=True)
146
+ st.balloons()
147
+ else:
148
+ st.error("⚠ Failed to analyze resume.")