YOUYOGITA commited on
Commit
a249ddd
Β·
verified Β·
1 Parent(s): 74fbb57

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -42
app.py CHANGED
@@ -1,71 +1,69 @@
1
  import streamlit as st
2
  from langchain.chat_models import ChatOpenAI
3
- from langchain.prompts import PromptTemplate
 
4
  from langchain.chains import LLMChain
 
5
  from PyPDF2 import PdfReader
6
  import os
7
 
8
  # Streamlit UI setup
9
  st.set_page_config(page_title="AI Job Interview Prep Tool")
10
- st.title("πŸ€– AI-Powered Job Interview Preparation")
11
 
12
- # Secure input for OpenAI API Key
13
  openai_key = st.text_input("πŸ” Enter your OpenAI API Key", type="password")
 
 
 
 
 
14
 
15
  # User Inputs
16
- company = st.text_input("🏒 Company Name")
17
- profile = st.text_input("πŸ’Ό Profile Name")
18
- jd = st.text_area("πŸ“„ Job Description")
19
- resume_file = st.file_uploader("πŸ“Ž Upload Resume (Optional)", type=["pdf"])
20
 
21
- # Extract text from PDF if resume is uploaded
22
  resume_text = ""
23
  if resume_file is not None:
24
- pdf = PdfReader(resume_file)
25
- for page in pdf.pages:
26
  resume_text += page.extract_text() or ""
27
 
28
- # Submit button
29
- submit = st.button("πŸš€ Generate Interview Questions")
30
-
31
- if submit:
32
- if not openai_key or not company or not profile or not jd:
33
- st.warning("Please fill in all required fields including the OpenAI API Key.")
34
- else:
35
- # Set environment variable for OpenAI
36
- os.environ["OPENAI_API_KEY"] = openai_key
37
-
38
- # Set up OpenAI LLM
39
- llm = ChatOpenAI(temperature=0.7, model_name="gpt-4", openai_api_key=openai_key)
40
 
41
- # Prompt Template
42
- base_prompt = PromptTemplate(
43
- input_variables=["company", "profile", "jd", "resume"],
44
- template="""
45
- You are an expert HR and Technical Interviewer.
46
- Given the following details:
47
  Company: {company}
48
  Profile: {profile}
49
  Job Description: {jd}
50
- Resume (if provided): {resume}
51
 
52
- Generate a structured set of interview questions:
53
- - Round 1: Technical Interview (7-10 questions including 2 hands-on tasks)
54
- - Round 2: Technical + Case Study (7-10 questions including at least 1 scenario or case-study based question)
55
- - Round 3: Business and HR Round (7-10 questions focused on communication, decision making, and company alignment)
56
-
57
- Present the questions grouped by round in clear bullet format using Markdown.
58
  """
59
- )
 
 
 
60
 
61
- chain = LLMChain(llm=llm, prompt=base_prompt)
 
62
  response = chain.run({
63
  "company": company,
64
  "profile": profile,
65
  "jd": jd,
66
- "resume": resume_text or "Not Provided"
67
  })
68
-
69
- st.subheader("πŸ“Œ Suggested Interview Questions")
70
- st.markdown(response)
71
-
 
1
  import streamlit as st
2
  from langchain.chat_models import ChatOpenAI
3
+ from langchain.prompts import ChatPromptTemplate
4
+ from langchain.schema.runnable import RunnableLambda
5
  from langchain.chains import LLMChain
6
+ from langchain.prompts import PromptTemplate
7
  from PyPDF2 import PdfReader
8
  import os
9
 
10
  # Streamlit UI setup
11
  st.set_page_config(page_title="AI Job Interview Prep Tool")
12
+ st.title("AI-Powered Job Interview Preparation")
13
 
14
+ # OpenAI API Key input
15
  openai_key = st.text_input("πŸ” Enter your OpenAI API Key", type="password")
16
+ if not openai_key:
17
+ st.warning("Please enter your OpenAI API Key to continue.")
18
+ st.stop()
19
+
20
+ os.environ["OPENAI_API_KEY"] = openai_key
21
 
22
  # User Inputs
23
+ company = st.text_input("Company Name")
24
+ profile = st.text_input("Profile Name")
25
+ jd = st.text_area("Job Description")
26
+ resume_file = st.file_uploader("Upload Resume (Optional)", type=["pdf"])
27
 
 
28
  resume_text = ""
29
  if resume_file is not None:
30
+ pdf_reader = PdfReader(resume_file)
31
+ for page in pdf_reader.pages:
32
  resume_text += page.extract_text() or ""
33
 
34
+ # Prompt Template
35
+ template = PromptTemplate(
36
+ input_variables=["company", "profile", "jd", "resume"],
37
+ template="""
38
+ You are an AI interview coach.
39
+ Generate:
40
+ - 2 technical rounds with 7-10 questions each
41
+ - Each technical round should have:
42
+ - Conceptual questions
43
+ - 2-3 hands-on tasks (code-oriented)
44
+ - 1 case-study type question
45
+ - 1 business + HR round with 7-10 questions
46
 
47
+ Base the questions on the job description, company, profile and resume.
 
 
 
 
 
48
  Company: {company}
49
  Profile: {profile}
50
  Job Description: {jd}
51
+ Resume (optional): {resume}
52
 
53
+ Provide questions clearly labeled under each round.
 
 
 
 
 
54
  """
55
+ )
56
+
57
+ llm = ChatOpenAI(temperature=0.7)
58
+ chain = LLMChain(llm=llm, prompt=template)
59
 
60
+ if st.button("Generate Interview Rounds"):
61
+ with st.spinner("Generating questions..."):
62
  response = chain.run({
63
  "company": company,
64
  "profile": profile,
65
  "jd": jd,
66
+ "resume": resume_text,
67
  })
68
+ st.subheader("πŸ“‹ Interview Questions")
69
+ st.write(response)