Resume / app.py
sairaarif89's picture
Create app.py
0b28f5d verified
import streamlit as st
import google.generativeai as genai
from fpdf import FPDF
# Set up your Gemini API key
GEMINI_API_KEY = "AIzaSyBpQcVs_Or_Asb4xnNcpk1qUbos-2o9Ddc"
genai.configure(api_key=GEMINI_API_KEY)
# Initialize the Gemini model
model = genai.GenerativeModel('gemini-pro')
# Function to generate a resume
def generate_resume(user_details, job_description):
prompt = f"""
You are a professional resume builder. Based on the following user details and job description, create a well-structured and tailored resume:
User Details:
- Name: {user_details['name']}
- Contact Info: {user_details['contact_info']}
- Education: {user_details['education']}
- Work Experience: {user_details['work_experience']}
- Skills: {user_details['skills']}
Job Description:
{job_description}
Provide the resume in Markdown format with the following sections:
1. **Name and Contact Info**
2. **Summary** (a brief introduction tailored to the job)
3. **Education**
4. **Work Experience** (use bullet points to highlight achievements)
5. **Skills**
6. **Additional Sections** (e.g., Certifications, Projects, if applicable)
"""
try:
# Generate the resume using Gemini
response = model.generate_content(prompt)
return response.text
except ValueError as e:
return f"Sorry, the system could not generate the resume due to an error. Please try again."
# Function to convert Markdown to PDF
def markdown_to_pdf(markdown_text, filename="resume.pdf"):
pdf = FPDF()
pdf.add_page()
pdf.set_font("Arial", size=12)
# Split Markdown text into lines
lines = markdown_text.split("\n")
for line in lines:
# Handle headers (e.g., ## Section)
if line.startswith("##"):
pdf.set_font("Arial", "B", 16)
pdf.cell(200, 10, txt=line.replace("##", "").strip(), ln=True)
pdf.set_font("Arial", size=12)
else:
pdf.cell(200, 10, txt=line, ln=True)
# Save the PDF
pdf.output(filename)
# Streamlit app
def main():
st.title("📄 AI-Powered Resume Builder")
st.write("Welcome! Fill in your details, and we'll create a professional resume tailored to your dream job.")
# Collect user details
st.header("Your Details")
name = st.text_input("Full Name:")
contact_info = st.text_input("Contact Info (Email/Phone):")
education = st.text_area("Education (e.g., Degree, University, Year):")
work_experience = st.text_area("Work Experience (e.g., Job Title, Company, Duration, Responsibilities):")
skills = st.text_area("Skills (e.g., Python, Data Analysis, Project Management):")
# Collect job description
st.header("Job Description")
job_description = st.text_area("Paste the job description you're targeting:")
if st.button("Generate Resume"):
if name and contact_info and education and work_experience and skills and job_description:
user_details = {
"name": name,
"contact_info": contact_info,
"education": education,
"work_experience": work_experience,
"skills": skills
}
# Generate the resume
st.write("Generating your resume...")
resume = generate_resume(user_details, job_description)
st.success("Here's your tailored resume:")
st.markdown(resume)
# Convert the resume to PDF
pdf_filename = "resume.pdf"
markdown_to_pdf(resume, pdf_filename)
# Provide a download link for the PDF
with open(pdf_filename, "rb") as file:
st.download_button(
label="Download Resume as PDF",
data=file,
file_name=pdf_filename,
mime="application/pdf"
)
else:
st.error("Please fill in all the fields to generate your resume.")
# Run the app
if __name__ == "__main__":
main()