File size: 1,270 Bytes
842813f
 
 
 
 
 
 
 
3dd31a3
df53555
842813f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28a8f11
 
842813f
 
 
 
 
 
7e4a9d7
842813f
 
 
 
 
3dd31a3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import whisper
import gradio as gr 
import time
from pyChatGPT import ChatGPT
import warnings

model = whisper.load_model("base")

#print(model.device)

def transcribe(audio):

    # load audio and pad/trim it to fit 30 seconds
    audio = whisper.load_audio(audio)
    audio = whisper.pad_or_trim(audio)

    # make log-Mel spectrogram and move to the same device as the model
    mel = whisper.log_mel_spectrogram(audio).to(model.device)

    # detect the spoken language
    _, probs = model.detect_language(mel)

    # decode the audio
    options = whisper.DecodingOptions()
    result = whisper.decode(model, mel, options)
    result_text = result.text

    # Pass the generated text to Audio
    chatgpt_api = ChatGPT(email='bratanmol@gmail.com', password='vq3!a^iRKr')
    resp = chatgpt_api.send_message(result_text)
    out_result = resp['message']

    return [result_text, out_result]

output_1 = gr.outputs.Textbox(label="Speech to Text")
output_2 = gr.outputs.Textbox(label="ChatGPT Output")


gr.Interface(
    title = 'OpenAI Whisper and ChatGPT ASR Gradio Web UI', 
    fn=transcribe, 
    inputs=[
        gr.inputs.Audio(source="microphone", type="filepath")
    ],

    outputs=[
        output_1,  output_2
    ],
    live=True).launch(inline=False)