Skip to content

Commit

Permalink
v0.1.2 update
Browse files Browse the repository at this point in the history
  • Loading branch information
jiatastic committed Aug 4, 2023
1 parent bc6364f commit a2bb490
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 111 deletions.
Binary file modified aws/__pycache__/synthesize_speech.cpython-310.pyc
Binary file not shown.
69 changes: 27 additions & 42 deletions pages/Behavioral Screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,23 @@ def update_markdown(audio_md):
update_audio()
update_markdown(global_audio_md)

def save_vector(text: str):
def embeddings(text: str):
nltk.download('punkt')
text_splitter = NLTKTextSplitter()
texts = text_splitter.split_text(text)
# Create emebeddings
embeddings = OpenAIEmbeddings()
docsearch = FAISS.from_texts(texts, embeddings)
return docsearch
retriever = docsearch.as_retriever(search_tupe='similarity search')
return retriever

def initialize_session_state():
if "bq_docsearch" not in st.session_state:
st.session_state.bq_docserch = save_vector(jd)
if "bq_retriever" not in st.session_state:
st.session_state.bq_retriever = st.session_state.bq_docserch.as_retriever(search_type="similarity")
if "bq_chain_type_kwargs" not in st.session_state:
if "retriever" not in st.session_state:
st.session_state.retriever = embeddings(jd)
if "chain_type_kwargs" not in st.session_state:
Behavioral_Prompt = PromptTemplate(input_variables=["context", "question"],
template=templates.behavioral_template)
st.session_state.bq_chain_type_kwargs = {"prompt": Behavioral_Prompt}
st.session_state.chain_type_kwargs = {"prompt": Behavioral_Prompt}
# interview history
if "history" not in st.session_state:
st.session_state.history = []
Expand All @@ -87,9 +86,10 @@ def initialize_session_state():
temperature=0.8, )
st.session_state.guideline = RetrievalQA.from_chain_type(
llm=llm,
chain_type_kwargs=st.session_state.bq_chain_type_kwargs, chain_type='stuff',
retriever=st.session_state.bq_retriever, memory=st.session_state.memory).run(
chain_type_kwargs=st.session_state.chain_type_kwargs, chain_type='stuff',
retriever=st.session_state.retriever, memory=st.session_state.memory).run(
"Create an interview guideline and prepare total of 8 questions. Make sure the questions tests the soft skills")

# llm chain and memory
if "conversation" not in st.session_state:
llm = ChatOpenAI(
Expand Down Expand Up @@ -136,42 +136,26 @@ def answer_call_back():
try:
input = transcribe("temp/audio.wav")
# save human_answer to history
st.session_state.history.append(
Message("human", input)
)
# OpenAI answer and save to history
llm_answer = st.session_state.conversation.run(input)
# speech synthesis and speak out
audio_file_path = synthesize_speech(llm_answer)
# create audio widget with autoplay
audio_widget = Audio(audio_file_path, autoplay=True)
# save audio data to history
st.session_state.history.append(
Message("ai", llm_answer)
)
st.session_state.token_count += cb.total_tokens
return audio_widget
except:
st.session_state.history.append(Message("ai", "Sorry, I didn't get that. Please try again."))
else:
input = human_answer
st.session_state.history.append(
Message("human", input)
)
# OpenAI answer and save to history
llm_answer = st.session_state.conversation.run(input)
# OpenAI answer and save to history
llm_answer = st.session_state.conversation.run(input)
# speech synthesis and speak out
audio_file_path = synthesize_speech(llm_answer)
# create audio widget with autoplay
audio_widget = Audio(audio_file_path, autoplay=True)
# save audio data to history
st.session_state.history.append(
Message("ai", llm_answer)
)
st.session_state.token_count += cb.total_tokens
return audio_widget

st.session_state.history.append(
Message("human", input)
)
# OpenAI answer and save to history
llm_answer = st.session_state.conversation.run(input)
# speech synthesis and speak out
audio_file_path = synthesize_speech(llm_answer)
# create audio widget with autoplay
audio_widget = Audio(audio_file_path, autoplay=True)
# save audio data to history
st.session_state.history.append(
Message("ai", llm_answer)
)
st.session_state.token_count += cb.total_tokens
return audio_widget

### ————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
if jd:
Expand All @@ -183,6 +167,7 @@ def answer_call_back():
audio = None
chat_placeholder = st.container()
answer_placeholder = st.container()

if guideline:
st.write(st.session_state.guideline)
# if submit email adress, get interview feedback imediately
Expand Down
51 changes: 17 additions & 34 deletions pages/Professional Screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,52 +115,35 @@ def initialize_session_state():
)

