jeonsworld commited on
Commit
eabba3c
Β·
1 Parent(s): a3dc4f3

first commit

Browse files
Files changed (3) hide show
  1. README.md +0 -13
  2. app.py +170 -0
  3. requirements.txt +1 -0
README.md DELETED
@@ -1,13 +0,0 @@
1
- ---
2
- title: Whisper Medium Ko
3
- emoji: 🏒
4
- colorFrom: red
5
- colorTo: indigo
6
- sdk: gradio
7
- sdk_version: 3.3.1
8
- app_file: app.py
9
- pinned: false
10
- license: mit
11
- ---
12
-
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app.py ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ os.system("pip install git+https://github.com/openai/whisper.git")
4
+ import gradio as gr
5
+ import whisper
6
+
7
+ model = whisper.load_model("medium")
8
+
9
+ def inference(audio):
10
+ audio = whisper.load_audio(audio)
11
+
12
+ audio = whisper.pad_or_trim(audio)
13
+
14
+ mel = whisper.log_mel_spectrogram(audio).to(model.device)
15
+
16
+ # _, probs = model.detect_language(mel)
17
+ options = dict(language="Korean", beam_size=5, best_of=5)
18
+ options = whisper.DecodingOptions(fp16=False, task="transcribe", **options)
19
+ result = whisper.decode(model, mel, options)
20
+ # print(result.text)
21
+ return result.text
22
+
23
+
24
+ title = "Whisper"
25
+
26
+ 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."
27
+
28
+ css = """
29
+ .gradio-container {
30
+ font-family: 'IBM Plex Sans', sans-serif;
31
+ }
32
+ .gr-button {
33
+ color: white;
34
+ border-color: black;
35
+ background: black;
36
+ }
37
+ input[type='range'] {
38
+ accent-color: black;
39
+ }
40
+ .dark input[type='range'] {
41
+ accent-color: #dfdfdf;
42
+ }
43
+ .container {
44
+ max-width: 730px;
45
+ margin: auto;
46
+ padding-top: 1.5rem;
47
+ }
48
+
49
+ .details:hover {
50
+ text-decoration: underline;
51
+ }
52
+ .gr-button {
53
+ white-space: nowrap;
54
+ }
55
+ .gr-button:focus {
56
+ border-color: rgb(147 197 253 / var(--tw-border-opacity));
57
+ outline: none;
58
+ box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
59
+ --tw-border-opacity: 1;
60
+ --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
61
+ --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(3px var(--tw-ring-offset-width)) var(--tw-ring-color);
62
+ --tw-ring-color: rgb(191 219 254 / var(--tw-ring-opacity));
63
+ --tw-ring-opacity: .5;
64
+ }
65
+ .footer {
66
+ margin-bottom: 45px;
67
+ margin-top: 35px;
68
+ text-align: center;
69
+ border-bottom: 1px solid #e5e5e5;
70
+ }
71
+ .footer>p {
72
+ font-size: .8rem;
73
+ display: inline-block;
74
+ padding: 0 10px;
75
+ transform: translateY(10px);
76
+ background: white;
77
+ }
78
+ .dark .footer {
79
+ border-color: #303030;
80
+ }
81
+ .dark .footer>p {
82
+ background: #0b0f19;
83
+ }
84
+ .prompt h4{
85
+ margin: 1.25em 0 .25em 0;
86
+ font-weight: bold;
87
+ font-size: 115%;
88
+ }
89
+ """
90
+
91
+ block = gr.Blocks(css=css)
92
+
93
+ with block:
94
+ gr.HTML(
95
+ """
96
+ <div style="text-align: center; max-width: 650px; margin: 0 auto;">
97
+ <div
98
+ style="
99
+ display: inline-flex;
100
+ align-items: center;
101
+ gap: 0.8rem;
102
+ font-size: 1.75rem;
103
+ "
104
+ >
105
+ <svg
106
+ width="0.65em"
107
+ height="0.65em"
108
+ viewBox="0 0 115 115"
109
+ fill="none"
110
+ xmlns="http://www.w3.org/2000/svg"
111
+ >
112
+ <rect width="23" height="23" fill="white"></rect>
113
+ <rect y="69" width="23" height="23" fill="white"></rect>
114
+ <rect x="23" width="23" height="23" fill="#AEAEAE"></rect>
115
+ <rect x="23" y="69" width="23" height="23" fill="#AEAEAE"></rect>
116
+ <rect x="46" width="23" height="23" fill="white"></rect>
117
+ <rect x="46" y="69" width="23" height="23" fill="white"></rect>
118
+ <rect x="69" width="23" height="23" fill="black"></rect>
119
+ <rect x="69" y="69" width="23" height="23" fill="black"></rect>
120
+ <rect x="92" width="23" height="23" fill="#D9D9D9"></rect>
121
+ <rect x="92" y="69" width="23" height="23" fill="#AEAEAE"></rect>
122
+ <rect x="115" y="46" width="23" height="23" fill="white"></rect>
123
+ <rect x="115" y="115" width="23" height="23" fill="white"></rect>
124
+ <rect x="115" y="69" width="23" height="23" fill="#D9D9D9"></rect>
125
+ <rect x="92" y="46" width="23" height="23" fill="#AEAEAE"></rect>
126
+ <rect x="92" y="115" width="23" height="23" fill="#AEAEAE"></rect>
127
+ <rect x="92" y="69" width="23" height="23" fill="white"></rect>
128
+ <rect x="69" y="46" width="23" height="23" fill="white"></rect>
129
+ <rect x="69" y="115" width="23" height="23" fill="white"></rect>
130
+ <rect x="69" y="69" width="23" height="23" fill="#D9D9D9"></rect>
131
+ <rect x="46" y="46" width="23" height="23" fill="black"></rect>
132
+ <rect x="46" y="115" width="23" height="23" fill="black"></rect>
133
+ <rect x="46" y="69" width="23" height="23" fill="black"></rect>
134
+ <rect x="23" y="46" width="23" height="23" fill="#D9D9D9"></rect>
135
+ <rect x="23" y="115" width="23" height="23" fill="#AEAEAE"></rect>
136
+ <rect x="23" y="69" width="23" height="23" fill="black"></rect>
137
+ </svg>
138
+ <h1 style="font-weight: 900; margin-bottom: 7px;">
139
+ Whisper
140
+ </h1>
141
+ </div>
142
+ <p style="margin-bottom: 10px; font-size: 94%">
143
+ 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.
144
+ </p>
145
+ </div>
146
+ """
147
+ )
148
+ with gr.Group():
149
+ with gr.Box():
150
+ with gr.Row().style(mobile_collapse=False, equal_height=True):
151
+ audio = gr.Audio(
152
+ label="Input Audio",
153
+ show_label=False,
154
+ source="microphone",
155
+ type="filepath"
156
+ )
157
+
158
+ btn = gr.Button("Transcribe!")
159
+ text = gr.Textbox(show_label=False)
160
+
161
+ btn.click(inference, inputs=[audio], outputs=[text])
162
+
163
+ gr.HTML('''
164
+ <div class="footer">
165
+ <p>Model by <a href="https://github.com/openai/whisper" style="text-decoration: underline;" target="_blank">OpenAI</a> - Gradio Demo by πŸ€— Hugging Face
166
+ </p>
167
+ </div>
168
+ ''')
169
+
170
+ block.launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ transformers