ysharma HF staff commited on
Commit
7a9df81
1 Parent(s): 8f045d7
Files changed (1) hide show
  1. app.py +21 -8
app.py CHANGED
@@ -15,14 +15,29 @@ HF_TOKEN = os.environ["HF_TOKEN"]
15
  headers = {"Authorization": f"Bearer {HF_TOKEN}"}
16
  #Language covered in Bloom : en, fr, esp, arb, hn, portu, Indonesian, Vietnamese, Chinese, tamil, telugu, bengali
17
 
 
 
 
 
18
  # Text-to-Speech
19
  LANGUAGES = list(CoquiTTS.langs.keys())
20
  print(f"Languages for Coqui are: {LANGUAGES}")
21
  #Languages for Coqui are: ['en', 'es', 'fr', 'de', 'pl', 'uk', 'ro', 'hu', 'el', 'bg', 'nl', 'fi', 'sl', 'lv', 'ga']
22
  coquiTTS = CoquiTTS()
23
 
 
 
 
 
 
 
 
 
 
 
24
  # Whisper - speeech-to-text
25
  def whisper_stt(audio):
 
26
  # load audio and pad/trim it to fit 30 seconds
27
  audio = whisper.load_audio(audio)
28
  audio = whisper.pad_or_trim(audio)
@@ -41,19 +56,16 @@ def whisper_stt(audio):
41
 
42
  # print the recognized text
43
  print(f"transcript is : {result.text}")
44
- return result.text
45
 
46
- # Driver function
47
- def fun_engine(audio) :
48
- text1 = whisper_stt(audio)
49
- #text1 = model.transcribe(audio)["text"]
50
- text2 = lang_model_response(text1)
51
- speech = tts(text2, 'en')
52
- return text1, text2, speech
53
 
54
  # LLM - Bloom Response
55
  def lang_model_response(prompt):
56
  print(f"*****Inside lang_model_response - Prompt is :{prompt}")
 
 
 
 
57
  if len(prompt) == 0:
58
  prompt = """Can you help me please?"""
59
 
@@ -82,6 +94,7 @@ def lang_model_response(prompt):
82
 
83
  # Coqui - Text-to-Speech
84
  def tts(text, language):
 
85
  with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
86
  coquiTTS.get_tts(text, fp, speaker = {"language" : language})
87
  return fp.name
 
15
  headers = {"Authorization": f"Bearer {HF_TOKEN}"}
16
  #Language covered in Bloom : en, fr, esp, arb, hn, portu, Indonesian, Vietnamese, Chinese, tamil, telugu, bengali
17
 
18
+ prompt = """Instruction: Given a Statement, produce a response in one sentence.
19
+ Statement:
20
+ """
21
+
22
  # Text-to-Speech
23
  LANGUAGES = list(CoquiTTS.langs.keys())
24
  print(f"Languages for Coqui are: {LANGUAGES}")
25
  #Languages for Coqui are: ['en', 'es', 'fr', 'de', 'pl', 'uk', 'ro', 'hu', 'el', 'bg', 'nl', 'fi', 'sl', 'lv', 'ga']
26
  coquiTTS = CoquiTTS()
27
 
28
+
29
+ # Driver function
30
+ def fun_engine(audio) :
31
+ text1, lang = whisper_stt(audio)
32
+ #text1 = model.transcribe(audio)["text"]
33
+ text2 = lang_model_response(text1)
34
+ speech = tts(text2, lang) #'en')
35
+ return text1, text2, speech
36
+
37
+
38
  # Whisper - speeech-to-text
39
  def whisper_stt(audio):
40
+ print("Inside Whisper TTS")
41
  # load audio and pad/trim it to fit 30 seconds
42
  audio = whisper.load_audio(audio)
43
  audio = whisper.pad_or_trim(audio)
 
56
 
57
  # print the recognized text
58
  print(f"transcript is : {result.text}")
59
+ return result.text, lang
60
 
 
 
 
 
 
 
 
61
 
62
  # LLM - Bloom Response
63
  def lang_model_response(prompt):
64
  print(f"*****Inside lang_model_response - Prompt is :{prompt}")
65
+ p = """Instruction: Given a Statement, produce a Response in one sentence.
66
+ Statement: """
67
+ prompt = p + prompt + "\n" + "Response: "
68
+
69
  if len(prompt) == 0:
70
  prompt = """Can you help me please?"""
71
 
 
94
 
95
  # Coqui - Text-to-Speech
96
  def tts(text, language):
97
+ print(f"Inside tts - language is : {language}")
98
  with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
99
  coquiTTS.get_tts(text, fp, speaker = {"language" : language})
100
  return fp.name