statisticalplumber commited on
Commit
070bea1
1 Parent(s): b9c76ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -22
app.py CHANGED
@@ -5,39 +5,39 @@ import os
5
 
6
  key = st.text_input("Provide Openai API Key to Chat")
7
  @st.cache_resource
8
- def get_whisper():
9
  model = whisper.load_model("base")
10
  return model
11
 
12
  def get_audio(url):
13
- yt = YouTube(url)
14
- video = yt.streams.filter(only_audio=True).first()
15
- out_file=video.download(output_path=".")
16
- base, ext = os.path.splitext(out_file)
17
- new_file = base+'.mp3'
18
- os.rename(out_file, new_file)
19
- a = new_file
20
- return a
21
 
22
  def get_text(url):
23
- model = get_whisper()
24
- result = model.transcribe(get_audio(url))
25
- return result['text']
26
 
27
  def get_youtube_title(y_url):
28
- yt = Youtube(y_url)
29
- embed_url = f"https://wwww.youtube.com/embed/{yt.video_id}"
30
- emded_html = f'<iframe src>"{embed_url}" frameborder="0" allowfullscreen></iframe>'
31
- return yt.title, emded_html
32
 
33
  y_url = st.sidebar.text_input("Enter youtube url")
34
  if st.sidebar.button('Get Youtube Content'):
35
- if st.spinner('Loading...'):
36
- video_title, embed_html = get_video_title(y_url)
37
- st.markdown(f'## {video_title}')
38
- st.markdown(embed_html, unsafe_allow_html=True)
39
- content = get_text(y_url)
40
- st.session_state.content = content
41
 
42
  template = """You are Adance AI that respond on given instruction based on available content
43
  content: {content}
 
5
 
6
  key = st.text_input("Provide Openai API Key to Chat")
7
  @st.cache_resource
8
+ def get_whisper():
9
  model = whisper.load_model("base")
10
  return model
11
 
12
  def get_audio(url):
13
+ yt = YouTube(url)
14
+ video = yt.streams.filter(only_audio=True).first()
15
+ out_file=video.download(output_path=".")
16
+ base, ext = os.path.splitext(out_file)
17
+ new_file = base+'.mp3'
18
+ os.rename(out_file, new_file)
19
+ a = new_file
20
+ return a
21
 
22
  def get_text(url):
23
+ model = get_whisper()
24
+ result = model.transcribe(get_audio(url))
25
+ return result['text']
26
 
27
  def get_youtube_title(y_url):
28
+ yt = Youtube(y_url)
29
+ embed_url = f"https://wwww.youtube.com/embed/{yt.video_id}"
30
+ emded_html = f'<iframe src>"{embed_url}" frameborder="0" allowfullscreen></iframe>'
31
+ return yt.title, emded_html
32
 
33
  y_url = st.sidebar.text_input("Enter youtube url")
34
  if st.sidebar.button('Get Youtube Content'):
35
+ if st.spinner('Loading...'):
36
+ video_title, embed_html = get_video_title(y_url)
37
+ st.markdown(f'## {video_title}')
38
+ st.markdown(embed_html, unsafe_allow_html=True)
39
+ content = get_text(y_url)
40
+ st.session_state.content = content
41
 
42
  template = """You are Adance AI that respond on given instruction based on available content
43
  content: {content}