Spaces:
Sleeping
Sleeping
mj-new
commited on
Commit
•
62adb55
1
Parent(s):
fb57ff3
Replaced domain with project name
Browse files
app.py
CHANGED
@@ -44,10 +44,10 @@ def get_unique_name():
|
|
44 |
return ''.join([random.choice(string.ascii_letters
|
45 |
+ string.digits) for n in range(32)])
|
46 |
|
47 |
-
def get_prompts(
|
48 |
-
print(f"Retrieving prompts for
|
49 |
size = int(size)
|
50 |
-
promptset = dict_promptset[
|
51 |
prompts_left_info = size
|
52 |
return(promptset, promptset[0],prompts_left_info)
|
53 |
|
@@ -55,6 +55,10 @@ def save_recording_and_meta(project_name, recording, prompt_text, language_code,
|
|
55 |
#, name, age, gender):
|
56 |
# TODO save user data in the next version
|
57 |
|
|
|
|
|
|
|
|
|
58 |
speaker_metadata={}
|
59 |
speaker_metadata['name'] = spk_name if spk_name !='' else 'unknown'
|
60 |
speaker_metadata['gender'] = spk_gender if spk_gender !='' else 'unknown'
|
@@ -92,6 +96,7 @@ def save_recording_and_meta(project_name, recording, prompt_text, language_code,
|
|
92 |
metadata= {'id':uuid_name,
|
93 |
'audio_file': audio_fn,
|
94 |
'language_code':language_code,
|
|
|
95 |
'prompt':prompt_text,
|
96 |
'name': speaker_metadata['name'],
|
97 |
'age': speaker_metadata['age'],
|
@@ -126,12 +131,8 @@ def save_recording_and_meta(project_name, recording, prompt_text, language_code,
|
|
126 |
|
127 |
output = print(f"Recording {audio_fn} and meta file {meta_fn} successfully saved to repo!")
|
128 |
|
129 |
-
#
|
130 |
-
|
131 |
-
if prompt_number == None:
|
132 |
-
prompt_number = 1
|
133 |
-
else:
|
134 |
-
prompt_number = prompt_number + 1
|
135 |
|
136 |
# check if this is the last prompt
|
137 |
if prompt_number == len(promptset):
|
@@ -215,8 +216,9 @@ block = gr.Blocks(css=css_file)
|
|
215 |
with block:
|
216 |
|
217 |
#state variables
|
|
|
|
|
218 |
language_code = gr.State("pl")
|
219 |
-
domain = gr.State()
|
220 |
prompts_type = gr.State()
|
221 |
promptset = gr.State("test.prompts.txt")
|
222 |
prompt_history = gr.State()
|
@@ -231,7 +233,6 @@ with block:
|
|
231 |
openai_api_key = gr.State()
|
232 |
google_api_key = gr.State()
|
233 |
azure_api_key = gr.State()
|
234 |
-
project_name = gr.State("voicebot") # TODO add list of projects to organize saved data
|
235 |
|
236 |
spk_age = gr.State("unknown")
|
237 |
spk_accent = gr.State("unknown")
|
@@ -243,11 +244,11 @@ with block:
|
|
243 |
|
244 |
|
245 |
# state handling functions
|
246 |
-
def
|
247 |
-
print("Changing
|
248 |
print(choice)
|
249 |
-
|
250 |
-
return(
|
251 |
|
252 |
def change_prompts_type(choice):
|
253 |
print("Changing promptset type to")
|
@@ -376,7 +377,8 @@ with block:
|
|
376 |
# Events actions
|
377 |
button_save_audio_and_trans.click(save_recording_and_meta, inputs=[project_name, mic_recording, out_asr, language_code, spk_age, spk_accent, spk_city, spk_gender, spk_nativity], outputs=[])
|
378 |
button_transcribe.click(transcribe, inputs=[mic_recording, language_code, whisper_model,whisper_model_type], outputs=out_asr)
|
379 |
-
button_prompt_gpt.click(
|
|
|
380 |
button_synth_speech.click(synthesize_speech, inputs=[out_gpt, language_code], outputs=synth_recording)
|
381 |
|
382 |
radio_lang.change(fn=change_language, inputs=radio_lang, outputs=language_code)
|
@@ -385,7 +387,7 @@ with block:
|
|
385 |
with gr.TabItem('Speech recordings app'):
|
386 |
|
387 |
with gr.Accordion(label="Promptset settings"):
|
388 |
-
|
389 |
#radio_promptset_type = gr.Radio(["New promptset generation", "Existing promptset use"], label="Language", value ="Existing promptset use", info="New promptset is generated using. Requires providing open AI key in general settings tab")
|
390 |
var_promptset_size = gr.Textbox(label="How many recordings you want to make? (max 200)")
|
391 |
button_get_prompts = gr.Button("Save settings and get a first prompt")
|
@@ -394,13 +396,13 @@ with block:
|
|
394 |
prompt_text = gr.Textbox(placeholder='Prompt to read during recording',label="Prompt to be read during recording")
|
395 |
speech_recording = gr.Audio(source="microphone",label="Select 'record from microphone' and read the prompt displayed above", type="filepath")
|
396 |
|
397 |
-
|
398 |
#radio_promptset_type.change(fn=change_prompts_type, inputs=radio_promptset_type, outputs=prompts_type)
|
399 |
#prompts_left.change(change_prompts_left, inputs = [prompts_left, current_prompt, var_promptset_size], outputs = [prompts_left])
|
400 |
|
401 |
button_save_and_next = gr.Button("Save recording and get the next prompt")
|
402 |
-
# TODO - add option to generate new promptset on the fly for new
|
403 |
-
button_get_prompts.click(get_prompts, inputs=[
|
404 |
|
405 |
button_save_and_next.click(save_recording_and_meta, inputs=[project_name, speech_recording, prompt_text, language_code, spk_name, spk_age, spk_accent, spk_city, spk_gender, spk_nativity, promptset, prompt_number, prompts_left_info], outputs=[prompt_text, prompt_number, speech_recording,prompts_left_info])
|
406 |
|
|
|
44 |
return ''.join([random.choice(string.ascii_letters
|
45 |
+ string.digits) for n in range(32)])
|
46 |
|
47 |
+
def get_prompts(project_name, size, language_code,prompts_left_info):
|
48 |
+
print(f"Retrieving prompts for project {project_name} with method: {type} for language_code {language_code} of size {size}")
|
49 |
size = int(size)
|
50 |
+
promptset = dict_promptset[project_name][0:size]
|
51 |
prompts_left_info = size
|
52 |
return(promptset, promptset[0],prompts_left_info)
|
53 |
|
|
|
55 |
#, name, age, gender):
|
56 |
# TODO save user data in the next version
|
57 |
|
58 |
+
# check if prompt number is set
|
59 |
+
if prompt_number == None:
|
60 |
+
prompt_number = 1
|
61 |
+
|
62 |
speaker_metadata={}
|
63 |
speaker_metadata['name'] = spk_name if spk_name !='' else 'unknown'
|
64 |
speaker_metadata['gender'] = spk_gender if spk_gender !='' else 'unknown'
|
|
|
96 |
metadata= {'id':uuid_name,
|
97 |
'audio_file': audio_fn,
|
98 |
'language_code':language_code,
|
99 |
+
'prompt_number':prompt_number,
|
100 |
'prompt':prompt_text,
|
101 |
'name': speaker_metadata['name'],
|
102 |
'age': speaker_metadata['age'],
|
|
|
131 |
|
132 |
output = print(f"Recording {audio_fn} and meta file {meta_fn} successfully saved to repo!")
|
133 |
|
134 |
+
# increment prompt number
|
135 |
+
prompt_number = prompt_number + 1
|
|
|
|
|
|
|
|
|
136 |
|
137 |
# check if this is the last prompt
|
138 |
if prompt_number == len(promptset):
|
|
|
216 |
with block:
|
217 |
|
218 |
#state variables
|
219 |
+
project_name = gr.State("voicebot") # voicebot is default for playground. For recording app, it is selected e.g. bridge
|
220 |
+
|
221 |
language_code = gr.State("pl")
|
|
|
222 |
prompts_type = gr.State()
|
223 |
promptset = gr.State("test.prompts.txt")
|
224 |
prompt_history = gr.State()
|
|
|
233 |
openai_api_key = gr.State()
|
234 |
google_api_key = gr.State()
|
235 |
azure_api_key = gr.State()
|
|
|
236 |
|
237 |
spk_age = gr.State("unknown")
|
238 |
spk_accent = gr.State("unknown")
|
|
|
244 |
|
245 |
|
246 |
# state handling functions
|
247 |
+
def change_project(choice):
|
248 |
+
print("Changing project to")
|
249 |
print(choice)
|
250 |
+
project=choice
|
251 |
+
return(project)
|
252 |
|
253 |
def change_prompts_type(choice):
|
254 |
print("Changing promptset type to")
|
|
|
377 |
# Events actions
|
378 |
button_save_audio_and_trans.click(save_recording_and_meta, inputs=[project_name, mic_recording, out_asr, language_code, spk_age, spk_accent, spk_city, spk_gender, spk_nativity], outputs=[])
|
379 |
button_transcribe.click(transcribe, inputs=[mic_recording, language_code, whisper_model,whisper_model_type], outputs=out_asr)
|
380 |
+
button_prompt_gpt.click(prompt "dates":["20230922"],
|
381 |
+
"speakers":["Test"]_gpt_assistant, inputs=[out_asr, openai_api_key, slider_temp], outputs=out_gpt)
|
382 |
button_synth_speech.click(synthesize_speech, inputs=[out_gpt, language_code], outputs=synth_recording)
|
383 |
|
384 |
radio_lang.change(fn=change_language, inputs=radio_lang, outputs=language_code)
|
|
|
387 |
with gr.TabItem('Speech recordings app'):
|
388 |
|
389 |
with gr.Accordion(label="Promptset settings"):
|
390 |
+
radio_project = gr.Dropdown(["bridge"], label="Select project", info="")
|
391 |
#radio_promptset_type = gr.Radio(["New promptset generation", "Existing promptset use"], label="Language", value ="Existing promptset use", info="New promptset is generated using. Requires providing open AI key in general settings tab")
|
392 |
var_promptset_size = gr.Textbox(label="How many recordings you want to make? (max 200)")
|
393 |
button_get_prompts = gr.Button("Save settings and get a first prompt")
|
|
|
396 |
prompt_text = gr.Textbox(placeholder='Prompt to read during recording',label="Prompt to be read during recording")
|
397 |
speech_recording = gr.Audio(source="microphone",label="Select 'record from microphone' and read the prompt displayed above", type="filepath")
|
398 |
|
399 |
+
radio_project.change(fn=change_project, inputs=radio_project, outputs=project_name)
|
400 |
#radio_promptset_type.change(fn=change_prompts_type, inputs=radio_promptset_type, outputs=prompts_type)
|
401 |
#prompts_left.change(change_prompts_left, inputs = [prompts_left, current_prompt, var_promptset_size], outputs = [prompts_left])
|
402 |
|
403 |
button_save_and_next = gr.Button("Save recording and get the next prompt")
|
404 |
+
# TODO - add option to generate new promptset on the fly for new projects
|
405 |
+
button_get_prompts.click(get_prompts, inputs=[radio_project, var_promptset_size, language_code, prompts_left_info], outputs = [promptset, prompt_text, prompts_left_info])
|
406 |
|
407 |
button_save_and_next.click(save_recording_and_meta, inputs=[project_name, speech_recording, prompt_text, language_code, spk_name, spk_age, spk_accent, spk_city, spk_gender, spk_nativity, promptset, prompt_number, prompts_left_info], outputs=[prompt_text, prompt_number, speech_recording,prompts_left_info])
|
408 |
|