-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
547 lines (429 loc) · 17.6 KB
/
app.py
File metadata and controls
547 lines (429 loc) · 17.6 KB
1
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
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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
"""
SmartResume AI - AI-Powered Resume Builder
Main Streamlit Application
"""
import streamlit as st
import os
from components.form_sections import (
render_personal_info_form,
render_professional_summary_form,
render_education_form,
render_skills_form,
render_experience_form,
render_projects_form,
render_certifications_form
)
from components.ai_generator import AIGenerator, render_ai_buttons, handle_ai_generation, handle_ai_generation_pre_render
from components.preview import render_resume_preview, render_empty_preview
from components.pdf_exporter import create_download_button, create_cover_letter_download_button
from components.cover_letter_form import (
render_cover_letter_personal_info,
render_cover_letter_form,
render_cover_letter_content,
render_cover_letter_preview,
render_cover_letter_actions
)
from components.cover_letter_generator import (
render_cover_letter_generator,
handle_cover_letter_generation_pre_render
)
from components.resume_manager import (
handle_resume_load_pre_render,
render_save_resume_section,
render_load_resume_section,
render_export_import_section,
render_resume_selector_for_cover_letter,
render_save_cover_letter_section
)
# Page configuration
st.set_page_config(
page_title="SmartResume AI - AI-Powered Resume Builder",
page_icon="📄",
layout="wide",
initial_sidebar_state="expanded",
menu_items={
'Get Help': 'https://github.com/UtkarshSrivastava1139/SmartResume',
'Report a bug': 'https://github.com/UtkarshSrivastava1139/SmartResume/issues',
'About': '# SmartResume AI\nAI-Powered Resume & Cover Letter Builder with Google Gemini'
}
)
# Load custom CSS
def load_custom_css():
"""Load custom CSS styling based on theme"""
theme = st.session_state.get('theme', 'light')
css_filename = 'dark.css' if theme == 'dark' else 'custom.css'
css_file = os.path.join(os.path.dirname(__file__), 'assets', 'styles', css_filename)
if os.path.exists(css_file):
with open(css_file) as f:
st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
load_custom_css()
# Initialize session state
def initialize_session_state():
"""Initialize session state variables"""
if 'initialized' not in st.session_state:
st.session_state.initialized = True
st.session_state.theme = 'light' # Default theme
st.session_state.name = ''
st.session_state.email = ''
st.session_state.phone = ''
st.session_state.linkedin = ''
st.session_state.location = ''
st.session_state.portfolio = ''
st.session_state.target_role = ''
st.session_state.experience_years = 0
st.session_state.summary = ''
st.session_state.education_list = []
st.session_state.technical_skills = ''
st.session_state.soft_skills = ''
st.session_state.experience_list = []
st.session_state.projects_list = []
st.session_state.certifications = ''
# Cover Letter fields
st.session_state.cl_job_title = ''
st.session_state.cl_company = ''
st.session_state.cl_job_description = ''
st.session_state.cl_additional_notes = ''
st.session_state.cover_letter_content = ''
initialize_session_state()
# Initialize AI Generator
@st.cache_resource
def get_ai_generator():
"""Get cached AI generator instance"""
return AIGenerator()
# Main App
def main():
"""Main application function"""
# Header
st.markdown("""
<div style='text-align: center; padding: 1rem 0;'>
<h1 style='color: #1f77b4; margin-bottom: 0.5rem;'>SmartResume AI</h1>
<p style='color: #666; font-size: 1.1rem;'>Build Your Professional Resume with AI in Minutes</p>
</div>
""", unsafe_allow_html=True)
# Sidebar
with st.sidebar:
st.image("https://img.icons8.com/fluency/96/000000/resume.png", width=60)
st.markdown("### Navigation")
page = st.radio(
"Go to:",
["Home", "Build Resume", "Cover Letter", "About"],
label_visibility="collapsed"
)
st.markdown("---")
# Theme Toggle
current_theme = st.session_state.get('theme', 'light')
theme_label = "🌙 Dark Mode" if current_theme == 'light' else "☀️ Light Mode"
if st.button(theme_label, use_container_width=True):
st.session_state.theme = 'dark' if current_theme == 'light' else 'light'
st.rerun()
st.markdown("---")
st.markdown("### Features")
st.markdown("""
- AI-Powered Content
- ATS-Friendly Format
- Instant PDF Download
- Professional Templates
- Real-Time Preview
""")
st.markdown("---")
st.markdown("### Tips")
st.markdown("""
1. Fill in all sections
2. Use AI to enhance content
3. Review the preview
4. Download your resume
""")
st.markdown("---")
st.info("**Tip**: Use the AI enhancement features to create professional, ATS-optimized content!")
# Show AI Provider at bottom of sidebar
try:
ai_gen = get_ai_generator()
if ai_gen and ai_gen.client:
provider = ai_gen.client.get_provider_name()
st.caption(f"🤖 AI Provider: **{provider}**")
except:
pass
# Pages
if page == "Home":
render_home_page()
elif page == "Build Resume":
render_builder_page()
elif page == "Cover Letter":
render_cover_letter_page()
else:
render_about_page()
def render_home_page():
"""Render home page"""
st.markdown("---")
col1, col2, col3 = st.columns(3)
with col1:
st.markdown("""
### AI-Powered
Let Google's Gemini AI write professional resume content for you
""")
with col2:
st.markdown("""
### Lightning Fast
Create a complete resume in just 10 minutes
""")
with col3:
st.markdown("""
### ATS-Friendly
Optimized to pass Applicant Tracking Systems
""")
st.markdown("---")
st.markdown("""
## Why Choose SmartResume AI?
Creating an effective resume is challenging. **SmartResume AI** solves common problems:
- **Writer's Block?** AI generates compelling content from basic inputs
- **ATS Rejection?** Our format is optimized for tracking systems
- **Time-Consuming?** Create professional resumes in minutes, not hours
- **Lack of Expertise?** AI knows what recruiters want to see
- **Missing Keywords?** AI suggests relevant skills and optimizes content
## How It Works
1. **Fill the Form** - Enter your basic information
2. **AI Enhancement** - Click AI buttons to generate professional content
3. **Real-Time Preview** - See your resume as you build it
4. **Download PDF** - Get your ATS-friendly resume instantly
## Get Started
Ready to build your resume? Click **"Build Resume"** in the sidebar to start!
""")
if st.button("Start Building Now", use_container_width=True, type="primary"):
st.session_state.page = "Build Resume"
st.rerun()
def render_builder_page():
"""Render resume builder page"""
# Get cached AI Generator instance
ai_generator = get_ai_generator()
# Handle resume loading BEFORE rendering widgets
handle_resume_load_pre_render()
# Handle any pending AI generation BEFORE rendering widgets
handle_ai_generation_pre_render(ai_generator)
# Check if API key is configured
gemini_key = os.getenv("GEMINI_API_KEY")
openrouter_key = os.getenv("OPENROUTER_API_KEY")
if not gemini_key and not openrouter_key:
st.warning("""
**AI API Key Not Configured**
To use AI features, configure one of these options:
**Option 1 - Google Gemini (Recommended):**
1. Get your free API key from https://aistudio.google.com/app/apikey
2. Add to `.env` file: `GEMINI_API_KEY=your_api_key_here`
**Option 2 - OpenRouter (Free Models Available):**
1. Get your API key from https://openrouter.ai/keys
2. Add to `.env` file: `OPENROUTER_API_KEY=your_api_key_here`
You can still use the app, but AI features will be disabled.
""")
# Create two-column layout
col_form, col_preview = st.columns([1, 1])
with col_form:
st.markdown("### Resume Information")
# Personal Information
personal_data = render_personal_info_form()
st.markdown("---")
# Professional Summary
summary_data = render_professional_summary_form()
st.markdown("---")
# Education
education_data = render_education_form()
st.markdown("---")
# Skills
skills_data = render_skills_form()
st.markdown("---")
# Work Experience
experience_data = render_experience_form()
st.markdown("---")
# Projects
projects_data = render_projects_form()
st.markdown("---")
# Certifications
certifications_data = render_certifications_form()
st.markdown("---")
# AI Enhancement Buttons (use same ai_generator instance)
ai_buttons = render_ai_buttons()
# Collect all resume data
resume_data = {
**personal_data,
**summary_data,
**skills_data,
'education_list': education_data,
'experience_list': experience_data,
'projects_list': projects_data,
'certifications': certifications_data
}
# Update save section with resume data
with st.expander("💾 Save & Load Resume", expanded=False):
tab1, tab2, tab3 = st.tabs(["Save", "Load", "Export/Import"])
with tab1:
render_save_resume_section(resume_data)
with tab2:
render_load_resume_section()
with tab3:
render_export_import_section()
# Handle AI generation
handle_ai_generation(ai_buttons, ai_generator, resume_data)
st.markdown("---")
# Download PDF Button
st.markdown("### Download Your Resume")
if st.button("Generate & Download PDF", use_container_width=True, type="primary"):
if not resume_data.get('name') or not resume_data.get('email'):
st.error("Please fill in at least Name and Email to generate PDF")
else:
with st.spinner("Generating PDF..."):
pdf_bytes, filename = create_download_button(resume_data)
if pdf_bytes:
st.download_button(
label="Download PDF",
data=pdf_bytes,
file_name=filename,
mime="application/pdf",
use_container_width=True
)
st.success("Resume PDF generated successfully!")
with col_preview:
st.markdown("### Live Preview")
# Show preview if there's data
if resume_data.get('name'):
render_resume_preview(resume_data)
else:
render_empty_preview()
def render_cover_letter_page():
"""Render cover letter generator page"""
# Handle any pending AI generation BEFORE rendering widgets
handle_cover_letter_generation_pre_render()
# Check if API key is configured
gemini_key = os.getenv("GEMINI_API_KEY")
openrouter_key = os.getenv("OPENROUTER_API_KEY")
if not gemini_key and not openrouter_key:
st.warning("""
**AI API Key Not Configured**
To use AI features, configure one of these options:
**Option 1 - Google Gemini (Recommended):**
1. Get your free API key from https://aistudio.google.com/app/apikey
2. Add to `.env` file: `GEMINI_API_KEY=your_api_key_here`
**Option 2 - OpenRouter (Free Models Available):**
1. Get your API key from https://openrouter.ai/keys
2. Add to `.env` file: `OPENROUTER_API_KEY=your_api_key_here`
You can still enter cover letter manually, but AI generation will be disabled.
""")
st.markdown("---")
st.markdown("## Cover Letter Generator")
st.caption("Create a professional, ATS-optimized cover letter tailored to your target role")
# Resume Linking Section
with st.expander("🔗 Link to Resume (Recommended)", expanded=True):
st.info("📋 Link this cover letter to a saved resume for AI to use your skills, experience, and achievements!")
render_resume_selector_for_cover_letter()
if st.session_state.get('cl_linked_resume_name'):
st.success(f"✅ Linked to resume: **{st.session_state['cl_linked_resume_name']}**")
st.markdown("---")
# Personal Information Section (at top)
render_cover_letter_personal_info()
st.markdown("---")
# Two-column layout
col_left, col_right = st.columns([1, 1])
with col_left:
# Form section
render_cover_letter_form()
st.markdown("---")
# AI Generation button
render_cover_letter_generator()
st.markdown("---")
# Content editor
render_cover_letter_content()
st.markdown("---")
# Save cover letter section
render_save_cover_letter_section()
with col_right:
# Preview section
render_cover_letter_preview()
# Actions at bottom (full width)
st.markdown("---")
# Handle PDF download button
if st.session_state.get('download_cover_letter_pdf_btn'):
name = st.session_state.get('name', '')
email = st.session_state.get('email', '')
phone = st.session_state.get('phone', '')
location = st.session_state.get('location', '')
company = st.session_state.get('cl_company', 'Company')
job_title = st.session_state.get('cl_job_title', 'Position')
cover_letter_content = st.session_state.get('cover_letter_content', '')
if not name or not cover_letter_content:
st.error("Please ensure your Name is filled and cover letter is generated before downloading PDF.")
else:
with st.spinner("Generating PDF..."):
pdf_bytes, filename = create_cover_letter_download_button(
name=name,
email=email,
phone=phone,
location=location,
company=company,
job_title=job_title,
cover_letter_content=cover_letter_content
)
if pdf_bytes:
st.download_button(
label="Download Cover Letter PDF",
data=pdf_bytes,
file_name=filename,
mime="application/pdf",
use_container_width=True
)
st.success("Cover letter PDF generated successfully!")
render_cover_letter_actions()
def render_about_page():
"""Render about page"""
st.markdown("---")
st.markdown("""
## About SmartResume AI
**SmartResume AI** is an innovative web-based resume builder that leverages Google's Gemini AI
to automatically generate professional, ATS-friendly resume content from basic user inputs.
### Technology Stack
- **Frontend**: Streamlit (Python web framework)
- **AI Engine**: Google Gemini API
- **PDF Generation**: FPDF2
- **Language**: Python 3.10+
### Key Features
#### 1. AI Content Generation
- Professional summary generation
- Experience bullet points enhancement
- Project description improvement
- Skills suggestion based on target role
#### 2. ATS Optimization
- Clean, parseable format
- Standard section headings
- No complex graphics or tables
- Proper font and spacing
#### 3. User-Friendly Interface
- Simple, intuitive forms
- Real-time preview
- One-click PDF download
- Mobile-responsive design
### How AI Helps
Our AI integration helps you:
- **Write Better**: Transform basic descriptions into compelling, professional content
- **Save Time**: Generate content in seconds instead of hours
- **Optimize Keywords**: Include relevant skills and industry terms
- **Show Impact**: Create achievement-focused bullet points
- **Stay Professional**: Maintain consistent tone and style
### Privacy & Security
- No data is stored on our servers
- All processing happens in your session
- API calls are secure and encrypted
- You own all generated content
### Getting Help
For issues or questions:
1. Check the sidebar tips
2. Review the form validation messages
3. Ensure your API key is configured correctly
4. Try refreshing the page if issues persist
### Credits
- Powered by Google Gemini AI
- Built with Streamlit
- Icons from Icons8
### Version
**Version 1.0.0** - Academic Project
---
Made with for job seekers everywhere
""")
if __name__ == "__main__":
main()