File size: 17,811 Bytes
adeee78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
261737d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
adeee78
 
 
 
 
 
 
261737d
adeee78
 
261737d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
adeee78
 
 
261737d
adeee78
 
 
 
 
 
261737d
adeee78
261737d
 
 
adeee78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
261737d
 
 
adeee78
 
 
 
 
 
 
 
 
 
 
 
 
 
261737d
adeee78
 
 
 
261737d
adeee78
 
 
261737d
 
adeee78
 
261737d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
adeee78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
261737d
adeee78
261737d
adeee78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
261737d
adeee78
 
 
 
 
261737d
 
 
 
adeee78
261737d
 
 
 
 
 
 
adeee78
 
 
 
 
 
 
 
261737d
adeee78
 
 
261737d
 
 
 
 
adeee78
 
 
 
 
 
 
 
261737d
adeee78
 
 
261737d
 
 
 
 
 
 
 
adeee78
261737d
adeee78
 
 
 
 
 
261737d
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
# -*- coding: utf-8 -*-
"""Feedalytics - Job Description.ipynb

Automatically generated by Colab.

Original file is located at
    https://colab.research.google.com/drive/1SlxUPjexW8FCdt108of4q8f4MOtn7BpP
"""

# Final Code

import gradio as gr
import openai
import os

# User credentials
USER_CREDENTIALS = {"admin": "password123"}  # Replace with desired username/password pairs

# Ensure OpenAI API Key is set
openai_api_key = os.getenv("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")  # Replace with your key if running locally

