Spaces:
Sleeping
Sleeping
Jeet Paul commited on
Commit ·
63ab04f
1
Parent(s): b5b43f7
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from langchain.llms import OpenAI
|
| 3 |
+
from langchain.prompts import PromptTemplate
|
| 4 |
+
from langchain.chains import LLMChain
|
| 5 |
+
from langchain.agents import initialize_agent
|
| 6 |
+
from langchain.chat_models import ChatOpenAI
|
| 7 |
+
import json
|
| 8 |
+
import os
|
| 9 |
+
|
| 10 |
+
openai_api_key = os.environ.get('OPENAI_API_KEY')
|
| 11 |
+
# Initialize your OpenAI language model here
|
| 12 |
+
llm = OpenAI(temperature=0.6, openai_api_key=openai_api_key, model_name="gpt-3.5-turbo-16k")
|
| 13 |
+
|
| 14 |
+
def generate_questionnaire(title, description, llm):
|
| 15 |
+
|
| 16 |
+
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.
|
| 17 |
+
Here are the Details:
|
| 18 |
+
Job title: {title}
|
| 19 |
+
Job description: {description}
|
| 20 |
+
|
| 21 |
+
Your Response should follow the following format:
|
| 22 |
+
"id":1, "Question":"Your Question will go here"\n,
|
| 23 |
+
"id":2, "Question":"Your Question will go here"\n,
|
| 24 |
+
"id":3, "Question":"Your Question will go here"\n
|
| 25 |
+
There should be at least 10 questions. Do output only the questions but in text."""
|
| 26 |
+
|
| 27 |
+
screen_template = PromptTemplate(input_variables=["title", "description"], template=question_template)
|
| 28 |
+
questions_chain = LLMChain(llm=llm, prompt=screen_template)
|
| 29 |
+
|
| 30 |
+
response = questions_chain.run({"title": title, "description": description})
|
| 31 |
+
|
| 32 |
+
return response
|
| 33 |
+
|
| 34 |
+
# Streamlit App
|
| 35 |
+
def main():
|
| 36 |
+
st.title("Candidate Screening Questionnaire Generator")
|
| 37 |
+
|
| 38 |
+
job_title = st.text_input("Enter Job Title:")
|
| 39 |
+
job_description = st.text_area("Enter Job Description:")
|
| 40 |
+
|
| 41 |
+
if st.button("Generate Questionnaire"):
|
| 42 |
+
if job_title and job_description:
|
| 43 |
+
questionnaire = generate_questionnaire(job_title, job_description, llm)
|
| 44 |
+
|
| 45 |
+
st.write("Generated Questions:")
|
| 46 |
+
st.write(questionnaire)
|
| 47 |
+
|
| 48 |
+
question_strings = questionnaire.split('"id":')
|
| 49 |
+
questions = []
|
| 50 |
+
for q_string in question_strings[1:]:
|
| 51 |
+
question_id, question_text = q_string.split(', "Question":')
|
| 52 |
+
question = {
|
| 53 |
+
"id": int(question_id.strip()),
|
| 54 |
+
"Question": question_text.strip()[1:-1] # Removing the surrounding quotes
|
| 55 |
+
}
|
| 56 |
+
questions.append(question)
|
| 57 |
+
questionnaire_json = json.dumps(questions, indent=4)
|
| 58 |
+
|
| 59 |
+
# Make the questionnaire_json downloadable
|
| 60 |
+
st.download_button(
|
| 61 |
+
label="Download JSON Questionnaire",
|
| 62 |
+
data=questionnaire_json,
|
| 63 |
+
file_name="questionnaire.json",
|
| 64 |
+
mime="application/json"
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
else:
|
| 68 |
+
st.warning("Please provide Job Title and Job Description.")
|
| 69 |
+
|
| 70 |
+
if __name__ == "__main__":
|
| 71 |
+
main()
|