Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -47,109 +47,89 @@ user_api_key = st.sidebar.text_input(
|
|
47 |
type="password")
|
48 |
|
49 |
def ui():
|
50 |
-
|
|
|
51 |
if user_api_key is not None and user_api_key.strip() != "":
|
52 |
-
os.environ["OPENAI_API_KEY"] =
|
53 |
template = """
|
54 |
-
Your
|
55 |
{history}
|
56 |
-
Me:
|
57 |
Jack:
|
58 |
-
|
59 |
-
|
60 |
prompt = PromptTemplate(
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
llm_chain = LLMChain(
|
66 |
-
llm=ChatOpenAI(temperature=0.0,
|
67 |
prompt=prompt,
|
68 |
verbose=True,
|
69 |
memory=ConversationBufferWindowMemory(k=2)
|
70 |
)
|
71 |
-
|
72 |
if 'history' not in st.session_state:
|
73 |
st.session_state['history'] = []
|
74 |
-
|
75 |
if 'generated' not in st.session_state:
|
76 |
st.session_state['generated'] = []
|
77 |
-
|
78 |
if 'past' not in st.session_state:
|
79 |
st.session_state['past'] = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
-
eleven_labs_api_key = st.sidebar.text_input(
|
82 |
-
label="Your Eleven Labs API key 👇",
|
83 |
-
placeholder="Paste your Eleven Labs API key",
|
84 |
-
type="password")
|
85 |
-
|
86 |
-
set_api_key(user_api_key)
|
87 |
-
|
88 |
-
audio_file = st.file_uploader("Upload an audio file", type=["wav", "mp4", "mp3"])
|
89 |
-
if audio_file is not None:
|
90 |
-
output_file_path = "./output_audio.mp3"
|
91 |
-
save_uploaded_file_as_mp3(audio_file, output_file_path)
|
92 |
-
hindi_input_audio, sample_rate = librosa.load(output_file_path, sr=None, mono=True)
|
93 |
-
|
94 |
-
# Applying audio recognition
|
95 |
-
hindi_transcription = parse_transcription('./output_audio.mp3')
|
96 |
-
st.success(f"Audio file saved as {output_file_path}")
|
97 |
-
|
98 |
-
# Convert Hindi to English
|
99 |
-
english_input = hindi_to_english(hindi_transcription)
|
100 |
-
|
101 |
-
# Feeding the input to the LLM
|
102 |
-
english_output = conversational_chat(llm_chain, english_input)
|
103 |
-
|
104 |
-
# Convert English to Hindi
|
105 |
-
hin_output = translate_english_to_hindi(english_output)
|
106 |
-
|
107 |
-
# Getting the Hindi TTS
|
108 |
-
hindi_output_audio = hindi_tts(hin_output)
|
109 |
-
|
110 |
-
# Show original uploaded audio
|
111 |
-
st.audio(audio_file, format='audio/mp3')
|
112 |
-
|
113 |
-
# Show processed output audio
|
114 |
-
st.audio(hindi_output_audio, format='audio/mp3')
|
115 |
-
|
116 |
-
# st.markdown("---")
|
117 |
-
# # Add a new audio uploader for users to upload another audio file
|
118 |
-
# with st.form(key='my_form', clear_on_submit=True):
|
119 |
-
# audio_file_new = st.file_uploader("Upload another audio file", type=["wav", "mp4", "mp3"])
|
120 |
-
# submit_button = st.form_submit_button(label='Process and Play')
|
121 |
-
|
122 |
-
# if audio_file_new is not None and submit_button:
|
123 |
-
# output_file_path_new = "./output_audio_new.mp3"
|
124 |
-
# save_uploaded_file_as_mp3(audio_file_new, output_file_path_new)
|
125 |
-
# hindi_input_audio_new, sample_rate_new = librosa.load(output_file_path_new, sr=None, mono=True)
|
126 |
-
|
127 |
-
# # Applying audio recognition for the new file
|
128 |
-
# hindi_transcription_new = parse_transcription(output_file_path_new)
|
129 |
-
# st.success(f"Audio file saved as {output_file_path_new}")
|
130 |
-
|
131 |
-
# # Convert Hindi to English for the new file
|
132 |
-
# english_input_new = hindi_to_english(hindi_transcription_new)
|
133 |
-
|
134 |
-
# # Feeding the input to the LLM for the new file
|
135 |
-
# english_output_new = conversational_chat(llm_chain, english_input_new)
|
136 |
-
|
137 |
-
# # Convert English to Hindi for the new file
|
138 |
-
# hin_output_new = translate_english_to_hindi(english_output_new)
|
139 |
-
|
140 |
-
# # Getting the Hindi TTS for the new file
|
141 |
-
# hindi_output_audio_new = hindi_tts(hin_output_new)
|
142 |
-
|
143 |
-
# # Show original uploaded audio for the new file
|
144 |
-
# st.audio(audio_file_new, format='audio/mp3')
|
145 |
-
|
146 |
-
# # Show processed output audio for the new file
|
147 |
-
# st.audio(hindi_output_audio_new, format='audio/mp3')
|
148 |
if __name__ == '__main__':
|
149 |
ui()
|
150 |
|
151 |
|
152 |
|
|
|
153 |
|
154 |
|
155 |
|
|
|
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 |
|
130 |
|
131 |
|
132 |
+
|
133 |
|
134 |
|
135 |
|