Spaces:
Build error
Build error
Update app.py
Browse files61 unmodified lines6263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212311912012112212312412512661 unmodified lines template=template ) llm_chain = LLMChain( llm = ChatOpenAI(temperature=0.0,model_name='gpt-3.5-turbo'), prompt=prompt, verbose=True, memory=ConversationBufferWindowMemory(k=2) )
if 'history' not in st.session_state: st.session_state['history'] = []
if 'generated' not in st.session_state: st.session_state['generated'] = ["Hello ! Ask me anything about " + " π€"]
if 'past' not in st.session_state: st.session_state['past'] = ["Hey ! π"]
if user_api_key is not None and user_api_key.strip() != "": eleven_labs_api_key = st.sidebar.text_input( label="#### Your Eleven Labs API key π", placeholder="Paste your Eleven Labs API key", type="password") set_api_key(user_api_key) #container for the chat history response_container = st.container() #container for the user's text input container = st.container()
with container: with st.form(key='my_form', clear_on_submit=True): audio_file = audiorecorder("Click to record", "Recording...") wav_file = open("./output_audio.mp3", "wb") wav_file.write(audio.tobytes()) submit_button = st.form_submit_button(label='Send') if submit_button and audio_file: output_file_path = "./output_audio.mp3" # save_uploaded_file_as_mp3(audio_file,output_file_path ) hindi_input_audio,sample_rate=torchaudio.load(output_file_path) #applying the audio recognition hindi_transcription=parse_transcription('./output_audio.mp3') st.success(f"Audio file saved as {output_file_path}") #convert hindi to english english_input=hindi_to_english(hindi_transcription) #feeding the input to the LLM english_output = conversational_chat(english_input) #converting english to hindi hin_output=translate_english_to_hindi(english_output) #getting the hindi_tts hindi_output_audio=hindi_tts(hin_output)
st.session_state['past'].append(hindi_input_audio) st.session_state['generated'].append(hindi_output_audio) llm_chain = LLMChain( llm = ChatOpenAI(temperature=0.0,model_name='gpt-3.5-turbo'), prompt=prompt, verbose=True, memory=ConversationBufferWindowMemory(k=2) ) if 'history' not in st.session_state: st.session_state['history'] = [] if 'generated' not in st.session_state: st.session_state['generated'] = ["Hello ! Ask me anything about " + " π€"] if 'past' not in st.session_state: st.session_state['past'] = ["Hey ! π"] if user_api_key is not None and user_api_key.strip() != "": eleven_labs_api_key = st.sidebar.text_input( label="#### Your Eleven Labs API key π", placeholder="Paste your Eleven Labs API key", type="password") set_api_key(user_api_key) #container for the chat history response_container = st.container() #container for the user's text input container = st.container() with container: with st.form(key='my_form', clear_on_submit=True): audio_file = audiorecorder("Click to record", "Recording...") wav_file = open("./output_audio.mp3", "wb") wav_file.write(audio.tobytes()) submit_button = st.form_submit_button(label='Send') if submit_button and audio_file: output_file_path = "./output_audio.mp3" # save_uploaded_file_as_mp3(audio_file,output_file_path ) hindi_input_audio,sample_rate=torchaudio.load(output_file_path) #applying the audio recognition hindi_transcription=parse_transcription('./output_audio.mp3') st.success(f"Audio file saved as {output_file_path}") #convert hindi to english english_input=hindi_to_english(hindi_transcription) #feeding the input to the LLM english_output = conversational_chat(english_input) #converting english to hindi hin_output=translate_english_to_hindi(english_output) #getting the hindi_tts hindi_output_audio=hindi_tts(hin_output) st.session_state['past'].append(hindi_input_audio) st.session_state['generated'].append(hindi_output_audio) if st.session_state['generated']: with response_container: for i in range(len(st.session_state['generated'])): st.audio(st.session_state["past"][i],format='audio/wav') st.audio(st.session_state["generated"][i],format='audio/wav') if st.session_state['generated']: with response_container: for i in range(len(st.session_state['generated'])): st.audio(st.session_state["past"][i],format='audio/wav') st.audio(st.session_state["generated"][i],format='audio/wav')
if __name__ == '__main__': ui()app.py+58-58