yama commited on
Commit
8bbd265
·
1 Parent(s): a93807b

Update app.py, requirements.txt, and packages.txt

Browse files
Files changed (3) hide show
  1. app.py +481 -65
  2. packages.txt +1 -0
  3. requirements.txt +23 -1
app.py CHANGED
@@ -1,69 +1,485 @@
 
 
 
 
1
  import gradio as gr
2
- import openai
 
 
 
3
  import os
4
- from io import BytesIO
5
- import tempfile
6
- from pydub import AudioSegment
7
- import shutil
8
-
9
- def create_meeting_summary(openai_key, prompt, uploaded_audio, max_transcribe_seconds):
10
- openai.api_key = openai_key
11
-
12
- # 音声ファイルを開く
13
- audio = AudioSegment.from_file(uploaded_audio)
14
-
15
- # 文字起こしする音声データの上限を設定する
16
- if len(audio) > int(max_transcribe_seconds) * 1000:
17
- audio = audio[:int(max_transcribe_seconds) * 1000]
18
-
19
- # ファイルサイズを削減するために音声ファイルを圧縮する
20
- compressed_audio = audio.set_frame_rate(16000).set_channels(1)
21
-
22
- # 圧縮した音声ファイルをmp3形式で一時ファイルに保存する
23
- with tempfile.NamedTemporaryFile(delete=True, suffix=".mp3") as tmp:
24
- compressed_audio.export(tmp.name, format="mp3")
25
-
26
- transcript = openai.Audio.transcribe("whisper-1", open(tmp.name, "rb"), response_format="verbose_json")
27
- transcript_text = ""
28
- for segment in transcript.segments:
29
- transcript_text += f"{segment['text']}\n"
30
-
31
- system_template = prompt
32
-
33
- completion = openai.ChatCompletion.create(
34
- model="gpt-3.5-turbo",
35
- messages=[
36
- {"role": "system", "content": system_template},
37
- {"role": "user", "content": transcript_text}
38
- ]
39
- )
40
- summary = completion.choices[0].message.content
41
- return summary, transcript_text
42
-
43
-
44
- inputs = [
45
- gr.Textbox(lines=1, label="openai_key", type="password"),
46
- gr.TextArea(label="プロンプト", value="""会議の文字起こしが渡されます。
47
-
48
- この会議のサマリーをMarkdown形式で作成してください。サマリーは、以下のような形式で書いてください。
49
- - 会議の目的
50
- - 会議の内容
51
- - 会議の結果"""),
52
- gr.Audio(type="filepath", label="音声ファイルをアップロード"),
53
- gr.Textbox(lines=1, label="最大文字起こし時間(秒)", type="text"),
54
- ]
55
-
56
- outputs = [
57
- gr.Textbox(label="会議サマリー"),
58
- gr.Textbox(label="文字起こし")
59
- ]
60
-
61
- app = gr.Interface(
62
- fn=create_meeting_summary,
63
- inputs=inputs,
64
- outputs=outputs,
65
- title="会議サマリー生成アプリ",
66
- description="音声ファイルをアップロードして、会議のサマリーをMarkdown形式で作成します。"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
- app.launch(debug=True)
 
1
+ # import whisper
2
+ from faster_whisper import WhisperModel
3
+ import datetime
4
+ import subprocess
5
  import gradio as gr
6
+ from pathlib import Path
7
+ import pandas as pd
8
+ import re
9
+ import time
10
  import os
11
+ import numpy as np
12
+ from sklearn.cluster import AgglomerativeClustering
13
+ from sklearn.metrics import silhouette_score
14
+
15
+ from pytube import YouTube
16
+ import yt_dlp
17
+ import torch
18
+ import pyannote.audio
19
+ from pyannote.audio.pipelines.speaker_verification import PretrainedSpeakerEmbedding
20
+ from pyannote.audio import Audio
21
+ from pyannote.core import Segment
22
+
23
+ from gpuinfo import GPUInfo
24
+
25
+ import wave
26
+ import contextlib
27
+ from transformers import pipeline
28
+ import psutil
29
+
30
+ whisper_models = ["tiny", "base", "small", "medium", "large-v1", "large-v2"]
31
+ source_languages = {
32
+ "ja": "Japanese",
33
+ "en": "English",
34
+ # "zh": "Chinese",
35
+ # "de": "German",
36
+ # "es": "Spanish",
37
+ # "ru": "Russian",
38
+ # "ko": "Korean",
39
+ # "fr": "French",
40
+ # "pt": "Portuguese",
41
+ # "tr": "Turkish",
42
+ # "pl": "Polish",
43
+ # "ca": "Catalan",
44
+ # "nl": "Dutch",
45
+ # "ar": "Arabic",
46
+ # "sv": "Swedish",
47
+ # "it": "Italian",
48
+ # "id": "Indonesian",
49
+ # "hi": "Hindi",
50
+ # "fi": "Finnish",
51
+ # "vi": "Vietnamese",
52
+ # "he": "Hebrew",
53
+ # "uk": "Ukrainian",
54
+ # "el": "Greek",
55
+ # "ms": "Malay",
56
+ # "cs": "Czech",
57
+ # "ro": "Romanian",
58
+ # "da": "Danish",
59
+ # "hu": "Hungarian",
60
+ # "ta": "Tamil",
61
+ # "no": "Norwegian",
62
+ # "th": "Thai",
63
+ # "ur": "Urdu",
64
+ # "hr": "Croatian",
65
+ # "bg": "Bulgarian",
66
+ # "lt": "Lithuanian",
67
+ # "la": "Latin",
68
+ # "mi": "Maori",
69
+ # "ml": "Malayalam",
70
+ # "cy": "Welsh",
71
+ # "sk": "Slovak",
72
+ # "te": "Telugu",
73
+ # "fa": "Persian",
74
+ # "lv": "Latvian",
75
+ # "bn": "Bengali",
76
+ # "sr": "Serbian",
77
+ # "az": "Azerbaijani",
78
+ # "sl": "Slovenian",
79
+ # "kn": "Kannada",
80
+ # "et": "Estonian",
81
+ # "mk": "Macedonian",
82
+ # "br": "Breton",
83
+ # "eu": "Basque",
84
+ # "is": "Icelandic",
85
+ # "hy": "Armenian",
86
+ # "ne": "Nepali",
87
+ # "mn": "Mongolian",
88
+ # "bs": "Bosnian",
89
+ # "kk": "Kazakh",
90
+ # "sq": "Albanian",
91
+ # "sw": "Swahili",
92
+ # "gl": "Galician",
93
+ # "mr": "Marathi",
94
+ # "pa": "Punjabi",
95
+ # "si": "Sinhala",
96
+ # "km": "Khmer",
97
+ # "sn": "Shona",
98
+ # "yo": "Yoruba",
99
+ # "so": "Somali",
100
+ # "af": "Afrikaans",
101
+ # "oc": "Occitan",
102
+ # "ka": "Georgian",
103
+ # "be": "Belarusian",
104
+ # "tg": "Tajik",
105
+ # "sd": "Sindhi",
106
+ # "gu": "Gujarati",
107
+ # "am": "Amharic",
108
+ # "yi": "Yiddish",
109
+ # "lo": "Lao",
110
+ # "uz": "Uzbek",
111
+ # "fo": "Faroese",
112
+ # "ht": "Haitian creole",
113
+ # "ps": "Pashto",
114
+ # "tk": "Turkmen",
115
+ # "nn": "Nynorsk",
116
+ # "mt": "Maltese",
117
+ # "sa": "Sanskrit",
118
+ # "lb": "Luxembourgish",
119
+ # "my": "Myanmar",
120
+ # "bo": "Tibetan",
121
+ # "tl": "Tagalog",
122
+ # "mg": "Malagasy",
123
+ # "as": "Assamese",
124
+ # "tt": "Tatar",
125
+ # "haw": "Hawaiian",
126
+ # "ln": "Lingala",
127
+ # "ha": "Hausa",
128
+ # "ba": "Bashkir",
129
+ # "jw": "Javanese",
130
+ # "su": "Sundanese",
131
+ }
132
+
133
+ source_language_list = [key[0] for key in source_languages.items()]
134
+
135
+ MODEL_NAME = "vumichien/whisper-medium-jp"
136
+ lang = "ja"
137
+
138
+ device = 0 if torch.cuda.is_available() else "cpu"
139
+ pipe = pipeline(
140
+ task="automatic-speech-recognition",
141
+ model=MODEL_NAME,
142
+ chunk_length_s=30,
143
+ device=device,
144
  )
145
+ os.makedirs('output', exist_ok=True)
146
+ pipe.model.config.forced_decoder_ids = pipe.tokenizer.get_decoder_prompt_ids(language=lang, task="transcribe")
147
+
148
+ embedding_model = PretrainedSpeakerEmbedding(
149
+ "speechbrain/spkrec-ecapa-voxceleb",
150
+ device=torch.device("cuda" if torch.cuda.is_available() else "cpu"))
151
+
152
+
153
+ # 音声データの転記
154
+ # def transcribe(microphone, file_upload):
155
+ # warn_output = ""
156
+ # if (microphone is not None) and (file_upload is not None):
157
+ # warn_output = (
158
+ # "WARNING: You've uploaded an audio file and used the microphone. "
159
+ # "The recorded file from the microphone will be used and the uploaded audio will be discarded.\n"
160
+ # )
161
+ #
162
+ # elif (microphone is None) and (file_upload is None):
163
+ # return "ERROR: You have to either use the microphone or upload an audio file"
164
+ #
165
+ # file = microphone if microphone is not None else file_upload
166
+ #
167
+ # text = pipe(file)["text"]
168
+ #
169
+ # return warn_output + text
170
+
171
+
172
+ # YouTubeの埋め込みプレーヤーを表示するHTMLコードを生成する
173
+ # def _return_yt_html_embed(yt_url):
174
+ # video_id = yt_url.split("?v=")[-1]
175
+ # HTML_str = (
176
+ # f'<center> <iframe width="500" height="320" src="https://www.youtube.com/embed/{video_id}"> </iframe>'
177
+ # " </center>"
178
+ # )
179
+ # return HTML_str
180
+
181
+
182
+ # YouTubeのビデオから音声をダウンロードし、音声データを使用して転写を行う
183
+ # def yt_transcribe(yt_url):
184
+ # # yt = YouTube(yt_url)
185
+ # # html_embed_str = _return_yt_html_embed(yt_url)
186
+ # # stream = yt.streams.filter(only_audio=True)[0]
187
+ # # stream.download(filename="audio.mp3")
188
+ #
189
+ # ydl_opts = {
190
+ # 'format': 'bestvideo*+bestaudio/best',
191
+ # 'postprocessors': [{
192
+ # 'key': 'FFmpegExtractAudio',
193
+ # 'preferredcodec': 'mp3',
194
+ # 'preferredquality': '192',
195
+ # }],
196
+ # 'outtmpl': 'audio.%(ext)s',
197
+ # }
198
+ #
199
+ # with yt_dlp.YoutubeDL(ydl_opts) as ydl:
200
+ # ydl.download([yt_url])
201
+ #
202
+ # text = pipe("audio.mp3")["text"]
203
+ # return html_embed_str, text
204
+
205
+
206
+ # 秒数を時刻表記に変換
207
+ def convert_time(secs):
208
+ return datetime.timedelta(seconds=round(secs))
209
+
210
+
211
+ # YouTubeのビデオをダウンロードする
212
+ # def get_youtube(video_url):
213
+ # # yt = YouTube(video_url)
214
+ # # abs_video_path = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first().download()
215
+ #
216
+ # ydl_opts = {
217
+ # 'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best',
218
+ # }
219
+ #
220
+ # with yt_dlp.YoutubeDL(ydl_opts) as ydl:
221
+ # info = ydl.extract_info(video_url, download=False)
222
+ # abs_video_path = ydl.prepare_filename(info)
223
+ # ydl.process_info(info)
224
+ #
225
+ # print("Success download video")
226
+ # print(abs_video_path)
227
+ # return abs_video_path
228
+
229
+ # 音声をテキストに変換
230
+ def speech_to_text(video_file_path, selected_source_lang, whisper_model, num_speakers):
231
+ """
232
+ # Transcribe youtube link using OpenAI Whisper
233
+ 1. Using Open AI's Whisper model to seperate audio into segments and generate transcripts.
234
+ 2. Generating speaker embeddings for each segments.
235
+ 3. Applying agglomerative clustering on the embeddings to identify the speaker for each segment.
236
+
237
+ Speech Recognition is based on models from OpenAI Whisper https://github.com/openai/whisper
238
+ Speaker diarization model and pipeline from by https://github.com/pyannote/pyannote-audio
239
+ """
240
+
241
+ # model = whisper.load_model(whisper_model)
242
+ # model = WhisperModel(whisper_model, device="cuda", compute_type="int8_float16")
243
+ model = WhisperModel(whisper_model, compute_type="int8")
244
+ time_start = time.time()
245
+ if (video_file_path == None):
246
+ raise ValueError("Error no video input")
247
+ print(video_file_path)
248
+
249
+ try:
250
+ # Read and convert youtube video
251
+ _, file_ending = os.path.splitext(f'{video_file_path}')
252
+ print(f'file enging is {file_ending}')
253
+ audio_file = video_file_path.replace(file_ending, ".wav")
254
+ print("starting conversion to wav")
255
+ os.system(f'ffmpeg -i "{video_file_path}" -ar 16000 -ac 1 -c:a pcm_s16le "{audio_file}"')
256
+
257
+ # Get duration
258
+ with contextlib.closing(wave.open(audio_file, 'r')) as f:
259
+ frames = f.getnframes()
260
+ rate = f.getframerate()
261
+ duration = frames / float(rate)
262
+ print(f"conversion to wav ready, duration of audio file: {duration}")
263
+
264
+ # Transcribe audio
265
+ options = dict(language=selected_source_lang, beam_size=5, best_of=5)
266
+ transcribe_options = dict(task="transcribe", **options)
267
+ segments_raw, info = model.transcribe(audio_file, **transcribe_options)
268
+
269
+ # Convert back to original openai format
270
+ segments = []
271
+ i = 0
272
+ for segment_chunk in segments_raw:
273
+ chunk = {}
274
+ chunk["start"] = segment_chunk.start
275
+ chunk["end"] = segment_chunk.end
276
+ chunk["text"] = segment_chunk.text
277
+ segments.append(chunk)
278
+ i += 1
279
+ print("transcribe audio done with fast whisper")
280
+ except Exception as e:
281
+ raise RuntimeError("Error converting video to audio")
282
+
283
+ try:
284
+ # Create embedding
285
+ def segment_embedding(segment):
286
+ audio = Audio()
287
+ start = segment["start"]
288
+ # Whisper overshoots the end timestamp in the last segment
289
+ end = min(duration, segment["end"])
290
+ clip = Segment(start, end)
291
+ waveform, sample_rate = audio.crop(audio_file, clip)
292
+ return embedding_model(waveform[None])
293
+
294
+ embeddings = np.zeros(shape=(len(segments), 192))
295
+ for i, segment in enumerate(segments):
296
+ embeddings[i] = segment_embedding(segment)
297
+ embeddings = np.nan_to_num(embeddings)
298
+ print(f'Embedding shape: {embeddings.shape}')
299
+
300
+ if num_speakers == 0:
301
+ # Find the best number of speakers
302
+ score_num_speakers = {}
303
+
304
+ for num_speakers in range(2, 10 + 1):
305
+ clustering = AgglomerativeClustering(num_speakers).fit(embeddings)
306
+ score = silhouette_score(embeddings, clustering.labels_, metric='euclidean')
307
+ score_num_speakers[num_speakers] = score
308
+ best_num_speaker = max(score_num_speakers, key=lambda x: score_num_speakers[x])
309
+ print(f"The best number of speakers: {best_num_speaker} with {score_num_speakers[best_num_speaker]} score")
310
+ else:
311
+ best_num_speaker = num_speakers
312
+
313
+ # Assign speaker label
314
+ clustering = AgglomerativeClustering(best_num_speaker).fit(embeddings)
315
+ labels = clustering.labels_
316
+ for i in range(len(segments)):
317
+ segments[i]["speaker"] = 'SPEAKER ' + str(labels[i] + 1)
318
+
319
+ # Make output
320
+ objects = {
321
+ 'Start': [],
322
+ 'End': [],
323
+ 'Speaker': [],
324
+ 'Text': []
325
+ }
326
+ text = ''
327
+ for (i, segment) in enumerate(segments):
328
+ if i == 0 or segments[i - 1]["speaker"] != segment["speaker"]:
329
+ objects['Start'].append(str(convert_time(segment["start"])))
330
+ objects['Speaker'].append(segment["speaker"])
331
+ if i != 0:
332
+ objects['End'].append(str(convert_time(segments[i - 1]["end"])))
333
+ objects['Text'].append(text)
334
+ text = ''
335
+ text += segment["text"] + ' '
336
+ objects['End'].append(str(convert_time(segments[i - 1]["end"])))
337
+ objects['Text'].append(text)
338
+
339
+ time_end = time.time()
340
+ time_diff = time_end - time_start
341
+ memory = psutil.virtual_memory()
342
+ gpu_utilization, gpu_memory = GPUInfo.gpu_usage()
343
+ gpu_utilization = gpu_utilization[0] if len(gpu_utilization) > 0 else 0
344
+ gpu_memory = gpu_memory[0] if len(gpu_memory) > 0 else 0
345
+ system_info = f"""
346
+ *Memory: {memory.total / (1024 * 1024 * 1024):.2f}GB, used: {memory.percent}%, available: {memory.available / (1024 * 1024 * 1024):.2f}GB.*
347
+ *Processing time: {time_diff:.5} seconds.*
348
+ *GPU Utilization: {gpu_utilization}%, GPU Memory: {gpu_memory}MiB.*
349
+ """
350
+ save_path = "output/transcript_result.csv"
351
+ df_results = pd.DataFrame(objects)
352
+ df_results.to_csv(save_path)
353
+ return df_results, system_info, save_path
354
+
355
+ except Exception as e:
356
+ raise RuntimeError("Error Running inference with local model", e)
357
+
358
+
359
+ # ---- Gradio Layout -----
360
+ # Inspiration from https://huggingface.co/spaces/RASMUS/Whisper-youtube-crosslingual-subtitles
361
+ video_in = gr.Video(label="Video file", mirror_webcam=False)
362
+ youtube_url_in = gr.Textbox(label="Youtube url", lines=1, interactive=True)
363
+ df_init = pd.DataFrame(columns=['Start', 'End', 'Speaker', 'Text'])
364
+ memory = psutil.virtual_memory()
365
+ selected_source_lang = gr.Dropdown(choices=source_language_list, type="value", value="ja",
366
+ label="Spoken language in video", interactive=True)
367
+ selected_whisper_model = gr.Dropdown(choices=whisper_models, type="value", value="base", label="Selected Whisper model",
368
+ interactive=True)
369
+ number_speakers = gr.Number(precision=0, value=0,
370
+ label="Input number of speakers for better results. If value=0, model will automatic find the best number of speakers",
371
+ interactive=True)
372
+ system_info = gr.Markdown(
373
+ f"*Memory: {memory.total / (1024 * 1024 * 1024):.2f}GB, used: {memory.percent}%, available: {memory.available / (1024 * 1024 * 1024):.2f}GB*")
374
+ download_transcript = gr.File(label="Download transcript")
375
+ transcription_df = gr.DataFrame(value=df_init, label="Transcription dataframe", row_count=(0, "dynamic"), max_rows=10,
376
+ wrap=True, overflow_row_behaviour='paginate')
377
+ title = "Whisper speaker diarization"
378
+ demo = gr.Blocks(title=title)
379
+ demo.encrypt = False
380
+
381
+ with demo:
382
+ with gr.Tab("Whisper speaker diarization"):
383
+ # gr.Markdown('''
384
+ # <div>
385
+ # <h1 style='text-align: center'>Whisper speaker diarization</h1>
386
+ # This space uses Whisper models from <a href='https://github.com/openai/whisper' target='_blank'><b>OpenAI</b></a> with <a href='https://github.com/guillaumekln/faster-whisper' target='_blank'><b>CTranslate2</b></a> which is a fast inference engine for Transformer models to recognize the speech (4 times faster than original openai model with same accuracy)
387
+ # and ECAPA-TDNN model from <a href='https://github.com/speechbrain/speechbrain' target='_blank'><b>SpeechBrain</b></a> to encode and clasify speakers
388
+ # </div>
389
+ # ''')
390
+ #
391
+ # with gr.Row():
392
+ # gr.Markdown('''
393
+ # ### Transcribe youtube link using OpenAI Whisper
394
+ # ##### 1. Using Open AI's Whisper model to seperate audio into segments and generate transcripts.
395
+ # ##### 2. Generating speaker embeddings for each segments.
396
+ # ##### 3. Applying agglomerative clustering on the embeddings to identify the speaker for each segment.
397
+ # ''')
398
+ #
399
+ # with gr.Row():
400
+ # gr.Markdown('''
401
+ # ### You can test by following examples:
402
+ # ''')
403
+ # examples = gr.Examples(examples=
404
+ # ["https://www.youtube.com/watch?v=j7BfEzAFuYc&t=32s",
405
+ # "https://www.youtube.com/watch?v=-UX0X45sYe4",
406
+ # "https://www.youtube.com/watch?v=7minSgqi-Gw"],
407
+ # label="Examples", inputs=[youtube_url_in])
408
+ #
409
+ # with gr.Row():
410
+ # with gr.Column():
411
+ # youtube_url_in.render()
412
+ # download_youtube_btn = gr.Button("Download Youtube video")
413
+ # download_youtube_btn.click(get_youtube, [youtube_url_in], [
414
+ # video_in])
415
+ # print(video_in)
416
+
417
+ with gr.Row():
418
+ with gr.Column():
419
+ video_in.render()
420
+ with gr.Column():
421
+ gr.Markdown('''
422
+ ##### Here you can start the transcription process.
423
+ ##### Please select the source language for transcription.
424
+ ##### You can select a range of assumed numbers of speakers.
425
+ ''')
426
+ selected_source_lang.render()
427
+ selected_whisper_model.render()
428
+ number_speakers.render()
429
+ transcribe_btn = gr.Button("Transcribe audio and diarization")
430
+ transcribe_btn.click(speech_to_text,
431
+ [video_in, selected_source_lang, selected_whisper_model, number_speakers],
432
+ [transcription_df, system_info, download_transcript]
433
+ )
434
+
435
+ with gr.Row():
436
+ gr.Markdown('''
437
+ ##### Here you will get transcription output
438
+ ##### ''')
439
+
440
+ with gr.Row():
441
+ with gr.Column():
442
+ download_transcript.render()
443
+ transcription_df.render()
444
+ # system_info.render()
445
+ # gr.Markdown(
446
+ # '''<center><img src='https://visitor-badge.glitch.me/badge?page_id=WhisperDiarizationSpeakers' alt='visitor badge'><a href="https://opensource.org/licenses/Apache-2.0"><img src='https://img.shields.io/badge/License-Apache_2.0-blue.svg' alt='License: Apache 2.0'></center>''')
447
+
448
+ # with gr.Tab("Whisper Transcribe Japanese Audio"):
449
+ # gr.Markdown(f'''
450
+ # <div>
451
+ # <h1 style='text-align: center'>Whisper Transcribe Japanese Audio</h1>
452
+ # </div>
453
+ # Transcribe long-form microphone or audio inputs with the click of a button! The fine-tuned
454
+ # checkpoint <a href='https://huggingface.co/{MODEL_NAME}' target='_blank'><b>{MODEL_NAME}</b></a> to transcribe audio files of arbitrary length.
455
+ # ''')
456
+ # microphone = gr.inputs.Audio(source="microphone", type="filepath", optional=True)
457
+ # upload = gr.inputs.Audio(source="upload", type="filepath", optional=True)
458
+ # transcribe_btn = gr.Button("Transcribe Audio")
459
+ # text_output = gr.Textbox()
460
+ # with gr.Row():
461
+ # gr.Markdown('''
462
+ # ### You can test by following examples:
463
+ # ''')
464
+ # examples = gr.Examples(examples=
465
+ # ["sample1.wav",
466
+ # "sample2.wav",
467
+ # ],
468
+ # label="Examples", inputs=[upload])
469
+ # transcribe_btn.click(transcribe, [microphone, upload], outputs=text_output)
470
+ #
471
+ # with gr.Tab("Whisper Transcribe Japanese YouTube"):
472
+ # gr.Markdown(f'''
473
+ # <div>
474
+ # <h1 style='text-align: center'>Whisper Transcribe Japanese YouTube</h1>
475
+ # </div>
476
+ # Transcribe long-form YouTube videos with the click of a button! The fine-tuned checkpoint:
477
+ # <a href='https://huggingface.co/{MODEL_NAME}' target='_blank'><b>{MODEL_NAME}</b></a> to transcribe audio files of arbitrary length.
478
+ # ''')
479
+ # youtube_link = gr.Textbox(label="Youtube url", lines=1, interactive=True)
480
+ # yt_transcribe_btn = gr.Button("Transcribe YouTube")
481
+ # text_output2 = gr.Textbox()
482
+ # html_output = gr.Markdown()
483
+ # yt_transcribe_btn.click(yt_transcribe, [youtube_link], outputs=[html_output, text_output2])
484
 
485
+ demo.launch(debug=True)
packages.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ ffmpeg
requirements.txt CHANGED
@@ -1,2 +1,24 @@
1
  openai==0.27.2
2
- pydub==0.25.1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  openai==0.27.2
2
+ pydub==0.25.1
3
+ git+https://github.com/huggingface/transformers
4
+ git+https://github.com/pyannote/pyannote-audio
5
+ git+https://github.com/openai/whisper.git
6
+ gradio==3.12
7
+ ffmpeg-python
8
+ pandas==1.5.0
9
+ pytube==12.1.0
10
+ sacremoses
11
+ sentencepiece
12
+ tokenizers
13
+ torch
14
+ torchaudio
15
+ tqdm==4.64.1
16
+ EasyNMT==2.0.2
17
+ nltk
18
+ transformers
19
+ pysrt
20
+ psutil==5.9.2
21
+ requests
22
+ gpuinfo
23
+ faster-whisper
24
+ yt-dlp