def answer_call_back():
""" answer call back function"""
with get_openai_callback() as cb:
# user input
human_answer = st.session_state.answer
# transcribe audio
if voice:
# transcribe audio
save_wav_file("temp/audio.wav", human_answer)
try:
input = transcribe("temp/audio.wav")
# save human_answer to history
st.session_state.jd_history.append(
Message("human", input)
)
# OpenAI answer and save to history
llm_answer = st.session_state.jd_screen.run(input)
# speech synthesis
audio_file_path = synthesize_speech(llm_answer)
st.session_state.audio_file_path = audio_file_path
# 创建自动播放的音频部件
audio_widget = Audio(audio_file_path, autoplay=True)
# save audio data to history
st.session_state.jd_history.append(
Message("ai", llm_answer)
)
st.session_state.token_count += cb.total_tokens
return audio_widget
except:
st.session_state.jd_history.append(Message("ai", "Sorry, I didn't get that. Please try again."))
else:
input = human_answer
st.session_state.jd_history.append(
Message("human", input)
)
# OpenAI answer and save to history
llm_answer = st.session_state.jd_screen.run(input)
# speech synthesis
audio_file_path = synthesize_speech(llm_answer)
st.session_state.audio_file_path = audio_file_path
# 创建自动播放的音频部件
audio_widget = Audio(audio_file_path, autoplay=True)
# save audio data to history
st.session_state.jd_history.append(
Message("ai", llm_answer)
)
st.session_state.token_count += cb.total_tokens
return audio_widget

st.session_state.jd_history.append(
Message("human", input)
)
# OpenAI answer and save to history
llm_answer = st.session_state.jd_screen.run(input)
# speech synthesis and speak out
audio_file_path = synthesize_speech(llm_answer)
# create audio widget with autoplay
audio_widget = Audio(audio_file_path, autoplay=True)
# save audio data to history
st.session_state.jd_history.append(
Message("ai", llm_answer)
)
st.session_state.token_count += cb.total_tokens
return audio_widget

### ——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
# sumitted job description
Expand Down
52 changes: 18 additions & 34 deletions pages/Resume Screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,48 +126,32 @@ def answer_call_back():
with get_openai_callback() as cb:
# user input
human_answer = st.session_state.answer
# transcribe audio
if voice:
# transcribe audio
save_wav_file("temp/audio.wav", human_answer)
try:
input = transcribe("temp/audio.wav")
# save human input to history
st.session_state.resume_history.append(
Message("human", input)
)
# GPT Interviewer output and save to history
llm_answer = st.session_state.resume_screen.run(input)
# speech synthesis and speak out
audio_file_path = synthesize_speech(llm_answer)
st.session_state.audio_file_path = audio_file_path
# create audio widget with autoplay
audio_widget = Audio(audio_file_path, autoplay=True)
# save audio data to history
st.session_state.resume_history.append(
Message("ai", llm_answer)
)
st.session_state.token_count += cb.total_tokens
return audio_widget
# save human_answer to history
except:
st.session_state.resume_history.append(Message("ai", "Sorry, I didn't get that. Please try again."))
else:
input = human_answer
st.session_state.resume_history.append(
Message("human", input)
)
# GPT Interviewer output and save to history
llm_answer = st.session_state.resume_screen.run(input)
# speech synthesis and speak out
audio_file_path = synthesize_speech(llm_answer)
st.session_state.audio_file_path = audio_file_path
# create audio widget with auto play
audio_widget = Audio(audio_file_path, autoplay=True)
# save audio data to history
st.session_state.resume_history.append(
Message("ai", llm_answer)
)
st.session_state.token_count += cb.total_tokens
return audio_widget

st.session_state.resume_history.append(
Message("human", input)
)
# OpenAI answer and save to history
llm_answer = st.session_state.resume_screen.run(input)
# speech synthesis and speak out
audio_file_path = synthesize_speech(llm_answer)
# create audio widget with autoplay
audio_widget = Audio(audio_file_path, autoplay=True)
# save audio data to history
st.session_state.resume_history.append(
Message("ai", llm_answer)
)
st.session_state.token_count += cb.total_tokens
return audio_widget

### ——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

Expand Down
1 change: 0 additions & 1 deletion prompts/examples.py

This file was deleted.

Binary file modified temp/audio.wav
Binary file not shown.

0 comments on commit a2bb490

Please sign in to comment.