Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import openai
|
| 3 |
import os
|
| 4 |
openai.api_key= os.environ.get("openai.api_key")
|
| 5 |
|
| 6 |
messages = [{"role": "system", "content": 'You are Python ML developer. reply only in python code'}]
|
| 7 |
|
| 8 |
-
def transcribe(
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
response = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=messages)
|
| 13 |
|
| 14 |
system_message = response["choices"][0]["message"]
|
| 15 |
messages.append(system_message)
|
| 16 |
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
chat_transcript = ""
|
|
@@ -23,4 +30,4 @@ def transcribe(text):
|
|
| 23 |
|
| 24 |
return chat_transcript
|
| 25 |
|
| 26 |
-
ui = gr.Interface(fn=transcribe, inputs="
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import openai,subprocess
|
| 3 |
import os
|
| 4 |
openai.api_key= os.environ.get("openai.api_key")
|
| 5 |
|
| 6 |
messages = [{"role": "system", "content": 'You are Python ML developer. reply only in python code'}]
|
| 7 |
|
| 8 |
+
def transcribe(audio):
|
| 9 |
+
global message
|
| 10 |
+
audio_filename_with_extension = audio + '.wav'
|
| 11 |
+
os.rename(audio, audio_filename_with_extension)
|
| 12 |
|
| 13 |
+
audio_file = open(audio_filename_with_extension, "rb")
|
| 14 |
+
transcript = openai.Audio.transcribe("whisper-1", audio_file)
|
| 15 |
+
|
| 16 |
+
messages.append({"role": "user", "content": transcript["text"]})
|
| 17 |
|
| 18 |
response = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=messages)
|
| 19 |
|
| 20 |
system_message = response["choices"][0]["message"]
|
| 21 |
messages.append(system_message)
|
| 22 |
|
| 23 |
+
subprocess.call(["say", system_message['content']])
|
| 24 |
|
| 25 |
|
| 26 |
chat_transcript = ""
|
|
|
|
| 30 |
|
| 31 |
return chat_transcript
|
| 32 |
|
| 33 |
+
ui = gr.Interface(fn=transcribe, inputs=gr.audio(source="microphone",type="filepath"), outputs="text").launch()
|