Commit
·
ac4c17a
1
Parent(s):
eb72da8
Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import openai
|
| 3 |
+
import pyttsx3
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
import os
|
| 6 |
+
load_dotenv()
|
| 7 |
+
|
| 8 |
+
openai.api_key = os.getenv("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")
|
| 9 |
+
|
| 10 |
+
messages=[
|
| 11 |
+
{"role": "system", "content": "You are a teacher"}
|
| 12 |
+
]
|
| 13 |
+
def transcribe(audio):
|
| 14 |
+
global messages
|
| 15 |
+
file = open(audio, "rb")
|
| 16 |
+
transcription = openai.Audio.transcribe("whisper-1", file)
|
| 17 |
+
print(transcription)
|
| 18 |
+
messages.append({"role": "user", "content": transcription["text"]})
|
| 19 |
+
response = openai.ChatCompletion.create(
|
| 20 |
+
model="gpt-3.5-turbo",
|
| 21 |
+
messages=messages
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
AImessage = response["choices"][0]["message"]["content"]
|
| 25 |
+
engine = pyttsx3.init()
|
| 26 |
+
engine.say(AImessage)
|
| 27 |
+
engine.runAndWait()
|
| 28 |
+
messages.append({"role": "assistant", "content": AImessage})
|
| 29 |
+
chat = ''
|
| 30 |
+
for message in messages:
|
| 31 |
+
if message["role"] != 'system':
|
| 32 |
+
chat += message["role"] + ':' + message["content"] + "\n\n"
|
| 33 |
+
return chat
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
ui = gr.Interface(fn=transcribe ,inputs=gr.Audio(source='microphone',type='filepath'), outputs='text')
|
| 37 |
+
|
| 38 |
+
ui.launch()
|