Spaces:
Sleeping
Sleeping
heliosbrahma
commited on
Commit
·
c33ad65
1
Parent(s):
6a33919
first commit
Browse files- README.md +8 -2
- main.py +51 -0
- requirements.txt +6 -0
README.md
CHANGED
@@ -5,8 +5,14 @@ colorFrom: gray
|
|
5 |
colorTo: gray
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.23.0
|
8 |
-
app_file:
|
9 |
pinned: false
|
10 |
---
|
|
|
|
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
5 |
colorTo: gray
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.23.0
|
8 |
+
app_file: main.py
|
9 |
pinned: false
|
10 |
---
|
11 |
+
# Smart Voice Assistant
|
12 |
+
Use this gradio app interface to get answers for all your queries in both text and speech format. Just communicate your queries in speech format and this app will take care of the rest.
|
13 |
|
14 |
+
This app is built using ChatGPT API and Whisper API.
|
15 |
+
|
16 |
+
## To generate OpenAI API key:
|
17 |
+
* Login to https://platform.openai.com/account/api-keys
|
18 |
+
* Click on "Create new secret key" button and copy the API key
|
main.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import whisper
|
2 |
+
import gradio as gr
|
3 |
+
import openai
|
4 |
+
from TTS.api import TTS
|
5 |
+
import subprocess
|
6 |
+
|
7 |
+
model_name = TTS.list_models()[9]
|
8 |
+
tts = TTS(model_name)
|
9 |
+
model = whisper.load_model('medium')
|
10 |
+
|
11 |
+
def run_ffmpeg_command():
|
12 |
+
command = ['ffmpeg', '-f', 'lavfi', '-i', 'anullsrc=r=44100:cl=mono', '-t', '1', '-q:a', '9', '-acodec', 'libmp3lame', 'output.wav']
|
13 |
+
result = subprocess.run(command, capture_output=True, text=True)
|
14 |
+
print(result.stdout)
|
15 |
+
|
16 |
+
|
17 |
+
def voice_chat(api_key, user_voice):
|
18 |
+
openai.api_key = str(api_key)
|
19 |
+
messages = [
|
20 |
+
{"role": "system", "content": "You are a kind helpful assistant."},
|
21 |
+
]
|
22 |
+
|
23 |
+
user_message = model.transcribe(user_voice)["text"]
|
24 |
+
messages.append(
|
25 |
+
{"role": "user", "content": user_message},
|
26 |
+
)
|
27 |
+
|
28 |
+
chat = openai.ChatCompletion.create(
|
29 |
+
model="gpt-3.5-turbo", messages=messages
|
30 |
+
)
|
31 |
+
reply = chat.choices[0].message.content
|
32 |
+
|
33 |
+
messages.append({"role": "assistant", "content": reply})
|
34 |
+
tts.tts_to_file(text=reply, file_path="output.wav")
|
35 |
+
return(reply, "output.wav")
|
36 |
+
|
37 |
+
# run_ffmpeg_command()
|
38 |
+
text_reply = gr.Textbox(label="Summarized Answer")
|
39 |
+
voice_reply = gr.Audio(type="filepath")
|
40 |
+
|
41 |
+
gr.Interface(
|
42 |
+
title = 'Smart Voice Assistant',
|
43 |
+
fn=voice_chat,
|
44 |
+
inputs=[
|
45 |
+
gr.Textbox(label="OpenAI API Key"),
|
46 |
+
gr.Audio(source="microphone", type="filepath")
|
47 |
+
|
48 |
+
],
|
49 |
+
outputs=[
|
50 |
+
text_reply, voice_reply
|
51 |
+
]).launch()
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
numpy==1.21.6
|
2 |
+
numba==0.53
|
3 |
+
TTS
|
4 |
+
openai-whisper
|
5 |
+
openai
|
6 |
+
gradio
|