jbilcke-hf HF staff commited on
Commit
becfdf3
1 Parent(s): 2e0561d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +156 -3
app.py CHANGED
@@ -3,8 +3,11 @@ os.system("pip install git+https://github.com/openai/whisper.git")
3
  import gradio as gr
4
  import whisper
5
 
 
 
6
  model = whisper.load_model("small")
7
 
 
8
 
9
  def inference(audio):
10
  audio = whisper.load_audio(audio)
@@ -18,13 +21,154 @@ def inference(audio):
18
  result = whisper.decode(model, mel, options)
19
 
20
  print(result.text)
21
- return result.text
 
 
 
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  block = gr.Blocks(css=css)
25
 
26
 
 
27
  with block:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  with gr.Group():
29
  with gr.Box():
30
  with gr.Row().style(mobile_collapse=False, equal_height=True):
@@ -37,12 +181,21 @@ with block:
37
 
38
  btn = gr.Button("Transcribe")
39
  text = gr.Textbox(show_label=False, elem_id="result-textarea")
 
 
 
 
 
 
 
40
 
41
- btn.click(inference, inputs=[audio], outputs=[text], api_name="transcribe")
 
42
 
43
  gr.HTML('''
44
  <div class="footer">
45
- <p>This space is used by VideoChain, the all-in-one API to generate video, audio and more.</p>
 
46
  </div>
47
  ''')
48
 
 
3
  import gradio as gr
4
  import whisper
5
 
6
+ from share_btn import community_icon_html, loading_icon_html, share_js
7
+
8
  model = whisper.load_model("small")
9
 
10
+
11
 
12
  def inference(audio):
13
  audio = whisper.load_audio(audio)
 
21
  result = whisper.decode(model, mel, options)
22
 
23
  print(result.text)
24
+ return result.text, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
25
+
26
+
27
+
28
 
29
+ css = """
30
+ .gradio-container {
31
+ font-family: 'IBM Plex Sans', sans-serif;
32
+ }
33
+ .gr-button {
34
+ color: white;
35
+ border-color: black;
36
+ background: black;
37
+ }
38
+ input[type='range'] {
39
+ accent-color: black;
40
+ }
41
+ .dark input[type='range'] {
42
+ accent-color: #dfdfdf;
43
+ }
44
+ .container {
45
+ max-width: 730px;
46
+ margin: auto;
47
+ padding-top: 1.5rem;
48
+ }
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
+ .animate-spin {
91
+ animation: spin 1s linear infinite;
92
+ }
93
+ @keyframes spin {
94
+ from {
95
+ transform: rotate(0deg);
96
+ }
97
+ to {
98
+ transform: rotate(360deg);
99
+ }
100
+ }
101
+ #share-btn-container {
102
+ 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;
103
+ }
104
+ #share-btn {
105
+ 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;
106
+ }
107
+ #share-btn * {
108
+ all: unset;
109
+ }
110
+ """
111
 
112
  block = gr.Blocks(css=css)
113
 
114
 
115
+
116
  with block:
117
+ gr.HTML(
118
+ """
119
+ <div style="text-align: center; max-width: 650px; margin: 0 auto;">
120
+ <div
121
+ style="
122
+ display: inline-flex;
123
+ align-items: center;
124
+ gap: 0.8rem;
125
+ font-size: 1.75rem;
126
+ "
127
+ >
128
+ <svg
129
+ width="0.65em"
130
+ height="0.65em"
131
+ viewBox="0 0 115 115"
132
+ fill="none"
133
+ xmlns="http://www.w3.org/2000/svg"
134
+ >
135
+ <rect width="23" height="23" fill="white"></rect>
136
+ <rect y="69" width="23" height="23" fill="white"></rect>
137
+ <rect x="23" width="23" height="23" fill="#AEAEAE"></rect>
138
+ <rect x="23" y="69" width="23" height="23" fill="#AEAEAE"></rect>
139
+ <rect x="46" width="23" height="23" fill="white"></rect>
140
+ <rect x="46" y="69" width="23" height="23" fill="white"></rect>
141
+ <rect x="69" width="23" height="23" fill="black"></rect>
142
+ <rect x="69" y="69" width="23" height="23" fill="black"></rect>
143
+ <rect x="92" width="23" height="23" fill="#D9D9D9"></rect>
144
+ <rect x="92" y="69" width="23" height="23" fill="#AEAEAE"></rect>
145
+ <rect x="115" y="46" width="23" height="23" fill="white"></rect>
146
+ <rect x="115" y="115" width="23" height="23" fill="white"></rect>
147
+ <rect x="115" y="69" width="23" height="23" fill="#D9D9D9"></rect>
148
+ <rect x="92" y="46" width="23" height="23" fill="#AEAEAE"></rect>
149
+ <rect x="92" y="115" width="23" height="23" fill="#AEAEAE"></rect>
150
+ <rect x="92" y="69" width="23" height="23" fill="white"></rect>
151
+ <rect x="69" y="46" width="23" height="23" fill="white"></rect>
152
+ <rect x="69" y="115" width="23" height="23" fill="white"></rect>
153
+ <rect x="69" y="69" width="23" height="23" fill="#D9D9D9"></rect>
154
+ <rect x="46" y="46" width="23" height="23" fill="black"></rect>
155
+ <rect x="46" y="115" width="23" height="23" fill="black"></rect>
156
+ <rect x="46" y="69" width="23" height="23" fill="black"></rect>
157
+ <rect x="23" y="46" width="23" height="23" fill="#D9D9D9"></rect>
158
+ <rect x="23" y="115" width="23" height="23" fill="#AEAEAE"></rect>
159
+ <rect x="23" y="69" width="23" height="23" fill="black"></rect>
160
+ </svg>
161
+ <h1 style="font-weight: 900; margin-bottom: 7px;">
162
+ Whisper
163
+ </h1>
164
+ </div>
165
+ <p style="margin-bottom: 10px; font-size: 94%">
166
+ 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. This demo cuts audio after around 30 secs.
167
+ </p>
168
+ <p>You can skip the queue by using google colab for the space: <a href="https://colab.research.google.com/drive/1WJ98KHgZxFGrHiMm4TyWZllSew_Af_ff?usp=sharing"><img data-canonical-src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" src="https://camo.githubusercontent.com/84f0493939e0c4de4e6dbe113251b4bfb5353e57134ffd9fcab6b8714514d4d1/68747470733a2f2f636f6c61622e72657365617263682e676f6f676c652e636f6d2f6173736574732f636f6c61622d62616467652e737667"></a></p>
169
+ </div>
170
+ """
171
+ )
172
  with gr.Group():
173
  with gr.Box():
174
  with gr.Row().style(mobile_collapse=False, equal_height=True):
 
181
 
182
  btn = gr.Button("Transcribe")
183
  text = gr.Textbox(show_label=False, elem_id="result-textarea")
184
+ with gr.Group(elem_id="share-btn-container"):
185
+ community_icon = gr.HTML(community_icon_html, visible=False)
186
+ loading_icon = gr.HTML(loading_icon_html, visible=False)
187
+ share_button = gr.Button("Share to community", elem_id="share-btn", visible=False)
188
+
189
+
190
+
191
 
192
+ btn.click(inference, inputs=[audio], outputs=[text, community_icon, loading_icon, share_button], api_name="transcribe")
193
+ share_button.click(None, [], [], _js=share_js)
194
 
195
  gr.HTML('''
196
  <div class="footer">
197
+ <p>Model by <a href="https://github.com/openai/whisper" style="text-decoration: underline;" target="_blank">OpenAI</a> - Gradio Demo by 🤗 Hugging Face
198
+ </p>
199
  </div>
200
  ''')
201