# -----------------------------
# Predefined Company Profiles
# -----------------------------
COMPANIES = {
    "Jaffer Business Systems (JBS)": {
        "description": "Jaffer Business Systems (JBS), founded in 1982 as a division of Jaffer Brothers, has been at the forefront of technology solutions for over four decades. Today, JBS stands as one of Pakistan’s leading IT companies, empowering organizations through innovation, digital transformation, and people-centric technology. Guided by our vision of “Harnessing Innovation & Empowering Generations,” we continue to build solutions that shape a smarter and more connected future. JBS delivers comprehensive solutions from IT infrastructure and enterprise software to advanced applications and consulting services that drive business growth and efficiency. JBS includes a diverse portfolio of subsidiaries such as Hysab Kytab, Energy & Automation Pakistan, Blutech Consulting, and Imparé, reflecting our expanding global footprint and commitment to technological excellence. Through its specialized business units — JBS Arabia, JBS Infrastructure Solutions, JBS Customer Service & JBS Americas and Europe. JBS continues to deliver exceptional value across regions and industries. ",
        "culture": "At JBS, we believe in creating impact through technology, collaboration, and continuous learning driving progress for our clients, our people, and the communities we serve."
    },
    "Hysab Kytab": {
        "description": "Hysab Kytab, a company of Jaffer Business Systems (JBS), is a leading fintech solutions provider dedicated to transforming the way individuals and businesses manage money. With a mission to promote financial wellness and inclusion, Hysab Kytab develops innovative digital financial products that empower users to make smarter financial decisions through data, insights, and intuitive technology. From personal finance management to enterprise financial platforms, Hysab Kytab focuses on creating user-centric solutions that simplify financial planning and enable a more informed, secure, and connected digital economy.",
        "culture": "Open, data-driven, and inclusive with a strong emphasis on innovation and user focus."
    },
    "Energy and Automation Pakistan Pvt. Ltd (ENA Pakistan)": {
        "description": "Energy and Automation Pakistan Pvt. Ltd (ENA Pakistan), a company of Jaffer Business Systems (JBS), began as an SME in the power solutions and backup domain with a vision to address challenges caused by frequent power outages and interruptions. Through dedication, innovation, and customer-centric service, ENA quickly gained trust and recognition in the market. Today, ENA is an enthusiastic and forward-looking team committed to becoming the first choice for IoT and power solutions in Pakistan. The company continues to evolve by integrating cutting-edge technology and automation, delivering reliable, intelligent, and energy-efficient solutions that empower businesses and communities.",
        "culture": "Empowering, growth-oriented, and diverse, with a focus on collaboration and inclusion."
    },
    "JBS Americas & Europe": {
        "description": "JBS Americas & Europe, a business unit of Jaffer Business Systems (JBS), is a digital transformation services provider helping businesses build smarter software solutions, scale with top talent, and harness the full potential of AI. With a strong focus on innovation and collaboration, JBS Americas & Europe partners with clients to turn their most complex challenges into sustainable growth opportunities. From enterprise-grade software development to strategic technology consulting, the company empowers organizations to accelerate their digital journey and achieve measurable results.",
        "culture": "Agile, customer-centric, and innovative with a focus on continuous learning."
    },
    "Imparé": {
        "description": "a Silicon Valley–based startup and a subsidiary of Jaffer Business Systems (JBS), marks JBS’s first international investment and a significant step toward advancing Pakistan’s presence in the global semiconductor industry. With this milestone, JBS has positioned itself at the forefront of chip verification services in the country. The company is building a verification hub in Pakistan, designed to support leading semiconductor firms worldwide while nurturing local engineering talent. Through world-class training and real-world project exposure, Imparé empowers Pakistani engineers to collaborate with global technology leaders — bridging innovation, expertise, and opportunity across borders.",
        "culture": "Open, data-driven, and inclusive with a strong emphasis on innovation and user focus"
    },
    "JBS Arabia (JA)": {
        "description": "JBS Arabia (JA), a business unit of Jaffer Business Systems (JBS), delivers end-to-end technological solutions — from ideation to execution — enabling clients to innovate, optimize, and outperform in an ever-evolving business landscape.With a strong legacy of over 25 years and a solid presence across the region, JBS Arabia’s team of expert consultants ensures that clients receive focused support from some of the brightest minds in the industry. The company helps enterprises drive innovation and achieve sustainable performance gains through advanced tools, strategic consulting, and implementation excellence. From consultation and solution design to deployment and training, JBS Arabia partners with leading organizations worldwide to deliver state-of-the-art technology solutions — continuously expanding its reach and impact both locally and internationally.",
        "culture": "Agile, customer-centric, and innovative with a focus on continuous learning."
    },
    "JBS Customer Service (JCS)": {
        "description": "JBS Customer Service (JCS), a business unit of Jaffer Business Systems (JBS), brings over 37 years of experience in delivering exceptional technology services and support. JCS strengthens JBS’s hardware and software offerings through comprehensive project management, service level agreements (SLAs), and managed services that ensure seamless business continuity. With the most extensive countrywide support infrastructure in Pakistan, JBS provides a wide range of customer services — including mission-critical support, 24/7 assistance, warranty management, help desk operations, resident engineer services, hardware and software deployment, and complete IT outsourcing. Backed by a well-managed inventory, strong processes, and highly skilled professionals, JBS Customer Service continues to deliver responsive, reliable, and high-quality support — enabling clients to achieve their mission-critical business goals with confidence.",
        "culture": "Agile, customer-centric, and innovative with a focus on continuous learning."
    },
    "Jaffer Sales and Services (JSS)": {
        "description": "Jaffer Sales and Services (JSS), a business unit of Jaffer Business Systems (JBS), is dedicated to delivering the latest technologies and solutions through a talented team of specialists who leverage the most advanced tools and best practices. It provides a comprehensive range of ICT products and services, including enterprise solutions, networking, virtualization, software, and personal systems. With over three decades of experience, it has empowered businesses to transform their technology investments into measurable performance gains, operational efficiency, and long-term value.",
        "culture": "Agile, customer-centric, and innovative with a focus on continuous learning."
    }
}

