aichina commited on
Commit
e129c20
1 Parent(s): 2fd9b5b
Files changed (1) hide show
  1. app.py +34 -0
app.py CHANGED
@@ -2,6 +2,26 @@ import gradio as gr
2
  import whisper
3
  from pytube import YouTube
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  def get_audio(url):
6
  print(f'{url} start get audio ...')
7
  yt = YouTube(url)
@@ -10,6 +30,20 @@ def get_audio(url):
10
  return audio_file
11
 
12
  def get_transcript(url, model_size, lang, format):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
 
15
  print('whisper loading ...')
 
2
  import whisper
3
  from pytube import YouTube
4
 
5
+
6
+ import requests
7
+
8
+ headers = {
9
+ 'accept': 'application/json',
10
+ 'x-gladia-key': '89b0adf5-fb2c-48ba-8a66-76b02827fd14',
11
+ # requests won't add a boundary if this header is set when you pass files=
12
+ # 'Content-Type': 'multipart/form-data',
13
+ }
14
+
15
+ files = {
16
+ 'audio': ("707539ca80d090a28c5ea7bbf93e8068.mp4", open('707539ca80d090a28c5ea7bbf93e8068.mp4', 'rb'), 'video/mp4'),
17
+ 'audio_url': (None, 'http://files.gladia.io/example/audio-transcription/split_infinity.wav'),
18
+ 'language': (None, 'english'),
19
+ 'language_behaviour': (None, 'automatic single language'),
20
+ }
21
+
22
+ response = requests.post('https://api.gladia.io/audio/text/audio-transcription/', headers=headers, files=files)
23
+
24
+
25
  def get_audio(url):
26
  print(f'{url} start get audio ...')
27
  yt = YouTube(url)
 
30
  return audio_file
31
 
32
  def get_transcript(url, model_size, lang, format):
33
+ audio_file = get_audio(url)
34
+ audio_file = 'tmp.mp4'
35
+ files = {
36
+ 'audio': (f"{audio_file}", open(f'{audio_file}', 'rb'), 'video/mp4'),
37
+ 'audio_url': (None, 'http://files.gladia.io/example/audio-transcription/split_infinity.wav'),
38
+ 'language': (None, 'english'),
39
+ 'language_behaviour': (None, 'automatic single language'),
40
+ }
41
+ response = requests.post('https://api.gladia.io/audio/text/audio-transcription/', headers=headers, files=files)
42
+ return response.text
43
+
44
+
45
+
46
+ def get_transcript2(url, model_size, lang, format):
47
 
48
 
49
  print('whisper loading ...')