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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
import streamlit as st
import json
from dotenv import load_dotenv

from langchain_core.prompts import ChatPromptTemplate
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_core.output_parsers import StrOutputParser

# ==========================================
# Load Environment Variables
# ==========================================

load_dotenv()

# ==========================================
# Streamlit Page Config
# ==========================================

st.set_page_config(
    page_title="AI Interview Assistant",
    page_icon="🎯",
    layout="wide"
)

# ==========================================
# Custom Styling
# ==========================================

page_bg = """

<style>



/* Main Background */

[data-testid="stAppViewContainer"] {

    background-image: url("https://images.unsplash.com/photo-1522202176988-66273c2fd55f");

    background-size: cover;

    background-position: center;

    background-repeat: no-repeat;

    background-attachment: fixed;

}



/* Transparent Header */

[data-testid="stHeader"] {

    background: rgba(0,0,0,0);

}



/* Sidebar */

[data-testid="stSidebar"] {

    background: rgba(255,255,255,0.08);

}



/* Text Area */

.stTextArea textarea {

    background-color: rgba(0,0,0,0.80);

    color: white;

    border: 2px solid #6C63FF;

    border-radius: 12px;

    font-size: 16px;

}



/* Select Box */

.stSelectbox div[data-baseweb="select"] {

    background-color: rgba(255,255,255,0.10);

    border-radius: 10px;

}



/* Buttons */

.stButton button {

    background: linear-gradient(90deg, #6C63FF, #8E2DE2);

    color: white;

    border: none;

    border-radius: 12px;

    height: 3.2em;

    width: 100%;

    font-size: 18px;

    font-weight: bold;

}



/* Headings */

h1, h2, h3, h4 {

    color: white !important;

}



/* Paragraph */

p, label {

    color: white !important;

    font-size: 18px;

}



/* Success Box */

.stAlert {

    border-radius: 12px;

}



/* Metric Cards */

[data-testid="metric-container"] {

    background-color: rgba(255,255,255,0.12);

    border-radius: 15px;

    padding: 15px;

    border: 1px solid rgba(255,255,255,0.2);

}



/* JSON Output */

.stJson {

    background-color: rgba(255,255,255,0.10);

    border-radius: 10px;

    padding: 10px;

}



</style>

"""

st.markdown(page_bg, unsafe_allow_html=True)

# ==========================================
# Title Section
# ==========================================

st.title("Smart Interview Preparation Assistant")

st.subheader("AI-Powered Interview Evaluation System")

st.write(
    "Generate interview questions and receive professional AI feedback instantly."
)

# ==========================================
# Interview Type
# ==========================================

role = st.selectbox(
    "Select Interview Type",
    ["HR", "Technical", "General"]
)

# ==========================================
# Gemini Model
# ==========================================

model = ChatGoogleGenerativeAI(
    model="gemini-2.5-flash",
    temperature=0.3
)

parser = StrOutputParser()

# ==========================================
# Question Prompt
# ==========================================

question_prompt = ChatPromptTemplate.from_messages([
    (
        "system",
        """

        You are an expert interviewer.



        Generate SHORT interview questions only.



        Rules:

        - Keep question under 20 words

        - Beginner friendly

        - No paragraph questions

        """
    ),
    (
        "human",
        "Generate one {role} interview question."
    )
])

question_chain = question_prompt | model | parser

# ==========================================
# Generate Question Button
# ==========================================

if st.button("Generate Interview Question"):

    try:

        with st.spinner("Generating question..."):

            response = question_chain.invoke({
                "role": role
            })

            st.session_state.question = response

    except Exception as e:

        st.error(f"Error: {e}")

# ==========================================
# Show Question
# ==========================================

if "question" in st.session_state:

    st.subheader("Interview Question")

    st.success(st.session_state.question)

    # ==========================================
    # User Answer
    # ==========================================

    answer = st.text_area(
        "✍️ Write Your Answer",
        height=200,
        placeholder="Example: OOP stands for Object-Oriented Programming..."
    )

    # ==========================================
    # Evaluation Prompt
    # ==========================================

    template = """

    You are an expert HR interviewer.



    Evaluate the candidate answer professionally.



    Return ONLY valid JSON.



    Expected JSON format:



    {{

        "question": "interview question",



        "candidate_answer": "user answer",



        "evaluation": {{

            "strengths": [

                "strength1",

                "strength2"

            ],



            "weaknesses": [

                "weakness1",

                "weakness2"

            ]

        }},



        "scores": {{

            "technical_knowledge": "8/10",

            "communication": "7/10",

            "confidence": "8/10",

            "overall": "8/10"

        }},



        "final_feedback": "professional feedback"

    }}

    """

    prompt = ChatPromptTemplate.from_messages([
        ("system", template),
        ("human", """

        Question:

        {question}



        Answer:

        {answer}

        """)
    ])

    evaluation_chain = prompt | model | parser

    # ==========================================
    # Evaluate Answer
    # ==========================================

    if st.button("Evaluate Answer"):

        if answer.strip():

            with st.spinner("Evaluating answer..."):

                try:

                    response = evaluation_chain.invoke({
                        "question": st.session_state.question,
                        "answer": answer
                    })

                    cleaned_response = (
                        response
                        .replace("```json", "")
                        .replace("```", "")
                        .strip()
                    )

                    data = json.loads(cleaned_response)

                    # ==========================================
                    # Display Results
                    # ==========================================

                    st.subheader("Question")
                    st.write(data.get("question", "N/A"))

                    st.subheader("Candidate Answer")
                    st.write(data.get("candidate_answer", "N/A"))

                    # ==========================================
                    # Strengths
                    # ==========================================

                    st.subheader("Strengths")

                    strengths = data.get(
                        "evaluation", {}
                    ).get("strengths", [])

                    for item in strengths:
                        st.write(f"• {item}")

                    # ==========================================
                    # Weaknesses
                    # ==========================================

                    st.subheader("Weaknesses")

                    weaknesses = data.get(
                        "evaluation", {}
                    ).get("weaknesses", [])

                    for item in weaknesses:
                        st.write(f"• {item}")

                    # ==========================================
                    # Scores
                    # ==========================================

                    st.subheader("Performance Scores")

                    scores = data.get("scores", {})

                    col1, col2 = st.columns(2)

                    with col1:

                        st.metric(
                            "Technical Knowledge",
                            scores.get(
                                "technical_knowledge",
                                "N/A"
                            )
                        )

                        st.metric(
                            "Communication",
                            scores.get(
                                "communication",
                                "N/A"
                            )
                        )

                    with col2:

                        st.metric(
                            "Confidence",
                            scores.get(
                                "confidence",
                                "N/A"
                            )
                        )

                        st.metric(
                            "Overall",
                            scores.get(
                                "overall",
                                "N/A"
                            )
                        )

                    # ==========================================
                    # Final Feedback
                    # ==========================================

                    st.subheader("Final Feedback")

                    st.write(
                        data.get(
                            "final_feedback",
                            "N/A"
                        )
                    )

                    # ==========================================
                    # Full JSON Output
                    # ==========================================

                    st.subheader("Full JSON Output")

                    st.json(data)

                except json.JSONDecodeError:

                    st.error("Invalid JSON received from Gemini.")

                    st.code(response)

                except Exception as e:

                    st.error(f"Error: {e}")

        else:

            st.warning("Please enter your answer.")

# ==========================================
# Footer
# ==========================================

st.markdown("---")

st.write("Built with Streamlit + Gemini AI + LangChain")