Spaces:
Build error
Build error
Update app.py
Browse files61 unmodified lines626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512661 unmodified linestemplate=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 historyresponse_container = st.container()#container for the user's text inputcontainer = 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 recognitionhindi_transcription=parse_transcription('./output_audio.mp3')st.success(f"Audio file saved as {output_file_path}")#convert hindi to englishenglish_input=hindi_to_english(hindi_transcription)#feeding the input to the LLMenglish_output = conversational_chat(english_input)#converting english to hindihin_output=translate_english_to_hindi(english_output)#getting the hindi_ttshindi_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 __name__ == '__main__':ui()61 unmodified lines626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512661 unmodified linestemplate=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 historyresponse_container = st.container()#container for the user's text inputcontainer = 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 recognitionhindi_transcription=parse_transcription('./output_audio.mp3')st.success(f"Audio file saved as {output_file_path}")#convert hindi to englishenglish_input=hindi_to_english(hindi_transcription)#feeding the input to the LLMenglish_output = conversational_chat(english_input)#converting english to hindihin_output=translate_english_to_hindi(english_output)#getting the hindi_ttshindi_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 __name__ == '__main__':ui()
app.py+58-58