Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +15 -8
src/streamlit_app.py
CHANGED
|
@@ -176,6 +176,7 @@ If a good followup question can be asked generate it but only if it is a genuine
|
|
| 176 |
import io # Make sure 'import io' is at the top of your file
|
| 177 |
|
| 178 |
# --- REPLACED: Official Google Cloud TTS Function ---
|
|
|
|
| 179 |
@st.cache_data
|
| 180 |
def synthesize_speech(text):
|
| 181 |
"""
|
|
@@ -186,8 +187,19 @@ def synthesize_speech(text):
|
|
| 186 |
st.warning("google-cloud-texttospeech library not found, audio playback is disabled.")
|
| 187 |
return None
|
| 188 |
|
| 189 |
-
#
|
| 190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
|
| 192 |
# Set the text input to be synthesized
|
| 193 |
synthesis_input = texttospeech.SynthesisInput(text=text)
|
|
@@ -209,7 +221,6 @@ def synthesize_speech(text):
|
|
| 209 |
|
| 210 |
return response.audio_content
|
| 211 |
|
| 212 |
-
|
| 213 |
def text_to_speech_and_display(text, autoplay=True):
|
| 214 |
"""
|
| 215 |
Displays the text and plays the synthesized audio.
|
|
@@ -342,15 +353,11 @@ if st.session_state.stage == 'start':
|
|
| 342 |
st.session_state.resume_text = resume_text_input
|
| 343 |
st.session_state.stage = 'processing_resume'
|
| 344 |
st.rerun()
|
| 345 |
-
|
| 346 |
# --- NEW STAGE 0.5: Process Resume (runs *after* file upload) ---
|
| 347 |
elif st.session_state.stage == 'processing_resume':
|
| 348 |
with st.spinner("Analyzing your resume... This may take a moment."):
|
| 349 |
try:
|
| 350 |
-
# --- START: TEMPORARY TEST CODE ---
|
| 351 |
-
st.warning("AI Calls are in TEST MODE.")
|
| 352 |
-
|
| 353 |
-
# 1. Generate DUMMY Questions
|
| 354 |
resume_text = st.session_state.resume_text
|
| 355 |
st.session_state.questions = generate_questions_from_resume(resume_text, gen_q_model)
|
| 356 |
|
|
|
|
| 176 |
import io # Make sure 'import io' is at the top of your file
|
| 177 |
|
| 178 |
# --- REPLACED: Official Google Cloud TTS Function ---
|
| 179 |
+
|
| 180 |
@st.cache_data
|
| 181 |
def synthesize_speech(text):
|
| 182 |
"""
|
|
|
|
| 187 |
st.warning("google-cloud-texttospeech library not found, audio playback is disabled.")
|
| 188 |
return None
|
| 189 |
|
| 190 |
+
# --- START OF FIX ---
|
| 191 |
+
# Get the API key from the environment (where HF secrets put it)
|
| 192 |
+
api_key = os.environ.get("GOOGLE_API_KEY")
|
| 193 |
+
|
| 194 |
+
# Check if the key exists
|
| 195 |
+
if not api_key:
|
| 196 |
+
st.error("GOOGLE_API_KEY not found in secrets. Cannot initialize TTS.")
|
| 197 |
+
return None
|
| 198 |
+
|
| 199 |
+
# Pass the key explicitly to the client
|
| 200 |
+
client_options = {"api_key": api_key}
|
| 201 |
+
client = texttospeech.TextToSpeechClient(client_options=client_options)
|
| 202 |
+
# --- END OF FIX ---
|
| 203 |
|
| 204 |
# Set the text input to be synthesized
|
| 205 |
synthesis_input = texttospeech.SynthesisInput(text=text)
|
|
|
|
| 221 |
|
| 222 |
return response.audio_content
|
| 223 |
|
|
|
|
| 224 |
def text_to_speech_and_display(text, autoplay=True):
|
| 225 |
"""
|
| 226 |
Displays the text and plays the synthesized audio.
|
|
|
|
| 353 |
st.session_state.resume_text = resume_text_input
|
| 354 |
st.session_state.stage = 'processing_resume'
|
| 355 |
st.rerun()
|
| 356 |
+
|
| 357 |
# --- NEW STAGE 0.5: Process Resume (runs *after* file upload) ---
|
| 358 |
elif st.session_state.stage == 'processing_resume':
|
| 359 |
with st.spinner("Analyzing your resume... This may take a moment."):
|
| 360 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
resume_text = st.session_state.resume_text
|
| 362 |
st.session_state.questions = generate_questions_from_resume(resume_text, gen_q_model)
|
| 363 |
|