Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +46 -31
src/streamlit_app.py
CHANGED
|
@@ -277,40 +277,55 @@ if st.session_state.stage == 'start':
|
|
| 277 |
uploaded_file = st.file_uploader("Upload your Resume (PDF)", type=["pdf"])
|
| 278 |
|
| 279 |
if uploaded_file:
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
st.warning("No AI-generated questions returned; using fallback questions.")
|
| 291 |
-
st.session_state.questions = generate_questions_from_resume(resume_text, None)
|
| 292 |
-
|
| 293 |
-
# 2. Get AI Introduction
|
| 294 |
-
intro_output = get_introduction(intro_model)
|
| 295 |
-
st.session_state.current_question = getattr(intro_output, 'question', "Can you introduce yourself?")
|
| 296 |
-
|
| 297 |
-
# 3. Move to next stage and display intro
|
| 298 |
-
st.session_state.stage = 'awaiting_intro'
|
| 299 |
-
|
| 300 |
-
# --- MODIFIED: Display text directly ---
|
| 301 |
-
text_to_speech_and_display(getattr(intro_output, 'intro', "Hello, I'm Interviewer.AI. Please introduce yourself."))
|
| 302 |
-
text_to_speech_and_display(getattr(intro_output, 'question', "Can you introduce yourself?"))
|
| 303 |
-
|
| 304 |
-
st.rerun()
|
| 305 |
-
except Exception as e:
|
| 306 |
-
st.error(f"An error occurred while processing the resume. Using fallback behaviour. Error: {e}")
|
| 307 |
-
fallback_qs = ["Tell me about your most significant project.", "Describe a challenging bug you fixed.", "How do you design for scalability?", "Which technologies are you most comfortable with?"]
|
| 308 |
-
st.session_state.questions = fallback_qs
|
| 309 |
-
st.session_state.stage = 'asking_question'
|
| 310 |
st.rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 311 |
|
| 312 |
# --- Main Interview Area (Stages > 0) ---
|
| 313 |
-
if st.session_state.stage
|
| 314 |
|
| 315 |
# --- Chat History Display ---
|
| 316 |
st.subheader("Interview Transcript")
|
|
|
|
| 277 |
uploaded_file = st.file_uploader("Upload your Resume (PDF)", type=["pdf"])
|
| 278 |
|
| 279 |
if uploaded_file:
|
| 280 |
+
try:
|
| 281 |
+
# 1. ONLY read the file and save the text
|
| 282 |
+
resume_text = read_resume(uploaded_file)
|
| 283 |
+
if not resume_text:
|
| 284 |
+
st.error("Could not extract text from the resume. Please try another file.")
|
| 285 |
+
st.session_state.stage = 'start'
|
| 286 |
+
else:
|
| 287 |
+
# 2. Save text to session state and move to a NEW stage
|
| 288 |
+
st.session_state.resume_text = resume_text
|
| 289 |
+
st.session_state.stage = 'processing_resume' # <-- NEW STAGE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
st.rerun()
|
| 291 |
+
except Exception as e:
|
| 292 |
+
st.error(f"Error reading PDF: {e}")
|
| 293 |
+
st.session_state.stage = 'start'
|
| 294 |
+
|
| 295 |
+
# --- NEW STAGE 0.5: Process Resume (runs *after* file upload) ---
|
| 296 |
+
elif st.session_state.stage == 'processing_resume':
|
| 297 |
+
with st.spinner("Analyzing your resume... This may take a moment."):
|
| 298 |
+
try:
|
| 299 |
+
resume_text = st.session_state.resume_text
|
| 300 |
+
|
| 301 |
+
# 1. Generate Questions
|
| 302 |
+
st.session_state.questions = generate_questions_from_resume(resume_text, gen_q_model)
|
| 303 |
+
if not st.session_state.questions:
|
| 304 |
+
st.warning("No AI-generated questions returned; using fallback questions.")
|
| 305 |
+
st.session_state.questions = generate_questions_from_resume(resume_text, None)
|
| 306 |
+
|
| 307 |
+
# 2. Get AI Introduction
|
| 308 |
+
intro_output = get_introduction(intro_model)
|
| 309 |
+
st.session_state.current_question = getattr(intro_output, 'question', "Can you introduce yourself?")
|
| 310 |
+
|
| 311 |
+
# 3. Move to next stage and display intro
|
| 312 |
+
st.session_state.stage = 'awaiting_intro'
|
| 313 |
+
|
| 314 |
+
text_to_speech_and_display(getattr(intro_output, 'intro', "Hello, I'm Interviewer.AI. Please introduce yourself."))
|
| 315 |
+
text_to_speech_and_display(getattr(intro_output, 'question', "Can you introduce yourself?"))
|
| 316 |
+
|
| 317 |
+
# Clean up the resume text from session state
|
| 318 |
+
del st.session_state.resume_text
|
| 319 |
+
st.rerun()
|
| 320 |
+
|
| 321 |
+
except Exception as e:
|
| 322 |
+
# NOW we will catch the REAL error if it's from Python
|
| 323 |
+
st.error(f"An error occurred during AI processing: {e}")
|
| 324 |
+
st.info("This might be a Google API error. Check your key or quota.")
|
| 325 |
+
st.session_state.stage = 'start'
|
| 326 |
|
| 327 |
# --- Main Interview Area (Stages > 0) ---
|
| 328 |
+
if st.session_state.stage not in ['start', 'processing_resume']:
|
| 329 |
|
| 330 |
# --- Chat History Display ---
|
| 331 |
st.subheader("Interview Transcript")
|