Spaces:
Runtime error
Runtime error
Commit
·
37b33f7
1
Parent(s):
fd23ae5
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,113 @@
|
|
| 1 |
-
from IPython.display import Audio, display
|
| 2 |
import whisper
|
| 3 |
-
|
|
|
|
| 4 |
model = whisper.load_model('large')
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import whisper
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
model = whisper.load_model('large')
|
| 5 |
+
|
| 6 |
+
def speech(x):
|
| 7 |
+
text = model.transcribe(x)
|
| 8 |
+
return text['text']
|
| 9 |
+
|
| 10 |
+
style = """
|
| 11 |
+
.gradio-container {
|
| 12 |
+
font-family: 'IBM Plex Sans', sans-serif;
|
| 13 |
+
}
|
| 14 |
+
.gr-button {
|
| 15 |
+
color: white;
|
| 16 |
+
border-color: black;
|
| 17 |
+
background: black;
|
| 18 |
+
}
|
| 19 |
+
input[type='range'] {
|
| 20 |
+
accent-color: black;
|
| 21 |
+
}
|
| 22 |
+
.dark input[type='range'] {
|
| 23 |
+
accent-color: #dfdfdf;
|
| 24 |
+
}
|
| 25 |
+
.container {
|
| 26 |
+
max-width: 730px;
|
| 27 |
+
margin: auto;
|
| 28 |
+
padding-top: 1.5rem;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
.details:hover {
|
| 32 |
+
text-decoration: underline;
|
| 33 |
+
}
|
| 34 |
+
.gr-button {
|
| 35 |
+
white-space: nowrap;
|
| 36 |
+
}
|
| 37 |
+
.gr-button:focus {
|
| 38 |
+
border-color: rgb(147 197 253 / var(--tw-border-opacity));
|
| 39 |
+
outline: none;
|
| 40 |
+
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
|
| 41 |
+
--tw-border-opacity: 1;
|
| 42 |
+
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
|
| 43 |
+
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);
|
| 44 |
+
--tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity));
|
| 45 |
+
--tw-ring-opacity: .5;
|
| 46 |
+
}
|
| 47 |
+
.footer {
|
| 48 |
+
margin-bottom: 45px;
|
| 49 |
+
margin-top: 35px;
|
| 50 |
+
text-align: center;
|
| 51 |
+
border-bottom: 1px solid #e5e5e5;
|
| 52 |
+
}
|
| 53 |
+
.footer>p {
|
| 54 |
+
font-size: .8rem;
|
| 55 |
+
display: inline-block;
|
| 56 |
+
padding: 0 10px;
|
| 57 |
+
transform: translateY(10px);
|
| 58 |
+
background: white;
|
| 59 |
+
}
|
| 60 |
+
.dark .footer {
|
| 61 |
+
border-color: #303030;
|
| 62 |
+
}
|
| 63 |
+
.dark .footer>p {
|
| 64 |
+
background: #0b0f19;
|
| 65 |
+
}
|
| 66 |
+
.prompt h4{
|
| 67 |
+
margin: 1.25em 0 .25em 0;
|
| 68 |
+
font-weight: bold;
|
| 69 |
+
font-size: 115%;
|
| 70 |
+
}
|
| 71 |
+
.animate-spin {
|
| 72 |
+
animation: spin 1s linear infinite;
|
| 73 |
+
}
|
| 74 |
+
@keyframes spin {
|
| 75 |
+
from {
|
| 76 |
+
transform: rotate(0deg);
|
| 77 |
+
}
|
| 78 |
+
to {
|
| 79 |
+
transform: rotate(360deg);
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
#share-btn-container {
|
| 83 |
+
display: flex; margin-top: 1.5rem !important; padding-left: 0.5rem !important; padding-right: 0.5rem !important; background-color: #000000; justify-content: center; align-items: center; border-radius: 9999px !important; width: 13rem;
|
| 84 |
+
}
|
| 85 |
+
#share-btn {
|
| 86 |
+
all: initial; color: #ffffff;font-weight: 600; cursor:pointer; font-family: 'IBM Plex Sans', sans-serif; margin-left: 0.5rem !important; padding-top: 0.25rem !important; padding-bottom: 0.25rem !important;
|
| 87 |
+
}
|
| 88 |
+
#share-btn * {
|
| 89 |
+
all: unset;
|
| 90 |
+
}
|
| 91 |
+
"""
|
| 92 |
+
|
| 93 |
+
with gr.Blocks(css = style) as demo:
|
| 94 |
+
with gr.Tab("Audio File"):
|
| 95 |
+
with gr.Row().style(equal_height=True):
|
| 96 |
+
audio_input1 = gr.Audio(label="Audio File", type="filepath")
|
| 97 |
+
text_output1 = gr.Textbox(label="Transcription", show_label=False)
|
| 98 |
+
file_button = gr.Button("Transcribe")
|
| 99 |
+
with gr.Tab("Record"):
|
| 100 |
+
with gr.Row().style(equal_height=True):
|
| 101 |
+
audio_input2 = gr.Audio(label="Input Audio", source="microphone", type="filepath")
|
| 102 |
+
text_output2 = gr.Textbox(label="Transcription", show_label=False)
|
| 103 |
+
rec_button = gr.Button("Transcribe")
|
| 104 |
+
gr.HTML('''
|
| 105 |
+
<div class="footer">
|
| 106 |
+
<p>Model by <a href="https://github.com/openai/whisper" style="text-decoration: underline;" target="_blank">OpenAI</a></p>
|
| 107 |
+
</div>
|
| 108 |
+
''')
|
| 109 |
+
|
| 110 |
+
file_button.click(speech, inputs=audio_input1, outputs=text_output1)
|
| 111 |
+
rec_button.click(speech, inputs=audio_input2, outputs=text_output2)
|
| 112 |
+
|
| 113 |
+
demo.launch()
|