Spaces:
Runtime error
Runtime error
import gradio as gr | |
import time | |
import whisper | |
import cohere | |
#from dotenv import load_dotenv | |
#load_dotenv() | |
co = cohere.Client('0brA5yZUeNlQM98z5h4XQAiYYpCGNMbGPjk5ghE6') | |
model = whisper.load_model("tiny") | |
def transcribe(audio): | |
#time.sleep(3) | |
# 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) | |
print(f"Detected language: {max(probs, key=probs.get)}") | |
# decode the audio | |
options = whisper.DecodingOptions(fp16 = False) | |
result = whisper.decode(model, mel, options) | |
#cohere | |
response = co.generate( | |
model='xlarge', | |
prompt=f'This program will generate an introductory paragraph to a blog post given a blog title, audience, and tone of voice.\n--\nBlog Title: Best Activities in Toronto\nAudience: Millennials\nTone of Voice: Lighthearted\nFirst Paragraph: Looking for fun things to do in Toronto? When it comes to exploring Canada\'s largest city, there\'s an ever-evolving set of activities to choose from. Whether you\'re looking to visit a local museum or sample the city\'s varied cuisine, there is plenty to fill any itinerary. In this blog post, I\'ll share some of my favorite recommendations\n--\nBlog Title: Mastering Dynamic Programming\nAudience: Developers\nTone: Informative\nFirst Paragraph: In this piece, we\'ll help you understand the fundamentals of dynamic programming, and when to apply this optimization technique. We\'ll break down bottom-up and top-down approaches to solve dynamic programming problems.\n--\nBlog Title: {result.text}\nAudience: Athletes\nTone: Enthusiastic\nFirst Paragraph:', | |
max_tokens=100, | |
temperature=0.8, | |
k=0, | |
p=1, | |
frequency_penalty=0, | |
presence_penalty=0, | |
stop_sequences=["--"], | |
return_likelihoods='NONE') | |
#result.text | |
reptxt = response.generations[0].text.strip("--") | |
return reptxt | |
gr.Interface( | |
title = 'OpenAI Whisper ASR Gradio Web UI', | |
fn=transcribe, | |
inputs=[ | |
gr.inputs.Audio(source="microphone", type="filepath") | |
], | |
outputs=[ | |
"textbox" | |
], | |
live=True).launch() |