# -----------------------------
# Generate Job Description
# -----------------------------
def generate_job_description(
    job_title, industry, employment_type, work_mode, location, salary_range,
    primary_responsibilities, optional_responsibilities, report_to, team_collaboration,
    min_education, experience_years, hard_skills, soft_skills, certifications,
    alternative_experience, transferable_skills, diversity_statement,
    company_name, company_description, company_culture, benefits,
    application_process, recruiter_contact,
    tone, detail_level, bias_free_language, must_have_keyword
):
    try:
        # Validation
        required_fields = {
            "Job Title": job_title,
            "Industry": industry,
            "Employment Type": employment_type,
            "Work Mode": work_mode,
            "Location": location,
            "Primary Responsibilities": primary_responsibilities,
            "Minimum Education": min_education,
            "Experience Years": experience_years,
            "Hard Skills": hard_skills,
            "Company Name": company_name,
            "Application Process": application_process,
            "Recruiter Contact": recruiter_contact,
            "Must-Have Keyword": must_have_keyword
        }
        errors = [f"{field} is required." for field, value in required_fields.items() if not value]
        if errors:
            return "", "\n".join(errors)

        # Clean inputs
        primary_responsibilities = "\n- ".join(str(primary_responsibilities).split(","))
        optional_responsibilities = "\n- ".join(str(optional_responsibilities).split(","))
        hard_skills = ", ".join(str(hard_skills).split(","))
        soft_skills = ", ".join(str(soft_skills).split(","))
        benefits = "\n- ".join(str(benefits).split(","))

        # AI prompt
        prompt = f"""
        Generate a comprehensive and inclusive job description.

        Include the specific keyword or skill: "{must_have_keyword}".

        Job Title: {job_title}
        Industry: {industry}
        Employment Type: {employment_type}
        Work Mode: {work_mode}
        Location: {location}
        Salary Range: {salary_range if salary_range else 'Not Specified'}

        Responsibilities:
        - {primary_responsibilities}

        Preferred but not required:
        - {optional_responsibilities}

        Qualifications:
        - Education: {min_education}
        - Experience: {experience_years}+ years preferred
        - Skills: {hard_skills}
        - Soft Skills: {soft_skills}
        - Certifications: {certifications if certifications else 'Not Required'}

        Company: {company_name}
        Description: {company_description}
        Culture: {company_culture}

        Benefits:
        - {benefits}

        Application Process: {application_process}
        Recruiter Contact: {recruiter_contact}

        Ensure the language is {tone.lower()} and {detail_level.lower()}.
        Use bias-free language: {'Yes' if bias_free_language else 'No'}.
        """

        response = openai.ChatCompletion.create(
            model="gpt-3.5-turbo-16k",
            messages=[
                {"role": "system", "content": "You are an expert in creating inclusive and flexible job descriptions."},
                {"role": "user", "content": prompt}
            ],
            temperature=0.7
        )

        return response["choices"][0]["message"]["content"].strip(), ""

    except Exception as e:
        import traceback
        print(traceback.format_exc())
        return "", f"Unexpected Error: {str(e)}"

# -----------------------------
# Prepare Word File
# -----------------------------
def prepare_download_docx(job_description, job_title="JobDescription"):
    if not job_description:
        return None
    file_path = f"{job_title}_JobDescription.docx"
    doc = Document()
    doc.add_heading("Generated Job Description", level=1)
    doc.add_paragraph(job_description)
    doc.save(file_path)
    return file_path

# -----------------------------
# Autofill Company Info
# -----------------------------
def autofill_company(selected_company):
    if selected_company in COMPANIES:
        info = COMPANIES[selected_company]
        return selected_company, info["description"], info["culture"]
    return "", "", ""

