Vageesh1 commited on
Commit
97f3692
Β·
1 Parent(s): 8c41c02

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -60
app.py CHANGED
@@ -47,83 +47,105 @@ user_api_key = st.sidebar.text_input(
47
  type="password")
48
 
49
  def ui():
50
-
51
-
52
  if user_api_key is not None and user_api_key.strip() != "":
53
- os.environ["OPENAI_API_KEY"] =user_api_key
54
  template = """
55
- Your custon promp
56
  {history}
57
- Me:Behave like a Telecomm customer servce call agent and don't include any website address, compnay name or any other parameter in your output {human_input}
58
  Jack:
59
- """
60
-
61
  prompt = PromptTemplate(
62
- input_variables=["history", "human_input"],
63
- template=template
64
- )
65
-
66
  llm_chain = LLMChain(
67
- llm = ChatOpenAI(temperature=0.0,model_name='gpt-3.5-turbo'),
68
  prompt=prompt,
69
  verbose=True,
70
  memory=ConversationBufferWindowMemory(k=2)
71
  )
72
-
73
  if 'history' not in st.session_state:
74
  st.session_state['history'] = []
75
-
76
  if 'generated' not in st.session_state:
77
  st.session_state['generated'] = []
78
-
79
  if 'past' not in st.session_state:
80
  st.session_state['past'] = []
81
-
82
- if user_api_key is not None and user_api_key.strip() != "":
83
- eleven_labs_api_key = st.sidebar.text_input(
84
- label="#### Your Eleven Labs API key πŸ‘‡",
85
- placeholder="Paste your Eleven Labs API key",
86
- type="password")
87
-
88
- set_api_key(user_api_key)
89
-
90
- # #container for the chat history
91
- # response_container = st.container()
92
- # #container for the user's text input
93
- # container = st.container()
94
-
95
- # with container:
96
- with st.form(key='my_form', clear_on_submit=True):
97
- audio_file = st.file_uploader("Upload an audio file ", type=[ "wav,Mp4","Mp3"])
98
- submit_button = st.form_submit_button(label='Send')
99
- if audio_file is not None and submit_button :
100
- output_file_path = "./output_audio.mp3"
101
- save_uploaded_file_as_mp3(audio_file,output_file_path )
102
- hindi_input_audio,sample_rate= librosa.load(output_file_path, sr=None, mono=True)
103
- #applying the audio recognition
104
- hindi_transcription=parse_transcription('./output_audio.mp3')
105
- st.success(f"Audio file saved as {output_file_path}")
106
- #convert hindi to english
107
- english_input=hindi_to_english(hindi_transcription)
108
- #feeding the input to the LLM
109
- english_output = conversational_chat(llm_chain,english_input)
110
- #converting english to hindi
111
- hin_output=translate_english_to_hindi(english_output)
112
- #getting the hindi_tts
113
- hindi_output_audio=hindi_tts(hin_output)
114
- # hindi_output_file="./Hindi_output_Audio.Mp3"
115
- # save_uploaded_file_as_mp3(hindi_out"put_audio,hindi_output_file)
116
- st.audio(hindi_output_audio)
117
-
118
- # st.session_state['past'].append(hindi_input_audio)
119
- # st.session_state['generated'].append(hindi_output_audio)
120
-
121
- # if 'generated' in st.session_state and st.session_state['generated']:
122
- # with response_container:
123
- # for i in range(len(st.session_state['generated'])):
124
- # st.audio(st.session_state["past"][i],format='audio/wav')
125
- # st.audio(st.session_state["generated"][i],format='audio/wav')
126
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  if __name__ == '__main__':
128
  ui()
129
 
 
47
  type="password")
48
 
49
  def ui():
50
+ user_api_key = st.sidebar.text_input("OpenAI API Key", type="password")
51
+
52
  if user_api_key is not None and user_api_key.strip() != "":
