File size: 3,090 Bytes
63ab04f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from langchain.llms import OpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from langchain.agents import initialize_agent
from langchain.chat_models import ChatOpenAI
import json
import os

openai_api_key = os.environ.get('OPENAI_API_KEY')
# Initialize your OpenAI language model here
llm = OpenAI(temperature=0.6, openai_api_key=openai_api_key, model_name="gpt-3.5-turbo-16k")

def generate_questionnaire(title, description, llm):

    question_template = """You are a member of the hiring committee of your company. Your task is to develop screening questions for each candidate, considering different levels of importance or significance assigned to the job description.
                                   Here are the Details:
                                   Job title: {title}
                                   Job description: {description}

                                Your Response should follow the following format:
                                 "id":1, "Question":"Your Question will go here"\n,
                                 "id":2, "Question":"Your Question will go here"\n,
                                 "id":3, "Question":"Your Question will go here"\n
                                 There should be at least 10 questions. Do output only the questions but in text."""
            
    screen_template = PromptTemplate(input_variables=["title", "description"], template=question_template)
    questions_chain = LLMChain(llm=llm, prompt=screen_template)
    
    response = questions_chain.run({"title": title, "description": description})
    
    return response

# Streamlit App
def main():
    st.title("Candidate Screening Questionnaire Generator")
    
    job_title = st.text_input("Enter Job Title:")
    job_description = st.text_area("Enter Job Description:")
    
    if st.button("Generate Questionnaire"):
        if job_title and job_description:
            questionnaire = generate_questionnaire(job_title, job_description, llm)
            
            st.write("Generated Questions:")
            st.write(questionnaire)
            
            question_strings = questionnaire.split('"id":')
            questions = []
            for q_string in question_strings[1:]:
                question_id, question_text = q_string.split(', "Question":')
                question = {
                    "id": int(question_id.strip()),
                    "Question": question_text.strip()[1:-1]  # Removing the surrounding quotes
                    }
                questions.append(question)
            questionnaire_json = json.dumps(questions, indent=4)
            
            # Make the questionnaire_json downloadable
            st.download_button(
                label="Download JSON Questionnaire",
                data=questionnaire_json,
                file_name="questionnaire.json",
                mime="application/json"
            )

        else:
            st.warning("Please provide Job Title and Job Description.")

if __name__ == "__main__":
    main()