ysharma HF staff commited on
Commit
ee1afde
1 Parent(s): b068279
Files changed (1) hide show
  1. app.py +19 -17
app.py CHANGED
@@ -22,10 +22,10 @@ coquiTTS = CoquiTTS()
22
 
23
 
24
  # Driver function
25
- def fun_engine(audio) :
26
  text1, lang = whisper_stt(audio)
27
  #text1 = model.transcribe(audio)["text"]
28
- text2 = lang_model_response(text1)
29
  speech = tts(text2, lang) #'en')
30
  return text1, text2, speech
31
 
@@ -55,16 +55,17 @@ def whisper_stt(audio):
55
 
56
 
57
  # LLM - Bloom Response
58
- def lang_model_response(prompt):
59
  print(f"*****Inside lang_model_response - Prompt is :{prompt}")
60
  p = """Question: How are you doing today?
61
  Answer: I am doing good, thanks.
62
  Question: """
63
- prompt = p + prompt + "\n" + "Answer: "
64
- #prompt = prompt + "\n"
65
-
66
  if len(prompt) == 0:
67
- prompt = """Can you help me please?"""
 
 
 
 
68
 
69
  json_ = {"inputs": prompt,
70
  "parameters":
@@ -80,27 +81,28 @@ def lang_model_response(prompt):
80
  "wait_for_model": True,
81
  },}
82
  response = requests.post(API_URL, headers=headers, json=json_)
83
- print(f"Response is : {response}")
84
  output = response.json()
85
- #print(f"output is : {output}")
86
  output_tmp = output[0]['generated_text']
87
- print(f"output_tmp is: {output_tmp}")
88
  solution = output_tmp.split("Answer: ")[2].split("\n")[0]
89
-
90
- print(f"Final response after splits is: {solution}")
91
  return solution
92
 
93
  # Coqui - Text-to-Speech
94
  def tts(text, language):
95
- print(f"Inside tts - language is : {language}")
96
- with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
97
- coquiTTS.get_tts(text, fp, speaker = {"language" : language})
98
- return fp.name
 
 
 
99
 
100
 
101
  gr.Interface(
102
  title = 'Testing Whisper',
103
- fn=fun_engine,
104
  inputs=[
105
  gr.Audio(source="microphone", type="filepath"), #streaming = True,
106
  # "state"
 
22
 
23
 
24
  # Driver function
25
+ def driver_fun(audio) :
26
  text1, lang = whisper_stt(audio)
27
  #text1 = model.transcribe(audio)["text"]
28
+ text2 = lang_model_response(text1, lang)
29
  speech = tts(text2, lang) #'en')
30
  return text1, text2, speech
31
 
 
55
 
56
 
57
  # LLM - Bloom Response
58
+ def lang_model_response(prompt, language):
59
  print(f"*****Inside lang_model_response - Prompt is :{prompt}")
60
  p = """Question: How are you doing today?
61
  Answer: I am doing good, thanks.
62
  Question: """
 
 
 
63
  if len(prompt) == 0:
64
+ prompt = """Question: Can you help me please?
65
+ Answer: Sure, I am here for you.
66
+ Question: """
67
+
68
+ prompt = p + prompt + "\n" + "Answer: "
69
 
70
  json_ = {"inputs": prompt,
71
  "parameters":
 
81
  "wait_for_model": True,
82
  },}
83
  response = requests.post(API_URL, headers=headers, json=json_)
84
+ #print(f"Response is : {response}")
85
  output = response.json()
 
86
  output_tmp = output[0]['generated_text']
87
+ print(f"Bloom API Response is : {output_tmp}")
88
  solution = output_tmp.split("Answer: ")[2].split("\n")[0]
89
+ print(f"Final Bloom Response after splits is: {solution}")
 
90
  return solution
91
 
92
  # Coqui - Text-to-Speech
93
  def tts(text, language):
94
+ print(f"Inside tts - language is : {language}")
95
+ coqui_langs = ['en' ,'es' ,'fr' ,'de' ,'pl' ,'uk' ,'ro' ,'hu' ,'bg' ,'nl' ,'fi' ,'sl' ,'lv' ,'ga']
96
+ if language not in coqui_langs:
97
+ language = 'en'
98
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
99
+ coquiTTS.get_tts(text, fp, speaker = {"language" : language})
100
+ return fp.name
101
 
102
 
103
  gr.Interface(
104
  title = 'Testing Whisper',
105
+ fn=driver_fun,
106
  inputs=[
107
  gr.Audio(source="microphone", type="filepath"), #streaming = True,
108
  # "state"