ginipick commited on
Commit
bb98d15
·
verified ·
1 Parent(s): 8d42280

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -9,19 +9,22 @@ logging.basicConfig(level=logging.INFO)
9
  model = whisper.load_model("base")
10
 
11
  def get_text(url):
 
12
  if url != '':
13
  output_text_transcribe = ''
14
 
15
  yt = YouTube(url)
 
 
16
  video = yt.streams.filter(only_audio=True).first()
17
- out_file = video.download(output_path=".")
18
 
19
  file_stats = os.stat(out_file)
20
  logging.info(f'Size of audio file in Bytes: {file_stats.st_size}')
21
 
22
  if file_stats.st_size <= 30000000:
23
  base, ext = os.path.splitext(out_file)
24
- new_file = base + '.mp3'
25
  os.rename(out_file, new_file)
26
  a = new_file
27
 
@@ -29,10 +32,12 @@ def get_text(url):
29
  return result['text'].strip()
30
  else:
31
  logging.error('Videos for transcription on this space are limited to about 1.5 hours. Sorry about this limit but some joker thought they could stop this tool from working by transcribing many extremely long videos. Please visit https://steve.digital to contact me about this space.')
 
 
32
 
33
  def get_summary(article):
34
  first_sentences = ' '.join(re.split(r'(?<=[.:;])\s', article)[:5])
35
- b = summarizer(first_sentences, min_length=20, max_length=120, do_sample=False)
36
  b = b[0]['summary_text'].replace(' .', '.').strip()
37
  return b
38
 
@@ -43,6 +48,10 @@ with gr.Blocks() as demo:
43
  result_button_transcribe = gr.Button('Transcribe')
44
  output_text_transcribe = gr.Textbox(placeholder='Transcript of the YouTube video.', label='Transcript')
45
 
46
- result_button_transcribe.click(get_text, inputs=input_text_url, outputs=output_text_transcribe)
 
 
 
 
47
 
48
- demo.queue(default_enabled=True).launch(show_api=True)
 
9
  model = whisper.load_model("base")
10
 
11
  def get_text(url):
12
+ #try:
13
  if url != '':
14
  output_text_transcribe = ''
15
 
16
  yt = YouTube(url)
17
+ #video_length = yt.length --- doesn't work anymore - using byte file size of the audio file instead now
18
+ #if video_length < 5400:
19
  video = yt.streams.filter(only_audio=True).first()
20
+ out_file=video.download(output_path=".")
21
 
22
  file_stats = os.stat(out_file)
23
  logging.info(f'Size of audio file in Bytes: {file_stats.st_size}')
24
 
25
  if file_stats.st_size <= 30000000:
26
  base, ext = os.path.splitext(out_file)
27
+ new_file = base+'.mp3'
28
  os.rename(out_file, new_file)
29
  a = new_file
30
 
 
32
  return result['text'].strip()
33
  else:
34
  logging.error('Videos for transcription on this space are limited to about 1.5 hours. Sorry about this limit but some joker thought they could stop this tool from working by transcribing many extremely long videos. Please visit https://steve.digital to contact me about this space.')
35
+ #finally:
36
+ # raise gr.Error("Exception: There was a problem transcribing the audio.")
37
 
38
  def get_summary(article):
39
  first_sentences = ' '.join(re.split(r'(?<=[.:;])\s', article)[:5])
40
+ b = summarizer(first_sentences, min_length = 20, max_length = 120, do_sample = False)
41
  b = b[0]['summary_text'].replace(' .', '.').strip()
42
  return b
43
 
 
48
  result_button_transcribe = gr.Button('Transcribe')
49
  output_text_transcribe = gr.Textbox(placeholder='Transcript of the YouTube video.', label='Transcript')
50
 
51
+ #result_button_summary = gr.Button('2. Create Summary')
52
+ #output_text_summary = gr.Textbox(placeholder='Summary of the YouTube video transcript.', label='Summary')
53
+
54
+ result_button_transcribe.click(get_text, inputs = input_text_url, outputs = output_text_transcribe)
55
+ #result_button_summary.click(get_summary, inputs = output_text_transcribe, outputs = output_text_summary)
56
 
57
+ demo.queue(default_enabled = True).launch(show_api=True)