Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,34 +1,70 @@
|
|
1 |
-
# -*- coding: utf-8 -*-
|
2 |
-
"""
|
3 |
-
Fancy Addition Calculator with Sidebar and Animations
|
4 |
-
Created on Sat Jul 12 10:49:24 2025
|
5 |
-
@author: somil
|
6 |
-
"""
|
7 |
-
|
8 |
import streamlit as st
|
9 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
#
|
12 |
-
st.
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
18 |
|
19 |
-
#
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
26 |
|
27 |
-
|
28 |
-
|
|
|
29 |
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
-
|
33 |
-
st.
|
34 |
-
st.markdown("<p style='text-align: center;'>π Hope you have a <b>nice</b> day! π</p>", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
# It's good practice to load these from a .env file, but for demonstration purposes, we are setting them directly
|
15 |
+
os.environ["OPENAI_API_KEY"] = "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" # Replace with your actual OpenAI API key
|
16 |
+
|
17 |
+
|
18 |
+
# User Inputs
|
19 |
+
company = st.text_input("Company Name")
|
20 |
+
profile = st.text_input("Profile Name")
|
21 |
+
jd = st.text_area("Job Description")
|
22 |
+
resume_file = st.file_uploader("Upload Resume (Optional)", type=["pdf"])
|
23 |
+
|
24 |
+
# Extract text from PDF if resume is uploaded
|
25 |
+
resume_text = ""
|
26 |
+
if resume_file is not None:
|
27 |
+
pdf = PdfReader(resume_file)
|
28 |
+
for page in pdf.pages:
|
29 |
+
resume_text += page.extract_text()
|
30 |
|
31 |
+
# Submit button
|
32 |
+
submit = st.button("Generate Interview Questions")
|
33 |
|
34 |
+
if submit:
|
35 |
+
if not company or not profile or not jd:
|
36 |
+
st.warning("Please fill in all mandatory fields.")
|
37 |
+
else:
|
38 |
+
# Set up OpenAI LLM
|
39 |
+
llm = ChatOpenAI(temperature=0.7, model_name="gpt-4")
|
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.
|
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.write(response)
|
|