Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,71 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
|
|
|
10 |
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
|
|
|
18 |
|
19 |
-
st.markdown(number3)
|
|
|
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 |
|
|