File size: 3,315 Bytes
c402081
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# -*- coding: utf-8 -*-
"""dpm1

Automatically generated by Colaboratory.

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

#!pip install streamlit

#!pip install transformers

import streamlit as st
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline

model_name = "EleutherAI/gpt-neo-1.3B"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)
generator = pipeline('text-generation', model=model, tokenizer=tokenizer)

def generate_job_posting(position, job_type, skillset, company_name, work_experience, job_location, job_benefits, field, currency, currency_format, package, communication, notice_period, qualifications, responsibility):
    context = f"{company_name} is hiring a {position} for a {job_type} position in {job_location}. The ideal candidate will have at least {work_experience} years of experience in {field}, and should be proficient in {skillset}. The job responsibility includes:\n- {responsibility}\nWe offer a {package} package in currency format {currency_format}. The successful candidate will be expected to maintain excellent communication with clients and colleagues. The notice period for this role is {notice_period}, and applicants should have the following qualifications: {qualifications}."
    output = generator(context, max_length=240, do_sample=True, temperature=0.7, num_return_sequences=3)
    def score_output(output_text):
        sentences = output_text.split('.')
        avg_sentence_length = sum(len(s.strip()) for s in sentences) / len(sentences)
        return 1.0 / avg_sentence_length
    sorted_outputs = sorted(output, key=lambda x: score_output(x['generated_text']), reverse=True)
    best_output = sorted_outputs[0]
    output_text = best_output['generated_text'].replace('- job responsibility', f"\n\n- {responsibility}")
    paragraphs = output_text.split('\n\n')
    output_text = '\n\n'.join('\n' + p for p in paragraphs)
    return output_text

st.title("Job Posting Generator")

position = st.text_input("Enter Position for Job Posting:")
job_type = st.text_input("Enter Job Type:")
skillset = st.text_input("Enter Skillset:")
company_name = st.text_input("Enter Company Name:")
work_experience = st.text_input("Enter Required Work Experience (in years):")
job_location = st.text_input("Enter job Location:")
job_benefits = st.text_input("Enter job benefits:")
field = st.text_input("Enter job field:")
currency = st.text_input("Enter Currency:")
currency_format = st.text_input("Enter Currency Format:")
package = st.text_input("Enter Package:")
communication = st.text_input("Enter Communication:")
notice_period = st.text_input("Enter Notice Period:")
qualifications = st.text_input("Enter Qualifications:")
responsibility = st.text_area("Enter Job Responsibility:")

if st.button("Generate Job Posting"):
    try:
        output_text = generate_job_posting(position, job_type, skillset, company_name, work_experience, job_location, job_benefits, field, currency, currency_format, package, communication, notice_period, qualifications, responsibility)
        st.success(output_text)
    except ValueError as e:
        st.error(f"Error: {e}")
    except Exception as e:
        st.error(f"An error occurred: {e}")