Added download button
Browse filesHad to add a download button because the built in st.audio() portion is failing the download part.
- hype_pack/streamlit_app.py +21 -5
- hype_pack/utils/nodes.py +61 -55
hype_pack/streamlit_app.py
CHANGED
|
@@ -167,13 +167,10 @@ def main():
|
|
| 167 |
)
|
| 168 |
|
| 169 |
st.session_state.interview_state = interview_state
|
| 170 |
-
if interview_state.audio_bytes:
|
| 171 |
-
st.audio(interview_state.audio_bytes, format='audio/mp3')
|
| 172 |
-
|
| 173 |
st.session_state.stage = 'results'
|
| 174 |
st.rerun()
|
| 175 |
|
| 176 |
-
|
| 177 |
elif st.session_state.stage == 'results':
|
| 178 |
if (st.session_state.interview_state and
|
| 179 |
st.session_state.interview_state.transcript):
|
|
@@ -184,7 +181,26 @@ def main():
|
|
| 184 |
# Audio player section
|
| 185 |
st.markdown("#### Listen to Your Hype Speech 🎧")
|
| 186 |
if st.session_state.interview_state.audio_bytes:
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
# Collapsible transcript
|
| 190 |
with st.expander("View Speech Transcript 📝", expanded=False):
|
|
|
|
| 167 |
)
|
| 168 |
|
| 169 |
st.session_state.interview_state = interview_state
|
|
|
|
|
|
|
|
|
|
| 170 |
st.session_state.stage = 'results'
|
| 171 |
st.rerun()
|
| 172 |
|
| 173 |
+
# Results Stage
|
| 174 |
elif st.session_state.stage == 'results':
|
| 175 |
if (st.session_state.interview_state and
|
| 176 |
st.session_state.interview_state.transcript):
|
|
|
|
| 181 |
# Audio player section
|
| 182 |
st.markdown("#### Listen to Your Hype Speech 🎧")
|
| 183 |
if st.session_state.interview_state.audio_bytes:
|
| 184 |
+
# Create columns for audio player and download button
|
| 185 |
+
col1, col2 = st.columns([3, 1])
|
| 186 |
+
|
| 187 |
+
with col1:
|
| 188 |
+
# Display audio player
|
| 189 |
+
st.audio(
|
| 190 |
+
st.session_state.interview_state.audio_bytes,
|
| 191 |
+
format='audio/mp3'
|
| 192 |
+
)
|
| 193 |
+
|
| 194 |
+
with col2:
|
| 195 |
+
# Add download button with unique filename
|
| 196 |
+
unique_filename = f"hype_speech_{uuid.uuid4().hex[:8]}.mp3"
|
| 197 |
+
st.download_button(
|
| 198 |
+
label="💾 Download",
|
| 199 |
+
data=st.session_state.interview_state.audio_bytes,
|
| 200 |
+
file_name=unique_filename,
|
| 201 |
+
mime="audio/mpeg",
|
| 202 |
+
help="Download your hype speech as an MP3 file"
|
| 203 |
+
)
|
| 204 |
|
| 205 |
# Collapsible transcript
|
| 206 |
with st.expander("View Speech Transcript 📝", expanded=False):
|
hype_pack/utils/nodes.py
CHANGED
|
@@ -9,19 +9,23 @@ from dotenv import load_dotenv
|
|
| 9 |
from lmnt.api import Speech
|
| 10 |
import time
|
| 11 |
import tempfile
|
|
|
|
| 12 |
|
| 13 |
load_dotenv()
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
|
| 17 |
def build_reference_material_node(interview_state: InterviewState) -> InterviewState:
|
| 18 |
"""
|
| 19 |
Analyzes candidate background to generate material for motivational speeches.
|
| 20 |
"""
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
| 25 |
|
| 26 |
prompt = ChatPromptTemplate.from_messages([
|
| 27 |
("system", """You are an expert at identifying compelling personal narratives
|
|
@@ -75,54 +79,55 @@ def generate_questions_node(interview_state: InterviewState) -> InterviewState:
|
|
| 75 |
"""
|
| 76 |
Generates questions and manages the question history.
|
| 77 |
"""
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
interview_state.qa_history
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
new_questions = llm.invoke(prompt.format_messages(
|
| 109 |
-
reference_material=interview_state.reference_material,
|
| 110 |
-
previous_questions="\n".join([
|
| 111 |
-
f"Q: {q.question_text}"
|
| 112 |
-
for q in (interview_state.qa_history.questions or [])
|
| 113 |
])
|
| 114 |
-
))
|
| 115 |
-
|
| 116 |
-
# Filter out any duplicate questions and append new ones
|
| 117 |
-
unique_new_questions = [
|
| 118 |
-
q for q in new_questions.questions
|
| 119 |
-
if q.question_text not in existing_questions
|
| 120 |
-
]
|
| 121 |
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
return interview_state
|
| 128 |
|
|
@@ -130,10 +135,11 @@ def generate_transcript_node(interview_state: InterviewState, speaker_profile: d
|
|
| 130 |
"""
|
| 131 |
Generates a concise, TTS-friendly motivational speech.
|
| 132 |
"""
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
|
|
|
| 137 |
|
| 138 |
prompt = ChatPromptTemplate.from_messages([
|
| 139 |
("system", f"""You are speaking directly TO the candidate about why they should be excited about THIS specific opportunity.
|
|
|
|
| 9 |
from lmnt.api import Speech
|
| 10 |
import time
|
| 11 |
import tempfile
|
| 12 |
+
from langchain_core.tracers.context import tracing_v2_enabled
|
| 13 |
|
| 14 |
load_dotenv()
|
| 15 |
|
| 16 |
+
# At the top of your file, after imports
|
| 17 |
+
os.environ["LANGCHAIN_TRACING_V2"] = "true"
|
| 18 |
+
os.environ["LANGCHAIN_PROJECT"] = "hypecast_generator"
|
| 19 |
|
| 20 |
def build_reference_material_node(interview_state: InterviewState) -> InterviewState:
|
| 21 |
"""
|
| 22 |
Analyzes candidate background to generate material for motivational speeches.
|
| 23 |
"""
|
| 24 |
+
with tracing_v2_enabled(tags=["reference_material"]):
|
| 25 |
+
llm = ChatOpenAI(
|
| 26 |
+
model="gpt-4o-mini",
|
| 27 |
+
temperature=0.1
|
| 28 |
+
).with_structured_output(ReferenceMaterial)
|
| 29 |
|
| 30 |
prompt = ChatPromptTemplate.from_messages([
|
| 31 |
("system", """You are an expert at identifying compelling personal narratives
|
|
|
|
| 79 |
"""
|
| 80 |
Generates questions and manages the question history.
|
| 81 |
"""
|
| 82 |
+
with tracing_v2_enabled(tags=["questions"]):
|
| 83 |
+
llm = ChatOpenAI(
|
| 84 |
+
model="gpt-4o-mini",
|
| 85 |
+
temperature=0.35
|
| 86 |
+
).with_structured_output(QuestionList)
|
| 87 |
+
|
| 88 |
+
# Get existing question texts to avoid duplicates
|
| 89 |
+
existing_questions = set()
|
| 90 |
+
if interview_state.qa_history is None:
|
| 91 |
+
interview_state.qa_history = QuestionList(questions=[])
|
| 92 |
+
|
| 93 |
+
for q in interview_state.qa_history.questions:
|
| 94 |
+
existing_questions.add(q.question_text)
|
| 95 |
+
|
| 96 |
+
prompt = ChatPromptTemplate.from_messages([
|
| 97 |
+
("system", """Generate 2-3 focused questions that reveal what motivates
|
| 98 |
+
this person. Each question should have 3 distinct choices."""),
|
| 99 |
+
("human", """
|
| 100 |
+
Reference Material:
|
| 101 |
+
{reference_material}
|
| 102 |
+
|
| 103 |
+
Previous Questions Asked:
|
| 104 |
+
{previous_questions}
|
| 105 |
+
|
| 106 |
+
Create new questions that:
|
| 107 |
+
- Are different from previous questions
|
| 108 |
+
- Focus on motivation and confidence
|
| 109 |
+
- Connect to their background
|
| 110 |
+
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
+
new_questions = llm.invoke(prompt.format_messages(
|
| 114 |
+
reference_material=interview_state.reference_material,
|
| 115 |
+
previous_questions="\n".join([
|
| 116 |
+
f"Q: {q.question_text}"
|
| 117 |
+
for q in (interview_state.qa_history.questions or [])
|
| 118 |
+
])
|
| 119 |
+
))
|
| 120 |
+
|
| 121 |
+
# Filter out any duplicate questions and append new ones
|
| 122 |
+
unique_new_questions = [
|
| 123 |
+
q for q in new_questions.questions
|
| 124 |
+
if q.question_text not in existing_questions
|
| 125 |
+
]
|
| 126 |
+
|
| 127 |
+
# Update qa_history, initializing if None
|
| 128 |
+
if interview_state.qa_history is None:
|
| 129 |
+
interview_state.qa_history = None
|
| 130 |
+
interview_state.qa_history.questions.extend(unique_new_questions)
|
| 131 |
|
| 132 |
return interview_state
|
| 133 |
|
|
|
|
| 135 |
"""
|
| 136 |
Generates a concise, TTS-friendly motivational speech.
|
| 137 |
"""
|
| 138 |
+
with tracing_v2_enabled(tags=["transcript"]):
|
| 139 |
+
llm = ChatOpenAI(
|
| 140 |
+
model="gpt-4o-mini",
|
| 141 |
+
temperature=0.6
|
| 142 |
+
).with_structured_output(HypeCastTranscript)
|
| 143 |
|
| 144 |
prompt = ChatPromptTemplate.from_messages([
|
| 145 |
("system", f"""You are speaking directly TO the candidate about why they should be excited about THIS specific opportunity.
|