File size: 1,740 Bytes
7bfbd68
be507c1
 
 
46d260b
 
be507c1
 
 
 
 
 
1e9bb11
 
7fe0a3f
e8c8755
be507c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e8c8755
be507c1
d715d72
e8c8755
7ec45c0
be507c1
 
46d260b
 
 
 
d8b0ac1
 
 
 
 
 
 
4ba798d
46d260b
be507c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7fe0a3f
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# -*- coding: utf-8 -*-
import whisper
import gradio as gr
import time
# from pyChatGPT import ChatGPT
import openai
import warnings

"""Variables"""

warnings.filterwarnings("ignore")

# secret_token = "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"
secret_token = "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"

model = whisper.load_model("small")


"""Transcribe function"""


def transcribe(audio):

    # load audio and pad/trim if 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(fp16=False)
    result = whisper.decode(model, mel, options)

    print(result.text)
    result_text = result.text

    # Pass the generated text to audio
    # chatgpt_api = ChatGPT(secret_token)
    # resp = chatgpt_api.send_message(result_text)
    # out_result = resp['message']

    #openai.api_key = secret_token
    #response = openai.Completion.create(
    #    engine="text-davinci-003",
    #    prompt=result_text,
    #    max_tokens=1024
    #)
    #result = response["choices"][0]["text"]
    result = ""
    return [result_text, result]


"""Gradio Interface"""

# @title
output_1 = gr.Textbox(label="Speech to Text")
output_2 = gr.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(debug=True)