Continue improving conversational agent
Browse files- app.py +37 -1
- requirements.txt +3 -2
app.py
CHANGED
|
@@ -13,6 +13,37 @@ from langchain.llms import OpenAI
|
|
| 13 |
news_api_key = os.environ["NEWS_API_KEY"]
|
| 14 |
tmdb_bearer_token = os.environ["TMDB_BEARER_TOKEN"]
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
def load_chain():
|
| 18 |
"""Logic for loading the chain you want to use should go here."""
|
|
@@ -100,11 +131,16 @@ with block:
|
|
| 100 |
chatbot = gr.Chatbot()
|
| 101 |
|
| 102 |
with gr.Row():
|
| 103 |
-
message = gr.Textbox(label="What's your
|
| 104 |
placeholder="What's the answer to life, the universe, and everything?",
|
| 105 |
lines=1)
|
| 106 |
submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
|
| 107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
gr.Examples(
|
| 109 |
examples=["How many people live in Canada?",
|
| 110 |
"What is 2 to the 30th power?",
|
|
|
|
| 13 |
news_api_key = os.environ["NEWS_API_KEY"]
|
| 14 |
tmdb_bearer_token = os.environ["TMDB_BEARER_TOKEN"]
|
| 15 |
|
| 16 |
+
import whisper
|
| 17 |
+
|
| 18 |
+
WHISPER_MODEL = whisper.load_model("tiny")
|
| 19 |
+
print("WHISPER_MODEL", WHISPER_MODEL)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def transcribe(aud_inp):
|
| 23 |
+
if aud_inp is None:
|
| 24 |
+
return ""
|
| 25 |
+
|
| 26 |
+
# load audio and pad/trim it to fit 30 seconds
|
| 27 |
+
aud = whisper.load_audio(aud_inp)
|
| 28 |
+
aud = whisper.pad_or_trim(aud)
|
| 29 |
+
|
| 30 |
+
# make log-Mel spectrogram and move to the same device as the model
|
| 31 |
+
mel = whisper.log_mel_spectrogram(aud).to(WHISPER_MODEL.device)
|
| 32 |
+
|
| 33 |
+
# detect the spoken language
|
| 34 |
+
_, probs = WHISPER_MODEL.detect_language(mel)
|
| 35 |
+
|
| 36 |
+
# decode the audio
|
| 37 |
+
options = whisper.DecodingOptions()
|
| 38 |
+
result = whisper.decode(WHISPER_MODEL, mel, options)
|
| 39 |
+
|
| 40 |
+
print("result.text", result.text)
|
| 41 |
+
|
| 42 |
+
result_text = ""
|
| 43 |
+
if result and result.text:
|
| 44 |
+
result_text = result.text
|
| 45 |
+
return result_text
|
| 46 |
+
|
| 47 |
|
| 48 |
def load_chain():
|
| 49 |
"""Logic for loading the chain you want to use should go here."""
|
|
|
|
| 131 |
chatbot = gr.Chatbot()
|
| 132 |
|
| 133 |
with gr.Row():
|
| 134 |
+
message = gr.Textbox(label="What's on your mind??",
|
| 135 |
placeholder="What's the answer to life, the universe, and everything?",
|
| 136 |
lines=1)
|
| 137 |
submit = gr.Button(value="Send", variant="secondary").style(full_width=False)
|
| 138 |
|
| 139 |
+
with gr.Row():
|
| 140 |
+
audio_comp = gr.Microphone(source="microphone", type="filepath", label="Just say it!",
|
| 141 |
+
interactive=True, streaming=False)
|
| 142 |
+
audio_comp.change(transcribe, inputs=[audio_comp], outputs=[message])
|
| 143 |
+
|
| 144 |
gr.Examples(
|
| 145 |
examples=["How many people live in Canada?",
|
| 146 |
"What is 2 to the 30th power?",
|
requirements.txt
CHANGED
|
@@ -2,5 +2,6 @@ openai==0.26.0
|
|
| 2 |
gradio==3.16.1
|
| 3 |
google-search-results
|
| 4 |
google-api-python-client
|
| 5 |
-
langchain==0.0.
|
| 6 |
-
requests~=2.28.1
|
|
|
|
|
|
| 2 |
gradio==3.16.1
|
| 3 |
google-search-results
|
| 4 |
google-api-python-client
|
| 5 |
+
langchain==0.0.59
|
| 6 |
+
requests~=2.28.1
|
| 7 |
+
git+https://github.com/openai/whisper.git
|