Spaces:
Running
on
Zero
Running
on
Zero
Create new file
Browse files
app.py
ADDED
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import whisper
|
3 |
+
|
4 |
+
model = whisper.load_model("base")
|
5 |
+
|
6 |
+
|
7 |
+
|
8 |
+
|
9 |
+
def inference(audio):
|
10 |
+
result = model.transcribe(audio)
|
11 |
+
print(result["text"])
|
12 |
+
return result["text"]
|
13 |
+
|
14 |
+
|
15 |
+
title="Whisper"
|
16 |
+
|
17 |
+
description="Whisper is a general-purpose speech recognition model. It is trained on a large dataset of diverse audio and is also a multi-task model that can perform multilingual speech recognition as well as speech translation and language identification."
|
18 |
+
|
19 |
+
css = """
|
20 |
+
.gradio-container {
|
21 |
+
font-family: 'IBM Plex Sans', sans-serif;
|
22 |
+
}
|
23 |
+
.gr-button {
|
24 |
+
color: white;
|
25 |
+
border-color: black;
|
26 |
+
background: black;
|
27 |
+
}
|
28 |
+
input[type='range'] {
|
29 |
+
accent-color: black;
|
30 |
+
}
|
31 |
+
.dark input[type='range'] {
|
32 |
+
accent-color: #dfdfdf;
|
33 |
+
}
|
34 |
+
.container {
|
35 |
+
max-width: 730px;
|
36 |
+
margin: auto;
|
37 |
+
padding-top: 1.5rem;
|
38 |
+
}
|
39 |
+
#gallery {
|
40 |
+
min-height: 22rem;
|
41 |
+
margin-bottom: 15px;
|
42 |
+
margin-left: auto;
|
43 |
+
margin-right: auto;
|
44 |
+
border-bottom-right-radius: .5rem !important;
|
45 |
+
border-bottom-left-radius: .5rem !important;
|
46 |
+
}
|
47 |
+
#gallery>div>.h-full {
|
48 |
+
min-height: 20rem;
|
49 |
+
}
|
50 |
+
.details:hover {
|
51 |
+
text-decoration: underline;
|
52 |
+
}
|
53 |
+
.gr-button {
|
54 |
+
white-space: nowrap;
|
55 |
+
}
|
56 |
+
.gr-button:focus {
|
57 |
+
border-color: rgb(147 197 253 / var(--tw-border-opacity));
|
58 |
+
outline: none;
|
59 |
+
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
|
60 |
+
--tw-border-opacity: 1;
|
61 |
+
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
|
62 |
+
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);
|
63 |
+
--tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity));
|
64 |
+
--tw-ring-opacity: .5;
|
65 |
+
}
|
66 |
+
.footer {
|
67 |
+
margin-bottom: 45px;
|
68 |
+
margin-top: 35px;
|
69 |
+
text-align: center;
|
70 |
+
border-bottom: 1px solid #e5e5e5;
|
71 |
+
}
|
72 |
+
.footer>p {
|
73 |
+
font-size: .8rem;
|
74 |
+
display: inline-block;
|
75 |
+
padding: 0 10px;
|
76 |
+
transform: translateY(10px);
|
77 |
+
background: white;
|
78 |
+
}
|
79 |
+
.dark .footer {
|
80 |
+
border-color: #303030;
|
81 |
+
}
|
82 |
+
.dark .footer>p {
|
83 |
+
background: #0b0f19;
|
84 |
+
}
|
85 |
+
.prompt h4{
|
86 |
+
margin: 1.25em 0 .25em 0;
|
87 |
+
font-weight: bold;
|
88 |
+
font-size: 115%;
|
89 |
+
}
|
90 |
+
"""
|
91 |
+
|
92 |
+
block = gr.Blocks(css=css)
|
93 |
+
|
94 |
+
|
95 |
+
|
96 |
+
with block:
|
97 |
+
gr.HTML(
|
98 |
+
"""
|
99 |
+
<div style="text-align: center; max-width: 650px; margin: 0 auto;">
|
100 |
+
<div
|
101 |
+
style="
|
102 |
+
display: inline-flex;
|
103 |
+
gap: 0.8rem;
|
104 |
+
font-size: 1.75rem;
|
105 |
+
margin-bottom: 10px;
|
106 |
+
margin-left: 220px;
|
107 |
+
justify-content: center;
|
108 |
+
"
|
109 |
+
>
|
110 |
+
<a href="https://github.com/PaddlePaddle/PaddleHub"><img src="https://user-images.githubusercontent.com/22424850/187387422-f6c9ccab-7fda-416e-a24d-7d6084c46f67.jpg" alt="Paddlehub" width="40%"></a>
|
111 |
+
</div>
|
112 |
+
<div
|
113 |
+
style="
|
114 |
+
display: inline-flex;
|
115 |
+
align-items: center;
|
116 |
+
gap: 0.8rem;
|
117 |
+
font-size: 1.75rem;
|
118 |
+
margin-bottom: 10px;
|
119 |
+
justify-content: center;
|
120 |
+
">
|
121 |
+
<a href="https://github.com/PaddlePaddle/PaddleHub"><h1 style="font-weight: 900; margin-bottom: 7px;">
|
122 |
+
ERNIE-ViLG Demo
|
123 |
+
</h1></a>
|
124 |
+
</div>
|
125 |
+
<p style="margin-bottom: 10px; font-size: 94%">
|
126 |
+
ERNIE-ViLG is a state-of-the-art text-to-image model that generates
|
127 |
+
images from Chinese text.
|
128 |
+
</p>
|
129 |
+
<a href="https://github.com/PaddlePaddle/PaddleHub"><img src="https://user-images.githubusercontent.com/22424850/188184795-98605a22-9af2-4106-827b-e58548f8892f.png" alt="star Paddlehub" width="100%"></a>
|
130 |
+
</div>
|
131 |
+
"""
|
132 |
+
)
|
133 |
+
with gr.Group():
|
134 |
+
with gr.Box():
|
135 |
+
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
136 |
+
audio = gr.Audio(
|
137 |
+
label="Input Audio",
|
138 |
+
show_label=False,
|
139 |
+
).style(
|
140 |
+
border=(True, False, True, True),
|
141 |
+
rounded=(True, False, False, True),
|
142 |
+
container=False,
|
143 |
+
)
|
144 |
+
|
145 |
+
btn = gr.Button("Transcribe").style(
|
146 |
+
margin=False,
|
147 |
+
rounded=(False, True, True, False),
|
148 |
+
)
|
149 |
+
text = gr.Textbox(
|
150 |
+
).style(height="auto")
|
151 |
+
|
152 |
+
|
153 |
+
|
154 |
+
|
155 |
+
btn.click(inference, inputs=[audio], outputs=[text])
|
156 |
+
|
157 |
+
gr.HTML('''
|
158 |
+
<div class="footer">
|
159 |
+
<p>Model by <a href="https://github.com/openai/whisper" style="text-decoration: underline;" target="_blank">OpenAI</a> and <a href="https://wenxin.baidu.com" style="text-decoration: underline;" target="_blank">文心大模型</a> - Gradio Demo by 🤗 Hugging Face
|
160 |
+
</p>
|
161 |
+
</div>
|
162 |
+
''')
|
163 |
+
|
164 |
+
block.launch()
|