Spaces:
Running
Running
Added Code
Browse files- src/streamlit_app.py +177 -38
src/streamlit_app.py
CHANGED
|
@@ -1,40 +1,179 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
|
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import google.generativeai as genai
|
| 3 |
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
import pdfkit
|
| 8 |
+
from docx import Document
|
| 9 |
+
|
| 10 |
+
import time
|
| 11 |
+
|
| 12 |
+
load_dotenv()
|
| 13 |
+
genai_Api_Key = st.secrets["API_KEY"]
|
| 14 |
+
|
| 15 |
+
genai.configure(api_key=genai_Api_Key)
|
| 16 |
+
|
| 17 |
+
generation_config = {
|
| 18 |
+
"temperature": 1,
|
| 19 |
+
"top_p": 0.95,
|
| 20 |
+
"top_k": 64,
|
| 21 |
+
"max_output_tokens": 1024,
|
| 22 |
+
"response_mime_type": "text/plain",
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
def generate_resume(name, job_title, skills, experience_title, experience_company, experience_start_date, experience_end_date, experience_description, education_degree, education_major, education_university, education_start_date, education_end_date, template, custom_prompt):
|
| 26 |
+
model=genai.GenerativeModel(
|
| 27 |
+
model_name="gemini-1.5-pro",
|
| 28 |
+
generation_config=generation_config,
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
if template == "Basic":
|
| 32 |
+
promt_prefix = "Please generate a basic resume based on the following information:"
|
| 33 |
+
elif template == "Professional":
|
| 34 |
+
promt_prefix = "Please generate a professional resume based on the following information:"
|
| 35 |
+
elif template == "Modern":
|
| 36 |
+
promt_prefix = "Please generate a modern resume based on the following information:"
|
| 37 |
+
elif template == "Creative":
|
| 38 |
+
promt_prefix = "Please generate a creative resume based on the following information:"
|
| 39 |
+
elif template == "Elegant":
|
| 40 |
+
promt_prefix = "Please generate an elegant resume based on the following information:"
|
| 41 |
+
elif template == "Executive":
|
| 42 |
+
promt_prefix = "Please generate an executive resume based on the following information:"
|
| 43 |
+
elif template == "Classic":
|
| 44 |
+
promt_prefix = "Please generate a classic resume based on the following information:"
|
| 45 |
+
elif template == "Simple":
|
| 46 |
+
promt_prefix = "Please generate a simple resume based on the following information:"
|
| 47 |
+
elif template == "Minimalist":
|
| 48 |
+
promt_prefix = "Please generate a minimalist resume based on the following information:"
|
| 49 |
+
elif template == "Stylish":
|
| 50 |
+
promt_prefix = "Please generate a stylish resume based on the following information:"
|
| 51 |
+
elif template == "Sophisticated":
|
| 52 |
+
promt_prefix = "Please generate a sophisticated resume based on the following information:"
|
| 53 |
+
elif template == "Traditional":
|
| 54 |
+
promt_prefix = "Please generate a traditional resume based on the following information:"
|
| 55 |
+
elif template == "Contemporary":
|
| 56 |
+
promt_prefix = "Please generate a contemporary resume based on the following information:"
|
| 57 |
+
elif template == "Futuristic":
|
| 58 |
+
promt_prefix = "Please generate a futuristic resume based on the following information:"
|
| 59 |
+
elif template == "Artistic":
|
| 60 |
+
promt_prefix = "Please generate an artistic resume based on the following information:"
|
| 61 |
+
elif template == "Colorful":
|
| 62 |
+
promt_prefix = "Please generate a colorful resume based on the following information:"
|
| 63 |
+
elif template == "Bold":
|
| 64 |
+
promt_prefix = "Please generate a bold resume based on the following information:"
|
| 65 |
+
elif template == "Unique":
|
| 66 |
+
promt_prefix = "Please generate a unique resume based on the following information:"
|
| 67 |
+
elif template == "Custom":
|
| 68 |
+
promt_prefix = "Please generate a custom resume based on the following information:"
|
| 69 |
+
|
| 70 |
+
context = f"{promt_prefix}\nName: {name}\nJob Title: {job_title}\nSkills: {', '.join(skills)}\nExperience: {experience_title} at {experience_company} ({experience_start_date} - {experience_end_date})\nDescription: {experience_description}\nEducation: {education_degree} in {education_major} from {education_university} ({education_start_date} - {education_end_date})\n{custom_prompt}"
|
| 71 |
+
chat_session = model.start_chat(
|
| 72 |
+
history=[
|
| 73 |
+
{
|
| 74 |
+
"role": "user",
|
| 75 |
+
"parts": [
|
| 76 |
+
context
|
| 77 |
+
],
|
| 78 |
+
}
|
| 79 |
+
],
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
response = chat_session.send_message(context)
|
| 83 |
+
|
| 84 |
+
# text = response.candidates[0].content if isinstance(response.candidates[0].content, str) else response.candidates[0].content.text
|
| 85 |
+
text = response.candidates[0].content.parts[0].text
|
| 86 |
+
|
| 87 |
+
return text
|
| 88 |
+
|
| 89 |
+
def clean_resume_text(text):
|
| 90 |
+
replacements = {
|
| 91 |
+
"[Add Email Address]": "[Your Email Address]",
|
| 92 |
+
"[Add Phone Number]": "[Your Phone Number]",
|
| 93 |
+
"[Add LinkedIn Profile]": "[Your LinkedIn Profile]",
|
| 94 |
+
"[Add University Name]": "[Your University Name]",
|
| 95 |
+
"[Add Graduation Year]": "[Your Graduation Year]",
|
| 96 |
+
}
|
| 97 |
+
for old, new in replacements.items():
|
| 98 |
+
text = text.replace(old, new)
|
| 99 |
+
return text
|
| 100 |
+
|
| 101 |
+
def create_pdf_download_link(text, filename="resume.pdf"):
|
| 102 |
+
pdf = pdfkit.from_string(text, False)
|
| 103 |
+
st.markdown(f'<a href="data:application/pdf;base64,{pdf.decode("utf-8")}" download="{filename}">Download PDF</a>', unsafe_allow_html=True)
|
| 104 |
+
|
| 105 |
+
def create_docx_download_link(text, filename="resume.docx"):
|
| 106 |
+
document = Document()
|
| 107 |
+
document.add_paragraph(text)
|
| 108 |
+
document.save("resume.docx")
|
| 109 |
+
with open("resume.docx", "rb") as file:
|
| 110 |
+
docx_data = file.read()
|
| 111 |
+
st.download_button(
|
| 112 |
+
label="Download DOCX",
|
| 113 |
+
data=docx_data,
|
| 114 |
+
file_name=filename,
|
| 115 |
+
mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
| 116 |
+
)
|
| 117 |
+
st.set_page_config(
|
| 118 |
+
page_title="SmartContent Studio",
|
| 119 |
+
page_icon=":briefcase:",
|
| 120 |
+
# layout="wide",
|
| 121 |
+
initial_sidebar_state="expanded",
|
| 122 |
+
menu_items={
|
| 123 |
+
'Get Help': 'https://www.example.com',
|
| 124 |
+
'Report a bug': "https://www.example.com",
|
| 125 |
+
'About': "This is a SmartContent Studio app!"
|
| 126 |
+
}
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
st.title("SmartContent Studio")
|
| 130 |
+
col1, col2 = st.columns(2)
|
| 131 |
+
with col1:
|
| 132 |
+
name = st.text_input("Enter your full name")
|
| 133 |
+
with col2:
|
| 134 |
+
job_title = st.text_input("Enter your job title")
|
| 135 |
+
skills = st.multiselect("Enter your skills", ["Python", "Machine Learning", "Deep Learning", "Data Science", "Software Development", "Web Development", "Cloud Computing", "DevOps", "Cybersecurity", "Blockchain", "IoT", "Big Data", "Data Analytics", "Data Engineering", "Data Visualization", "Business Intelligence", "Artificial Intelligence", "Natural Language Processing", "Computer Vision", "Robotics", "Automation", "Quantum Computing", "Augmented Reality", "Virtual Reality", "Game Development", "Mobile Development", "Desktop Development", "Backend Development", "Frontend Development", "Full Stack Development", "Database Management", "System Administration", "Network Administration", "IT Support", "Technical Support", "Customer Support", "Sales", "Marketing", "Product Management", "Project Management", "Quality Assurance", "Testing", "Technical Writing", "Content Writing", "Copywriting", "Blogging", "SEO", "SEM", "Social Media Marketing", "Email Marketing", "Affiliate Marketing", "Influencer Marketing", "Growth Hacking", "Digital Marketing", "E-commerce", "Dropshipping", "Freelancing", "Entrepreneurship", "Startup", "Venture Capital", "Private Equity", "Investment Banking", "Finance", "Accounting", "Economics", "Business Analysis", "Business Development", "Consulting", "Legal", "Human Resources", "Recruitment", "Training", "Learning & Development", "Employee Relations", "Organizational Development", "Change Management", "Performance Management", "Compensation & Benefits", "Payroll", "Talent Management", "Diversity & Inclusion", "Employee Engagement", "Workforce Planning", "Succession Planning", "HRIS", "People Analytics", "Health & Safety", "Wellness", "Occupational Health", "Employee Assistance", "Labor Relations", "Union Negotiations", "Employment Law", "Regulatory Compliance", "Risk Management", "Insurance", "Claims", "Underwriting", "Actuarial", "Investments", "Wealth Management", "Financial Planning", "Retirement Planning", "Tax Planning", "Estate Planning", "Trusts & Estates", "Philanthropy", "Charitable Giving", "Social Impact", "Sustainability", "Corporate Social Responsibility", "Environmental, Social, Governance", "Ethics", "Compliance", "Anti-Money Laundering", "Fraud Prevention", "Cybersecurity", "Information Security", "Privacy", "Data Protection", "GDPR", "CCPA", "HIPAA", "PCI DSS", "SOX", "ISO 27001", "NIST", "CIS", "CMMC", "ITIL", "COBIT", "Agile", "Scrum", "Kanban", "Lean", "Six Sigma", "Kaizen", "Total Quality Management"])
|
| 136 |
+
with st.expander("Experience"):
|
| 137 |
+
col_exp1, col_exp2 = st.columns(2)
|
| 138 |
+
with col_exp1:
|
| 139 |
+
experience_title = st.text_input("Title")
|
| 140 |
+
with col_exp2:
|
| 141 |
+
experience_company = st.text_input("Company")
|
| 142 |
+
with col_exp1:
|
| 143 |
+
experience_start_date = st.text_input("Start date")
|
| 144 |
+
with col_exp2:
|
| 145 |
+
experience_end_date = st.text_input("End date")
|
| 146 |
+
experience_description = st.text_area("Description")
|
| 147 |
+
with st.expander("Education"):
|
| 148 |
+
col_edu1, col_edu2 = st.columns(2)
|
| 149 |
+
col_edu3, col_edu4 = st.columns(2)
|
| 150 |
+
with col_edu1:
|
| 151 |
+
education_degree = st.text_input("Degree")
|
| 152 |
+
with col_edu2:
|
| 153 |
+
education_major = st.text_input("Major")
|
| 154 |
+
education_university = st.text_input("University")
|
| 155 |
+
with col_edu3:
|
| 156 |
+
education_start_date = st.text_input("Admission date")
|
| 157 |
+
with col_edu4:
|
| 158 |
+
education_end_date = st.text_input("Passout date")
|
| 159 |
+
template = st.selectbox("Select a resume template", ["Basic", "Professional", "Modern", "Creative", "Elegant", "Executive", "Classic", "Simple", "Minimalist", "Stylish", "Sophisticated", "Traditional", "Contemporary", "Futuristic", "Artistic", "Colorful", "Bold", "Unique", "Custom"])
|
| 160 |
+
custom_prompt = st.text_area("Enter any additional information or custom prompt")
|
| 161 |
+
|
| 162 |
+
if st.button("Generate Resume"):
|
| 163 |
+
if name and job_title and skills and experience_title and experience_company and experience_start_date and experience_end_date and experience_description and education_degree and education_major and education_university and education_start_date and education_end_date and template and custom_prompt:
|
| 164 |
+
my_bar = st.progress(0)
|
| 165 |
+
for percent_complete in range(100):
|
| 166 |
+
time.sleep(0.5)
|
| 167 |
+
my_bar.progress(percent_complete + 1)
|
| 168 |
+
try:
|
| 169 |
+
resume = generate_resume(name, job_title, skills, experience_title, experience_company, experience_start_date, experience_end_date, experience_description, education_degree, education_major, education_university, education_start_date, education_end_date, template, custom_prompt)
|
| 170 |
+
cleaned = clean_resume_text(resume)
|
| 171 |
+
st.markdown("#### Generated Resume")
|
| 172 |
+
st.write(cleaned)
|
| 173 |
+
|
| 174 |
+
# create_pdf_download_link(cleaned)
|
| 175 |
+
create_docx_download_link(cleaned)
|
| 176 |
+
except Exception as e:
|
| 177 |
+
st.error(f"An error occurred: {e}")
|
| 178 |
+
else:
|
| 179 |
+
st.warning("Please enter all the data!")
|