Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,109 +1,147 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from docx import Document
|
|
|
|
| 3 |
import io
|
| 4 |
-
from transformers import pipeline
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
# Using Flan-T5-large for generating job descriptions
|
| 10 |
-
generator = pipeline("text-generation", model="google/flan-t5-large")
|
| 11 |
-
return generator
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
doc = Document()
|
| 16 |
-
doc.add_heading(f'Job Description for {designation}', level=1)
|
| 17 |
-
doc.add_paragraph(job_description)
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
doc_io.seek(0)
|
| 23 |
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
# Streamlit
|
| 27 |
-
st.set_page_config(
|
| 28 |
-
page_title="Construction Job Description Generator",
|
| 29 |
-
page_icon="👷♂️",
|
| 30 |
-
layout="wide"
|
| 31 |
-
)
|
| 32 |
|
| 33 |
-
|
| 34 |
-
st.
|
| 35 |
-
<style>
|
| 36 |
-
.main {
|
| 37 |
-
background-color: #f4f4f9;
|
| 38 |
-
}
|
| 39 |
-
.stButton>button {
|
| 40 |
-
background-color: #4CAF50;
|
| 41 |
-
color: white;
|
| 42 |
-
border-radius: 5px;
|
| 43 |
-
padding: 10px 20px;
|
| 44 |
-
font-size: 16px;
|
| 45 |
-
}
|
| 46 |
-
.stSelectbox>div>div {
|
| 47 |
-
background-color: #ffffff;
|
| 48 |
-
border-radius: 5px;
|
| 49 |
-
}
|
| 50 |
-
.header {
|
| 51 |
-
font-size: 36px;
|
| 52 |
-
color: #333333;
|
| 53 |
-
text-align: center;
|
| 54 |
-
margin-bottom: 20px;
|
| 55 |
-
}
|
| 56 |
-
.subheader {
|
| 57 |
-
font-size: 24px;
|
| 58 |
-
color: #555555;
|
| 59 |
-
margin-bottom: 10px;
|
| 60 |
-
}
|
| 61 |
-
</style>
|
| 62 |
-
""", unsafe_allow_html=True)
|
| 63 |
|
| 64 |
-
#
|
| 65 |
-
st.
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
|
|
|
| 76 |
|
| 77 |
-
#
|
| 78 |
-
st.
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
-
#
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
# Display job description
|
| 95 |
-
st.markdown('<div class="subheader">Generated Job Description</div>', unsafe_allow_html=True)
|
| 96 |
-
st.write(generated_text)
|
| 97 |
-
|
| 98 |
-
# Create Word document
|
| 99 |
-
doc_io = create_word_document(role, generated_text)
|
| 100 |
-
|
| 101 |
-
# Download button for Word document
|
| 102 |
-
st.download_button(
|
| 103 |
-
label="Download Job Description as Word",
|
| 104 |
-
data=doc_io,
|
| 105 |
-
file_name=f"{role.replace(' ', '_')}_job_description.docx",
|
| 106 |
-
mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
| 107 |
-
)
|
| 108 |
-
else:
|
| 109 |
-
st.warning("Please select a department and role to generate the job description.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from docx import Document
|
| 3 |
+
import requests
|
| 4 |
import io
|
|
|
|
| 5 |
|
| 6 |
+
# Hugging Face API details
|
| 7 |
+
API_URL = "https://api-inference.huggingface.co/models/google/flan-t5-large"
|
| 8 |
+
HEADERS = {"Authorization": "Bearer TNovMWSMvIBjCPmyJSkBBXsYQAwWutoXbN"}
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
# Department and Role mapping
|
| 11 |
+
DEPARTMENT_ROLES = {
|
| 12 |
+
"Construction": [
|
| 13 |
+
"Site Engineer",
|
| 14 |
+
"Project Manager",
|
| 15 |
+
"Construction Worker",
|
| 16 |
+
"Safety Officer",
|
| 17 |
+
"Quantity Surveyor"
|
| 18 |
+
],
|
| 19 |
+
"Design": [
|
| 20 |
+
"Architect",
|
| 21 |
+
"Interior Designer",
|
| 22 |
+
"CAD Technician",
|
| 23 |
+
"Structural Engineer"
|
| 24 |
+
],
|
| 25 |
+
"Management": [
|
| 26 |
+
"Operations Manager",
|
| 27 |
+
"Site Supervisor",
|
| 28 |
+
"Contracts Manager",
|
| 29 |
+
"Planning Manager"
|
| 30 |
+
]
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
# Function to generate JD using Hugging Face model
|
| 34 |
+
def generate_jd_with_hf(department, role):
|
| 35 |
+
prompt = f"""
|
| 36 |
+
Create a detailed professional job description for a {role} in the {department} department of a construction company.
|
| 37 |
+
Include the following sections:
|
| 38 |
+
1. Job Summary
|
| 39 |
+
2. Key Responsibilities
|
| 40 |
+
3. Qualifications and Skills
|
| 41 |
+
4. Experience Requirements
|
| 42 |
+
5. Benefits and Perks
|
| 43 |
+
|
| 44 |
+
Make it professional and detailed, suitable for a construction company.
|
| 45 |
+
"""
|
| 46 |
+
|
| 47 |
+
payload = {
|
| 48 |
+
"inputs": prompt,
|
| 49 |
+
"parameters": {
|
| 50 |
+
"max_length": 1000,
|
| 51 |
+
"temperature": 0.7,
|
| 52 |
+
"do_sample": True
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
response = requests.post(API_URL, headers=HEADERS, json=payload)
|
| 57 |
+
if response.status_code == 200:
|
| 58 |
+
return response.json()[0]['generated_text']
|
| 59 |
+
else:
|
| 60 |
+
raise Exception(f"API Error: {response.status_code} - {response.text}")
|
| 61 |
+
|
| 62 |
+
# Function to create Word document
|
| 63 |
+
def create_word_document(role, content):
|
| 64 |
doc = Document()
|
|
|
|
|
|
|
| 65 |
|
| 66 |
+
# Add title
|
| 67 |
+
title = doc.add_heading(f"Job Description: {role}", 0)
|
| 68 |
+
title.alignment = 1 # Center alignment
|
|
|
|
| 69 |
|
| 70 |
+
# Add content
|
| 71 |
+
for line in content.split('\n'):
|
| 72 |
+
if line.strip().startswith(('1.', '2.', '3.', '4.', '5.')):
|
| 73 |
+
heading = doc.add_heading(line.strip(), level=1)
|
| 74 |
+
else:
|
| 75 |
+
para = doc.add_paragraph(line)
|
| 76 |
+
|
| 77 |
+
# Save to bytes buffer
|
| 78 |
+
buffer = io.BytesIO()
|
| 79 |
+
doc.save(buffer)
|
| 80 |
+
buffer.seek(0)
|
| 81 |
+
return buffer
|
| 82 |
|
| 83 |
+
# Streamlit UI
|
| 84 |
+
st.set_page_config(page_title="Construction JD Generator", layout="wide")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
+
st.title("🏗️ AI-Powered Job Description Generator")
|
| 87 |
+
st.subheader("Create professional job descriptions for your construction company")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
+
# Create two columns for department and role selection
|
| 90 |
+
col1, col2 = st.columns(2)
|
| 91 |
|
| 92 |
+
with col1:
|
| 93 |
+
department = st.selectbox(
|
| 94 |
+
"Select Department",
|
| 95 |
+
list(DEPARTMENT_ROLES.keys()),
|
| 96 |
+
index=0,
|
| 97 |
+
help="Choose the department for the position"
|
| 98 |
+
)
|
| 99 |
|
| 100 |
+
with col2:
|
| 101 |
+
role = st.selectbox(
|
| 102 |
+
"Select Role",
|
| 103 |
+
DEPARTMENT_ROLES[department],
|
| 104 |
+
index=0,
|
| 105 |
+
help="Choose the specific role"
|
| 106 |
+
)
|
| 107 |
|
| 108 |
+
# Generate JD button
|
| 109 |
+
if st.button("✨ Generate Job Description"):
|
| 110 |
+
with st.spinner("Generating professional job description using AI..."):
|
| 111 |
+
try:
|
| 112 |
+
# Generate JD content
|
| 113 |
+
jd_content = generate_jd_with_hf(department, role)
|
| 114 |
+
|
| 115 |
+
# Create Word document
|
| 116 |
+
doc_buffer = create_word_document(role, jd_content)
|
| 117 |
+
|
| 118 |
+
# Show preview
|
| 119 |
+
st.success("Job Description Generated Successfully!")
|
| 120 |
+
st.markdown("### Preview:")
|
| 121 |
+
st.markdown(jd_content)
|
| 122 |
+
|
| 123 |
+
# Download button
|
| 124 |
+
st.download_button(
|
| 125 |
+
label="📥 Download Job Description",
|
| 126 |
+
data=doc_buffer,
|
| 127 |
+
file_name=f"{role.replace(' ', '_')}_JD.docx",
|
| 128 |
+
mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
| 129 |
+
help="Download the job description in Word format"
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
except Exception as e:
|
| 133 |
+
st.error(f"Error generating job description: {str(e)}")
|
| 134 |
|
| 135 |
+
# Instructions
|
| 136 |
+
st.markdown("""
|
| 137 |
+
### Instructions:
|
| 138 |
+
1. Select the department from the first dropdown
|
| 139 |
+
2. Choose the specific role from the second dropdown
|
| 140 |
+
3. Click 'Generate Job Description'
|
| 141 |
+
4. Review the generated description
|
| 142 |
+
5. Download the Word document
|
| 143 |
+
""")
|
| 144 |
+
|
| 145 |
+
# Footer
|
| 146 |
+
st.markdown("---")
|
| 147 |
+
st.markdown("Built with ❤️ using Streamlit and Hugging Face")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|