ysharma HF staff commited on
Commit
d296e9c
1 Parent(s): 4946ad9
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -38,10 +38,13 @@ coquiTTS = CoquiTTS()
38
 
39
 
40
  # Driver function
41
- def driver_fun(audio) :
42
-
43
- translation, lang = whisper_stt(audio)
44
 
 
 
 
 
 
45
  random_val = random.randrange(0,231657)
46
  if random_val < 226657:
47
  lower_limit = random_val
@@ -51,7 +54,7 @@ def driver_fun(audio) :
51
  upper_limit = random_val
52
  print(f"lower_limit : upper_limit = {lower_limit} : {upper_limit}")
53
  dataset_subset = filtered_dataset['Joke'][lower_limit : upper_limit]
54
- data = query({"inputs": {"source_sentence": "That is a happy person","sentences": dataset_subset} } )
55
  if 'error' in data:
56
  print(f"Error is : {data}")
57
  return 'Error in model inference - Run Again Please', 'Error in model inference - Run Again Please', None
@@ -112,10 +115,11 @@ with demo:
112
  out_transcript = gr.Textbox(label= 'Transcript of your Audio using OpenAI Whisper')
113
 
114
  with gr.Column():
 
115
  out_audio = gr.Audio(label='Audio response form CoquiTTS')
116
  out_generated_joke = gr.Textbox(label= 'Joke returned! ')
117
 
118
- b1.click(driver_fun,inputs=[in_audio], outputs=[out_transcript, out_generated_joke, out_audio]) #out_translation_en, out_generated_text,out_generated_text_en,
119
  with gr.Row():
120
  gr.Markdown(
121
  """Model pipeline consisting of - <br>- [**Whisper**](https://github.com/openai/whisper) for Speech-to-text, <br>- [**CoquiTTS**](https://huggingface.co/coqui) for Text-To-Speech.<br>- [Sentence Transformers](https://huggingface.co/models?library=sentence-transformers&sort=downloads)<br>- Front end is built using [**Gradio Block API**](https://gradio.app/docs/#blocks).<br><be>If you want to reuse the App, simply click on the small cross button in the top right corner of your voice record panel, and then press record again! <br><br> Few Caveats:<br>1. Please note that sometimes the joke might be NSFW. Although, I have tried putting in filters to not have that experience, but they seem non-exhaustive.<br>2. Sometimes the joke might not match your theme, please bear with the limited capabilities of free open-source ML prototypes.<br>3. Much like real life, sometimes the joke might just not land, haha!<br>4. If you see the message 'Error in model inference - Run Again Please', just press the button again every time!
 
38
 
39
 
40
  # Driver function
41
+ def driver_fun(audio, text) :
 
 
42
 
43
+ if text == 'dummy':
44
+ translation, lang = whisper_stt(audio)
45
+ else:
46
+ translation = text
47
+
48
  random_val = random.randrange(0,231657)
49
  if random_val < 226657:
50
  lower_limit = random_val
 
54
  upper_limit = random_val
55
  print(f"lower_limit : upper_limit = {lower_limit} : {upper_limit}")
56
  dataset_subset = filtered_dataset['Joke'][lower_limit : upper_limit]
57
+ data = query({"inputs": {"source_sentence": translation ,"sentences": dataset_subset} } ) #"That is a happy person"
58
  if 'error' in data:
59
  print(f"Error is : {data}")
60
  return 'Error in model inference - Run Again Please', 'Error in model inference - Run Again Please', None
 
115
  out_transcript = gr.Textbox(label= 'Transcript of your Audio using OpenAI Whisper')
116
 
117
  with gr.Column():
118
+ in_text = gr.Textbox(label='Or enter any text here..', value='dummy')
119
  out_audio = gr.Audio(label='Audio response form CoquiTTS')
120
  out_generated_joke = gr.Textbox(label= 'Joke returned! ')
121
 
122
+ b1.click(driver_fun,inputs=[in_audio, in_text], outputs=[out_transcript, out_generated_joke, out_audio]) #out_translation_en, out_generated_text,out_generated_text_en,
123
  with gr.Row():
124
  gr.Markdown(
125
  """Model pipeline consisting of - <br>- [**Whisper**](https://github.com/openai/whisper) for Speech-to-text, <br>- [**CoquiTTS**](https://huggingface.co/coqui) for Text-To-Speech.<br>- [Sentence Transformers](https://huggingface.co/models?library=sentence-transformers&sort=downloads)<br>- Front end is built using [**Gradio Block API**](https://gradio.app/docs/#blocks).<br><be>If you want to reuse the App, simply click on the small cross button in the top right corner of your voice record panel, and then press record again! <br><br> Few Caveats:<br>1. Please note that sometimes the joke might be NSFW. Although, I have tried putting in filters to not have that experience, but they seem non-exhaustive.<br>2. Sometimes the joke might not match your theme, please bear with the limited capabilities of free open-source ML prototypes.<br>3. Much like real life, sometimes the joke might just not land, haha!<br>4. If you see the message 'Error in model inference - Run Again Please', just press the button again every time!