Spaces:
Runtime error
Runtime error
init!
Browse files
app.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import time
|
3 |
+
import whisper
|
4 |
+
import cohere
|
5 |
+
#from dotenv import load_dotenv
|
6 |
+
|
7 |
+
#load_dotenv()
|
8 |
+
co = cohere.Client('0brA5yZUeNlQM98z5h4XQAiYYpCGNMbGPjk5ghE6')
|
9 |
+
|
10 |
+
model = whisper.load_model("base")
|
11 |
+
|
12 |
+
def transcribe(audio):
|
13 |
+
|
14 |
+
#time.sleep(3)
|
15 |
+
# load audio and pad/trim it to fit 30 seconds
|
16 |
+
audio = whisper.load_audio(audio)
|
17 |
+
audio = whisper.pad_or_trim(audio)
|
18 |
+
|
19 |
+
# make log-Mel spectrogram and move to the same device as the model
|
20 |
+
mel = whisper.log_mel_spectrogram(audio).to(model.device)
|
21 |
+
|
22 |
+
# detect the spoken language
|
23 |
+
_, probs = model.detect_language(mel)
|
24 |
+
print(f"Detected language: {max(probs, key=probs.get)}")
|
25 |
+
|
26 |
+
# decode the audio
|
27 |
+
options = whisper.DecodingOptions()
|
28 |
+
result = whisper.decode(model, mel, options)
|
29 |
+
|
30 |
+
#cohere
|
31 |
+
response = co.generate(
|
32 |
+
model='xlarge',
|
33 |
+
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:',
|
34 |
+
max_tokens=100,
|
35 |
+
temperature=0.8,
|
36 |
+
k=0,
|
37 |
+
p=1,
|
38 |
+
frequency_penalty=0,
|
39 |
+
presence_penalty=0,
|
40 |
+
stop_sequences=["--"],
|
41 |
+
return_likelihoods='NONE')
|
42 |
+
#result.text
|
43 |
+
reptxt = response.generations[0].text.strip("--")
|
44 |
+
|
45 |
+
return reptxt
|
46 |
+
|
47 |
+
|
48 |
+
|
49 |
+
gr.Interface(
|
50 |
+
title = 'OpenAI Whisper ASR Gradio Web UI',
|
51 |
+
fn=transcribe,
|
52 |
+
inputs=[
|
53 |
+
gr.inputs.Audio(source="microphone", type="filepath")
|
54 |
+
],
|
55 |
+
outputs=["text"],
|
56 |
+
live=True).launch(share=True)
|