Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +34 -14
src/streamlit_app.py
CHANGED
|
@@ -288,6 +288,8 @@ def text_to_speech_and_display(text, autoplay=True):
|
|
| 288 |
st.session_state.chat_history.append(f"**Interviewer:** {text}")
|
| 289 |
|
| 290 |
# 2. Synthesize speech
|
|
|
|
|
|
|
| 291 |
audio_content = synthesize_speech(text)
|
| 292 |
|
| 293 |
# 3. Display audio player
|
|
@@ -375,6 +377,8 @@ st.divider()
|
|
| 375 |
# --- Session State Initialization ---
|
| 376 |
if 'stage' not in st.session_state:
|
| 377 |
st.session_state.stage = 'start'
|
|
|
|
|
|
|
| 378 |
if 'chat_history' not in st.session_state:
|
| 379 |
st.session_state.chat_history = []
|
| 380 |
if 'questions' not in st.session_state:
|
|
@@ -393,7 +397,11 @@ if 'num_questions' not in st.session_state:
|
|
| 393 |
# --- STAGE 0: Start (File Upload) ---
|
| 394 |
if st.session_state.stage == 'start':
|
| 395 |
st.info("Welcome! Please paste your resume text below to begin.")
|
| 396 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 397 |
with st.form(key="resume_form"):
|
| 398 |
resume_text_input = st.text_area("Paste your resume text here:", height=300)
|
| 399 |
submit_button = st.form_submit_button("Start Interview")
|
|
@@ -466,20 +474,32 @@ if st.session_state.stage not in ['start', 'processing_resume']:
|
|
| 466 |
st.info("Interview is finished. Start a new interview to speak.")
|
| 467 |
|
| 468 |
else:
|
| 469 |
-
st.
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
if audio_bytes_dict:
|
| 477 |
-
# The component returns a dictionary, get the bytes
|
| 478 |
-
audio_bytes = audio_bytes_dict['bytes']
|
| 479 |
|
| 480 |
-
|
| 481 |
-
#
|
| 482 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 483 |
# --- END OF REPLACEMENT ---
|
| 484 |
|
| 485 |
|
|
|
|
| 288 |
st.session_state.chat_history.append(f"**Interviewer:** {text}")
|
| 289 |
|
| 290 |
# 2. Synthesize speech
|
| 291 |
+
if not st.session_state.get('audio_enabled', False):
|
| 292 |
+
return
|
| 293 |
audio_content = synthesize_speech(text)
|
| 294 |
|
| 295 |
# 3. Display audio player
|
|
|
|
| 377 |
# --- Session State Initialization ---
|
| 378 |
if 'stage' not in st.session_state:
|
| 379 |
st.session_state.stage = 'start'
|
| 380 |
+
if 'audio_enabled' not in st.session_state:
|
| 381 |
+
st.session_state.audio_enabled = False
|
| 382 |
if 'chat_history' not in st.session_state:
|
| 383 |
st.session_state.chat_history = []
|
| 384 |
if 'questions' not in st.session_state:
|
|
|
|
| 397 |
# --- STAGE 0: Start (File Upload) ---
|
| 398 |
if st.session_state.stage == 'start':
|
| 399 |
st.info("Welcome! Please paste your resume text below to begin.")
|
| 400 |
+
st.toggle(
|
| 401 |
+
"Enable Audio Mode (AI Voice & Microphone)",
|
| 402 |
+
key='audio_enabled',
|
| 403 |
+
help="If ON, the AI will speak and you can answer with your voice. If OFF, it's text-only and you have to type your answer."
|
| 404 |
+
)
|
| 405 |
with st.form(key="resume_form"):
|
| 406 |
resume_text_input = st.text_area("Paste your resume text here:", height=300)
|
| 407 |
submit_button = st.form_submit_button("Start Interview")
|
|
|
|
| 474 |
st.info("Interview is finished. Start a new interview to speak.")
|
| 475 |
|
| 476 |
else:
|
| 477 |
+
if st.session_state.audio_enabled:
|
| 478 |
+
st.write("Your turn to speak:")
|
| 479 |
+
audio_bytes_dict = mic_recorder(
|
| 480 |
+
start_prompt="Start Recording ⏺️",
|
| 481 |
+
stop_prompt="Stop Recording ⏹️",
|
| 482 |
+
key='recorder'
|
| 483 |
+
)
|
|
|
|
|
|
|
|
|
|
| 484 |
|
| 485 |
+
if audio_bytes_dict:
|
| 486 |
+
# The component returns a dictionary, get the bytes
|
| 487 |
+
audio_bytes = audio_bytes_dict['bytes']
|
| 488 |
+
|
| 489 |
+
with st.spinner("Transcribing your answer..."):
|
| 490 |
+
# Use our NEW Google Cloud STT function
|
| 491 |
+
user_text = speech_to_text(audio_bytes)
|
| 492 |
+
|
| 493 |
+
|
| 494 |
+
else:
|
| 495 |
+
# --- TEXT-ONLY MODE (Text Input) ---
|
| 496 |
+
with st.form(key="answer_form", clear_on_submit=True):
|
| 497 |
+
answer = st.text_input("Your answer:", disabled=is_disabled)
|
| 498 |
+
submit_button = st.form_submit_button(label="Submit Answer", disabled=is_disabled)
|
| 499 |
+
|
| 500 |
+
if submit_button and answer:
|
| 501 |
+
user_text = answer
|
| 502 |
+
st.session_state.chat_history.append(f"**You:** {user_text}")
|
| 503 |
# --- END OF REPLACEMENT ---
|
| 504 |
|
| 505 |
|