Viper51 commited on
Commit
702e8a9
·
verified ·
1 Parent(s): 66caf46

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +21 -9
src/streamlit_app.py CHANGED
@@ -360,23 +360,35 @@ if st.session_state.stage == 'start':
360
 
361
  if uploaded_file:
362
  with st.spinner("Analyzing your resume... This may take a moment."):
363
- resume_text = read_resume(uploaded_file)
364
- if resume_text:
365
- # 1. Generate Questions
366
- st.session_state.questions = generate_questions_from_resume(resume_text, gen_q_model)
367
- if not st.session_state.questions:
368
- st.error("Could not generate questions from the resume. Please try another file.")
369
  st.session_state.stage = 'start'
370
  else:
371
- # 2. Get AI Introduction
 
 
 
 
 
 
372
  intro_output = get_introduction(intro_model)
373
  st.session_state.current_question = getattr(intro_output, 'question', "Can you introduce yourself?")
374
-
375
  # 3. Move to next stage and display intro
376
  st.session_state.stage = 'awaiting_intro'
377
  text_to_speech_and_display(getattr(intro_output, 'intro', "Hello, I'm Interviewer.AI. Please introduce yourself."))
378
  text_to_speech_and_display(getattr(intro_output, 'question', "Can you introduce yourself?"))
379
- st.rerun() # Rerun to update the UI
 
 
 
 
 
 
 
 
380
 
381
  # --- Main Interview Area (Stages > 0) ---
382
  if st.session_state.stage != 'start':
 
360
 
361
  if uploaded_file:
362
  with st.spinner("Analyzing your resume... This may take a moment."):
363
+ try:
364
+ resume_text = read_resume(uploaded_file)
365
+ if not resume_text:
366
+ st.error("Could not extract text from the resume. Please try another file.")
 
 
367
  st.session_state.stage = 'start'
368
  else:
369
+ # 1. Generate Questions (guarded inside function)
370
+ st.session_state.questions = generate_questions_from_resume(resume_text, gen_q_model)
371
+ if not st.session_state.questions:
372
+ st.warning("No AI-generated questions returned; using fallback questions.")
373
+ st.session_state.questions = generate_questions_from_resume(resume_text, None)
374
+
375
+ # 2. Get AI Introduction (guarded)
376
  intro_output = get_introduction(intro_model)
377
  st.session_state.current_question = getattr(intro_output, 'question', "Can you introduce yourself?")
378
+
379
  # 3. Move to next stage and display intro
380
  st.session_state.stage = 'awaiting_intro'
381
  text_to_speech_and_display(getattr(intro_output, 'intro', "Hello, I'm Interviewer.AI. Please introduce yourself."))
382
  text_to_speech_and_display(getattr(intro_output, 'question', "Can you introduce yourself?"))
383
+ st.rerun()
384
+ except Exception as e:
385
+ # Catch-all to prevent any LLM/network exceptions from surfacing to the client
386
+ st.error(f"An error occurred while processing the resume. Using fallback behaviour. Error: {e}")
387
+ # Fallback simple questions
388
+ 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?"]
389
+ st.session_state.questions = fallback_qs
390
+ st.session_state.stage = 'asking_question'
391
+ st.rerun()
392
 
393
  # --- Main Interview Area (Stages > 0) ---
394
  if st.session_state.stage != 'start':