# -----------------------------
# Gradio UI
# -----------------------------
with gr.Blocks(css="""
#company-logo img {
    width: 150px;
    height: auto;
    margin: 0 auto;
    display: block;
}
""") as app:

    username = gr.Textbox(label="Username")
    password = gr.Textbox(label="Password", type="password")
    login_button = gr.Button("Login")
    auth_status = gr.Textbox(label="Login Status", interactive=False)

    with gr.Group(visible=False) as app_interface:
        gr.Image(
            value="https://drive.google.com/uc?id=1tgTSBVCm6gvg6EGEsgHsjsqyiGefxqHP",
            show_label=False,
            elem_id="company-logo"
        )
        gr.Markdown("## 🧠 AI-Powered Job Description Generator")

        # Job & company info
        with gr.Row():
            job_title = gr.Textbox(label="Job Title")
            industry = gr.Textbox(label="Industry")
            employment_type = gr.Dropdown(["Full-time", "Part-time", "Contract", "Internship"], label="Employment Type")
        with gr.Row():
            work_mode = gr.Dropdown(["Remote", "Hybrid", "On-site"], label="Work Mode")
            location = gr.Textbox(label="Location")
            salary_range = gr.Textbox(label="Salary Range (Optional)")

        primary_responsibilities = gr.Textbox(label="Primary Responsibilities (Comma Separated)")
        optional_responsibilities = gr.Textbox(label="Optional Responsibilities (Comma Separated)")
        report_to = gr.Textbox(label="Reports To")
        team_collaboration = gr.Textbox(label="Team Collaboration")

        with gr.Row():
            min_education = gr.Dropdown(["High School", "Associate's Degree", "Bachelor's", "Master's", "PhD"], label="Minimum Education")
            experience_years = gr.Slider(0, 20, step=0.5, label="Years of Experience")

        hard_skills = gr.Textbox(label="Hard Skills (Comma Separated)")
        soft_skills = gr.Textbox(label="Soft Skills (Comma Separated)")
        certifications = gr.Textbox(label="Certifications (Optional)")
        must_have_keyword = gr.Textbox(label="Must-Have Keyword or Skill (Required)")

        alternative_experience = gr.Checkbox(label="Consider Alternative Experience")
        transferable_skills = gr.Checkbox(label="Consider Transferable Skills")
        diversity_statement = gr.Textbox(label="Diversity & Inclusion Statement (Optional)")

        company_dropdown = gr.Dropdown(list(COMPANIES.keys()), label="Select Company (Optional)")
        company_name = gr.Textbox(label="Company Name (Editable)")
        company_description = gr.Textbox(label="Company Description (Editable)", lines=3)
        company_culture = gr.Textbox(label="Company Culture & Values (Editable)", lines=3)

        company_dropdown.change(
            autofill_company,
            inputs=[company_dropdown],
            outputs=[company_name, company_description, company_culture]
        )

        benefits = gr.Textbox(label="Benefits & Perks (Comma Separated)")
        application_process = gr.Textbox(label="Application Process Details")
        recruiter_contact = gr.Textbox(label="Recruiter Contact Information")

        with gr.Row():
            tone = gr.Dropdown(["Formal", "Casual"], label="Tone of Job Description")
            detail_level = gr.Dropdown(["Concise", "Detailed"], label="Detail Level")
            bias_free_language = gr.Checkbox(label="Use Bias-Free Language")

        # Output + Download
        output = gr.Textbox(label="Generated Job Description", lines=15)
        error_output = gr.Textbox(label="Error Messages", lines=5, interactive=False)

        generate_button = gr.Button("Generate Job Description")
        prepare_download_button = gr.Button("Prepare Download")
        download_file = gr.File(label="Download as Word File (.docx)")

        # Generate job description
        generate_button.click(
            generate_job_description,
            inputs=[job_title, industry, employment_type, work_mode, location, salary_range,
                    primary_responsibilities, optional_responsibilities, report_to, team_collaboration,
                    min_education, experience_years, hard_skills, soft_skills, certifications,
                    alternative_experience, transferable_skills, diversity_statement,
                    company_name, company_description, company_culture, benefits,
                    application_process, recruiter_contact,
                    tone, detail_level, bias_free_language, must_have_keyword],
            outputs=[output, error_output]
        )

        # Prepare Word file for download
        prepare_download_button.click(
            prepare_download_docx,
            inputs=[output, job_title],
            outputs=[download_file]
        )

    # Login logic
    def authenticate(username_val, password_val):
        if username_val in USER_CREDENTIALS and password_val == USER_CREDENTIALS[username_val]:
            return gr.update(visible=True), "Login Successful"
        else:
            return gr.update(visible=False), "Login Failed"

    login_button.click(authenticate, inputs=[username, password], outputs=[app_interface, auth_status])

app.launch(share=True, debug=True)