assist / app.py
jlsotoh's picture
Update app.py
4ba798d
raw
history blame contribute delete
No virus
1.74 kB
# -*- 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)