projekt-rising-ai commited on
Commit
5d59bd9
·
1 Parent(s): 173d366

Rolled back changes from previous commit

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py CHANGED
@@ -9,7 +9,9 @@ import boto3
9
  import gradio as gr
10
  import requests
11
 
 
12
  import warnings
 
13
 
14
  from langchain import ConversationChain, LLMChain
15
 
@@ -71,9 +73,58 @@ PROMPT_TEMPLATE = PromptTemplate(
71
  POLLY_VOICE_DATA = PollyVoiceData()
72
  AZURE_VOICE_DATA = AzureVoiceData()
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  # Temporarily address Wolfram Alpha SSL certificate issue
75
  ssl._create_default_https_context = ssl._create_unverified_context
76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  # Pertains to Express-inator functionality
78
  def transform_text(desc, express_chain, num_words, formality,
79
  anticipation_level, joy_level, trust_level,
@@ -544,6 +595,9 @@ with gr.Blocks(css="css/custom_css.css", title="Expert Answer Demo") as block:
544
  translate_to_state = gr.State(TRANSLATE_TO_DEFAULT)
545
  literary_style_state = gr.State(LITERARY_STYLE_DEFAULT)
546
 
 
 
 
547
  # Pertains to question answering functionality
548
  embeddings_state = gr.State()
549
  qa_chain_state = gr.State()
 
9
  import gradio as gr
10
  import requests
11
 
12
+ # UNCOMMENT TO USE WHISPER
13
  import warnings
14
+ import whisper
15
 
16
  from langchain import ConversationChain, LLMChain
17
 
 
73
  POLLY_VOICE_DATA = PollyVoiceData()
74
  AZURE_VOICE_DATA = AzureVoiceData()
75
 
76
+ # Pertains to WHISPER functionality
77
+ WHISPER_DETECT_LANG = "Detect language"
78
+
79
+ # UNCOMMENT TO USE WHISPER
80
+ warnings.filterwarnings("ignore")
81
+ WHISPER_MODEL = whisper.load_model("tiny")
82
+ print("WHISPER_MODEL", WHISPER_MODEL)
83
+
84
+
85
+ # UNCOMMENT TO USE WHISPER
86
+ def transcribe(aud_inp, whisper_lang):
87
+ if aud_inp is None:
88
+ return ""
89
+ aud = whisper.load_audio(aud_inp)
90
+ aud = whisper.pad_or_trim(aud)
91
+ mel = whisper.log_mel_spectrogram(aud).to(WHISPER_MODEL.device)
92
+ _, probs = WHISPER_MODEL.detect_language(mel)
93
+ options = whisper.DecodingOptions()
94
+ if whisper_lang != WHISPER_DETECT_LANG:
95
+ whisper_lang_code = POLLY_VOICE_DATA.get_whisper_lang_code(whisper_lang)
96
+ options = whisper.DecodingOptions(language=whisper_lang_code)
97
+ result = whisper.decode(WHISPER_MODEL, mel, options)
98
+ print("result.text", result.text)
99
+ result_text = ""
100
+ if result and result.text:
101
+ result_text = result.text
102
+ return result_text
103
+
104
+
105
  # Temporarily address Wolfram Alpha SSL certificate issue
106
  ssl._create_default_https_context = ssl._create_unverified_context
107
 
108
+
109
+ # TEMPORARY FOR TESTING
110
+ def transcribe_dummy(aud_inp_tb, whisper_lang):
111
+ if aud_inp_tb is None:
112
+ return ""
113
+ # aud = whisper.load_audio(aud_inp)
114
+ # aud = whisper.pad_or_trim(aud)
115
+ # mel = whisper.log_mel_spectrogram(aud).to(WHISPER_MODEL.device)
116
+ # _, probs = WHISPER_MODEL.detect_language(mel)
117
+ # options = whisper.DecodingOptions()
118
+ # options = whisper.DecodingOptions(language="ja")
119
+ # result = whisper.decode(WHISPER_MODEL, mel, options)
120
+ result_text = "Whisper will detect language"
121
+ if whisper_lang != WHISPER_DETECT_LANG:
122
+ whisper_lang_code = POLLY_VOICE_DATA.get_whisper_lang_code(whisper_lang)
123
+ result_text = f"Whisper will use lang code: {whisper_lang_code}"
124
+ print("result_text", result_text)
125
+ return aud_inp_tb
126
+
127
+
128
  # Pertains to Express-inator functionality
129
  def transform_text(desc, express_chain, num_words, formality,
130
  anticipation_level, joy_level, trust_level,
 
595
  translate_to_state = gr.State(TRANSLATE_TO_DEFAULT)
596
  literary_style_state = gr.State(LITERARY_STYLE_DEFAULT)
597
 
598
+ # Pertains to WHISPER functionality
599
+ whisper_lang_state = gr.State(WHISPER_DETECT_LANG)
600
+
601
  # Pertains to question answering functionality
602
  embeddings_state = gr.State()
603
  qa_chain_state = gr.State()