53
+ os.environ["OPENAI_API_KEY"] = user_api_key
54
  template = """
55
+ Your custom prompt
56
  {history}
57
+ Me: Behave like a Telecomm customer service call agent and don't include any website address, company name, or any other parameter in your output {human_input}
58
  Jack:
59
+ """
60
+
61
  prompt = PromptTemplate(
62
+ input_variables=["history", "human_input"],
63
+ template=template
64
+ )
65
+
66
  llm_chain = LLMChain(
67
+ llm=ChatOpenAI(temperature=0.0, model_name='gpt-3.5-turbo'),
68
  prompt=prompt,
69
  verbose=True,
70
  memory=ConversationBufferWindowMemory(k=2)
71
  )
72
+
73
  if 'history' not in st.session_state:
74
  st.session_state['history'] = []
75
+
76
  if 'generated' not in st.session_state:
77
  st.session_state['generated'] = []
78
+
79
  if 'past' not in st.session_state:
80
  st.session_state['past'] = []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
+ eleven_labs_api_key = st.sidebar.text_input(
83
+ label="Your Eleven Labs API key πŸ‘‡",
84
+ placeholder="Paste your Eleven Labs API key",
85
+ type="password")
86
+
87
+ set_api_key(user_api_key)
88
+
89
+ audio_file = st.file_uploader("Upload an audio file", type=["wav", "mp4", "mp3"])
90
+ if audio_file is not None:
91
+ output_file_path = "./output_audio.mp3"
92
+ save_uploaded_file_as_mp3(audio_file, output_file_path)
93
+ hindi_input_audio, sample_rate = librosa.load(output_file_path, sr=None, mono=True)
94
+
95
+ # Applying audio recognition
96
+ hindi_transcription = parse_transcription('./output_audio.mp3')
97
+ st.success(f"Audio file saved as {output_file_path}")
98
+
99
+ # Convert Hindi to English
100
+ english_input = hindi_to_english(hindi_transcription)
101
+
102
+ # Feeding the input to the LLM
103
+ english_output = conversational_chat(llm_chain, english_input)
104
+
105
+ # Convert English to Hindi
106
+ hin_output = translate_english_to_hindi(english_output)
107
+
108
+ # Getting the Hindi TTS
109
+ hindi_output_audio = hindi_tts(hin_output)
110
+
111
+ # Show original uploaded audio
112
+ st.audio(audio_file, format='audio/mp3')
113
+
114
+ # Show processed output audio
115
+ st.audio(hindi_output_audio, format='audio/mp3')
116
+
117
+ st.markdown("---")
118
+ # Add a new audio uploader for users to upload another audio file
119
+ with st.form(key='my_form', clear_on_submit=True):
120
+ audio_file_new = st.file_uploader("Upload another audio file", type=["wav", "mp4", "mp3"])
121
+ submit_button = st.form_submit_button(label='Process and Play')
122
+
123
+ if audio_file_new is not None and submit_button:
124
+ output_file_path_new = "./output_audio_new.mp3"
125
+ save_uploaded_file_as_mp3(audio_file_new, output_file_path_new)
126
+ hindi_input_audio_new, sample_rate_new = librosa.load(output_file_path_new, sr=None, mono=True)
127
+
128
+ # Applying audio recognition for the new file
129
+ hindi_transcription_new = parse_transcription(output_file_path_new)
130
+ st.success(f"Audio file saved as {output_file_path_new}")
131
+
132
+ # Convert Hindi to English for the new file
133
+ english_input_new = hindi_to_english(hindi_transcription_new)
134
+
135
+ # Feeding the input to the LLM for the new file
136
+ english_output_new = conversational_chat(llm_chain, english_input_new)
137
+
138
+ # Convert English to Hindi for the new file
139
+ hin_output_new = translate_english_to_hindi(english_output_new)
140
+
141
+ # Getting the Hindi TTS for the new file
142
+ hindi_output_audio_new = hindi_tts(hin_output_new)
143
+
144
+ # Show original uploaded audio for the new file
145
+ st.audio(audio_file_new, format='audio/mp3')
146
+
147
+ # Show processed output audio for the new file
148
+ st.audio(hindi_output_audio_new, format='audio/mp3')
149
  if __name__ == '__main__':
150
  ui()
151