Spaces:
Runtime error
Runtime error
Commit
·
c0c4599
1
Parent(s):
2320803
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,104 +1,26 @@
|
|
| 1 |
-
import os
|
| 2 |
-
os.system("pip install git+https://github.com/openai/whisper.git")
|
| 3 |
import gradio as gr
|
| 4 |
import whisper
|
| 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 |
-
.dark input[type='range'] {
|
| 31 |
-
accent-color: #dfdfdf;
|
| 32 |
-
}
|
| 33 |
-
.container {
|
| 34 |
-
max-width: 730px;
|
| 35 |
-
margin: auto;
|
| 36 |
-
padding-top: 1.5rem;
|
| 37 |
-
}
|
| 38 |
-
|
| 39 |
-
.details:hover {
|
| 40 |
-
text-decoration: underline;
|
| 41 |
-
}
|
| 42 |
-
.gr-button {
|
| 43 |
-
white-space: nowrap;
|
| 44 |
-
}
|
| 45 |
-
.gr-button:focus {
|
| 46 |
-
border-color: rgb(147 197 253 / var(--tw-border-opacity));
|
| 47 |
-
outline: none;
|
| 48 |
-
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
|
| 49 |
-
--tw-border-opacity: 1;
|
| 50 |
-
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
|
| 51 |
-
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);
|
| 52 |
-
--tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity));
|
| 53 |
-
--tw-ring-opacity: .5;
|
| 54 |
-
}
|
| 55 |
-
.footer {
|
| 56 |
-
margin-bottom: 45px;
|
| 57 |
-
margin-top: 35px;
|
| 58 |
-
text-align: center;
|
| 59 |
-
border-bottom: 1px solid #e5e5e5;
|
| 60 |
-
}
|
| 61 |
-
.footer>p {
|
| 62 |
-
font-size: .8rem;
|
| 63 |
-
display: inline-block;
|
| 64 |
-
padding: 0 10px;
|
| 65 |
-
transform: translateY(10px);
|
| 66 |
-
background: white;
|
| 67 |
-
}
|
| 68 |
-
.dark .footer {
|
| 69 |
-
border-color: #303030;
|
| 70 |
-
}
|
| 71 |
-
.dark .footer>p {
|
| 72 |
-
background: #0b0f19;
|
| 73 |
-
}
|
| 74 |
-
.prompt h4{
|
| 75 |
-
margin: 1.25em 0 .25em 0;
|
| 76 |
-
font-weight: bold;
|
| 77 |
-
font-size: 115%;
|
| 78 |
-
}
|
| 79 |
-
"""
|
| 80 |
-
|
| 81 |
-
block = gr.Blocks(css=css)
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
with block:
|
| 86 |
-
gr.HTML(
|
| 87 |
-
"""
|
| 88 |
-
<div style="text-align: center; max-width: 650px; margin: 0 auto;">
|
| 89 |
-
|
| 90 |
-
</div>
|
| 91 |
-
"""
|
| 92 |
-
)
|
| 93 |
-
with gr.Group():
|
| 94 |
-
with gr.Box():
|
| 95 |
-
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
| 96 |
-
audio = gr.Audio()
|
| 97 |
-
btn = gr.Button("Transcribe")
|
| 98 |
-
text = gr.Textbox(show_label=False)
|
| 99 |
-
|
| 100 |
-
btn.click(transcription, inputs=[audio], outputs=[text])
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
block.launch()
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import whisper
|
| 3 |
+
from langcodes import *
|
| 4 |
+
|
| 5 |
+
def speech_to_text(tmp_filename, uploaded, model_size):
|
| 6 |
+
model = whisper.load_model(model_size)
|
| 7 |
+
source = uploaded if uploaded is not None else tmp_filename
|
| 8 |
+
result = model.transcribe(source)
|
| 9 |
+
return f'Detected language: {Language.make(language=result["language"]).display_name()}\n\n You said: {result["text"]}'
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
gr.Interface(
|
| 13 |
+
|
| 14 |
+
title="Whisper by OpenAI",
|
| 15 |
+
thumbnail="https://cdn.openai.com/whisper/asr-summary-of-model-architecture-desktop.svg",
|
| 16 |
+
css="""
|
| 17 |
+
.gr-prose p{text-align: center;}
|
| 18 |
+
.gr-button {background: black;color: white}
|
| 19 |
+
""",
|
| 20 |
+
description="Whisper is an automatic speech recognition (ASR) system trained on 680,000 hours of multilingual and multitask supervised data collected from the web.",
|
| 21 |
+
fn=speech_to_text,
|
| 22 |
+
inputs=[
|
| 23 |
+
gr.Audio(label="Record your voice on your mic",source="microphone", type="filepath"),
|
| 24 |
+
gr.Audio(source="upload", type="filepath", label="Upload Audio"),
|
| 25 |
+
gr.Dropdown(label="Select model size",value="base",choices=["tiny", "base", "small", "medium", "large"])],
|
| 26 |
+
outputs="text").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|