SteveDigital commited on
Commit
49d7053
1 Parent(s): 97fd8dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -39
app.py CHANGED
@@ -1,51 +1,35 @@
1
  import whisper
2
  from pytube import YouTube
3
- #from transformers import pipeline
4
  import gradio as gr
5
  import os
6
  import re
 
7
 
 
8
  model = whisper.load_model("base")
9
- #summarizer = pipeline("summarization")
10
-
11
- #def get_audio(url):
12
- #try:
13
- #yt = YouTube(url)
14
- #if yt.length < 5400:
15
- #video = yt.streams.filter(only_audio=True).first()
16
- #out_file=video.download(output_path=".")
17
- #base, ext = os.path.splitext(out_file)
18
- #new_file = base+'.mp3'
19
- #os.rename(out_file, new_file)
20
- #a = new_file
21
- #return a
22
- #else:
23
- #raise gr.Error("Videos for transcription on this space are limited to 1.5 hours. Sorry about this limit but some joker thought they could stop this tool from working by transcribing many extremely long videos.")
24
- #return ""
25
- #finally:
26
- #raise gr.Error("Exception: There was a problem getting the video or audio of the URL provided.")
27
 
28
  def get_text(url):
29
- #try:
30
- if url != '':
31
- output_text_transcribe = ''
32
-
33
- yt = YouTube(url)
34
- #video_length = yt.length
35
- #if video_length < 5400:
36
- video = yt.streams.filter(only_audio=True).first()
37
- out_file=video.download(output_path=".")
38
- base, ext = os.path.splitext(out_file)
39
- new_file = base+'.mp3'
40
- os.rename(out_file, new_file)
41
- a = new_file
42
-
43
- result = model.transcribe(a)
44
- return result['text'].strip()
45
- #else:
46
- # return "Videos for transcription on this space are limited to 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."
47
- #finally:
48
- #raise gr.Error("Exception: There was a problem transcribing the audio after successfully retrieving it from the video/URL.")
 
49
 
50
  def get_summary(article):
51
  #try:
 
1
  import whisper
2
  from pytube import YouTube
 
3
  import gradio as gr
4
  import os
5
  import re
6
+ import logging
7
 
8
+ logging.basicConfig(level=logging.INFO)
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
18
+ #if video_length < 5400:
19
+ video = yt.streams.filter(only_audio=True).first()
20
+ out_file=video.download(output_path=".")
21
+ base, ext = os.path.splitext(out_file)
22
+ new_file = base+'.mp3'
23
+ os.rename(out_file, new_file)
24
+ a = new_file
25
+
26
+ logging.error("Size of audio file: %s", str(a.length))
27
+ result = model.transcribe(a)
28
+ return result['text'].strip()
29
+ #else:
30
+ # return "Videos for transcription on this space are limited to 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."
31
+ finally:
32
+ raise gr.Error("Exception: There was a problem transcribing the audio.")
33
 
34
  def get_summary(article):
35
  #try: