fabiogra commited on
Commit
a4f7be2
β€’
1 Parent(s): 59e9730

fix: session error between pages, improve logs

Browse files
app/header.py CHANGED
@@ -1,15 +1,9 @@
1
- import logging
2
-
3
  import streamlit as st
4
- from helpers import switch_page
5
  from streamlit_option_menu import option_menu
6
- from style import CSS
7
 
8
- logging.basicConfig(
9
- format="%(asctime)s %(levelname)-8s %(message)s",
10
- level=logging.INFO,
11
- datefmt="%Y-%m-%d %H:%M:%S",
12
- )
13
 
14
  DEFAULT_PAGE = "Separate"
15
 
@@ -56,6 +50,7 @@ def header(logo_and_title=True):
56
  key="",
57
  )
58
  if page != st.session_state.get("page", DEFAULT_PAGE):
 
59
  switch_page(page)
60
 
61
  if logo_and_title:
 
 
 
1
  import streamlit as st
2
+ from loguru import logger as log
3
  from streamlit_option_menu import option_menu
 
4
 
5
+ from helpers import switch_page
6
+ from style import CSS
 
 
 
7
 
8
  DEFAULT_PAGE = "Separate"
9
 
 
50
  key="",
51
  )
52
  if page != st.session_state.get("page", DEFAULT_PAGE):
53
+ log.info(f"Go to {page}")
54
  switch_page(page)
55
 
56
  if logo_and_title:
app/helpers.py CHANGED
@@ -130,6 +130,7 @@ def _standardize_name(name: str) -> str:
130
 
131
  @st.cache_data(show_spinner=False)
132
  def switch_page(page_name: str):
 
133
  st.session_state.page = page_name
134
 
135
  page_name = _standardize_name(page_name)
 
130
 
131
  @st.cache_data(show_spinner=False)
132
  def switch_page(page_name: str):
133
+ st.session_state.executed = False
134
  st.session_state.page = page_name
135
 
136
  page_name = _standardize_name(page_name)
app/pages/Karaoke.py CHANGED
@@ -66,7 +66,7 @@ def show_karaoke(pathname):
66
  with st.columns([1, 4, 1])[1]:
67
  if events.name == "onPlay":
68
  sess.player_restart = True
69
- log.info(f"Play Karaoke - {sess.selected_value}")
70
 
71
  elif (
72
  events.name == "onProgress"
@@ -140,7 +140,9 @@ def body():
140
  if selected_value is None or selected_value == "":
141
  with yt_cols[2]:
142
  if st.button("🎲 Random song", use_container_width=True):
 
143
  sess.last_dir, sess.url = get_random_song()
 
144
  sess.selected_value = sess.last_dir
145
  sess.random_song = True
146
  sess.video_options = []
@@ -182,6 +184,7 @@ def body():
182
  with st.spinner(
183
  "Separating vocals from music, it could take a few minutes... Don't close this page!"
184
  ):
 
185
  sess.filename = download_audio_from_youtube(sess.url, in_path)
186
  if sess.filename is None:
187
  st.stop()
@@ -193,6 +196,7 @@ def body():
193
  if cancel_button.button(
194
  "Cancel", use_container_width=True, type="secondary"
195
  ):
 
196
  st.experimental_rerun()
197
  separate(
198
  input=in_path / filename,
@@ -205,6 +209,8 @@ def body():
205
  sess.last_dir = ".".join(sess.filename.split(".")[:-1])
206
  sess.executed = True
207
  cancel_button.empty()
 
 
208
  else:
209
  sess.executed = True
210
 
 
66
  with st.columns([1, 4, 1])[1]:
67
  if events.name == "onPlay":
68
  sess.player_restart = True
69
+ log.info(f"Play Karaoke - {sess.selected_value} - {sess.delay}s delay")
70
 
71
  elif (
72
  events.name == "onProgress"
 
140
  if selected_value is None or selected_value == "":
141
  with yt_cols[2]:
142
  if st.button("🎲 Random song", use_container_width=True):
143
+ reset_karaoke()
144
  sess.last_dir, sess.url = get_random_song()
145
+ log.info(f"Random song - {sess.last_dir}")
146
  sess.selected_value = sess.last_dir
147
  sess.random_song = True
148
  sess.video_options = []
 
184
  with st.spinner(
185
  "Separating vocals from music, it could take a few minutes... Don't close this page!"
186
  ):
187
+ log.info(f"Separating vocals from {sess.selected_value}")
188
  sess.filename = download_audio_from_youtube(sess.url, in_path)
189
  if sess.filename is None:
190
  st.stop()
 
196
  if cancel_button.button(
197
  "Cancel", use_container_width=True, type="secondary"
198
  ):
199
+ log.info(f"Cancel separation of vocals from {filename}")
200
  st.experimental_rerun()
201
  separate(
202
  input=in_path / filename,
 
209
  sess.last_dir = ".".join(sess.filename.split(".")[:-1])
210
  sess.executed = True
211
  cancel_button.empty()
212
+ log.info(f"Separating Done - {sess.selected_value}")
213
+
214
  else:
215
  sess.executed = True
216
 
app/service/youtube.py CHANGED
@@ -4,6 +4,7 @@ import re
4
  import string
5
  from typing import List
6
 
 
7
  import streamlit as st
8
  import yt_dlp
9
  from pytube import Search
@@ -26,7 +27,7 @@ def download_audio_from_youtube(url, output_path):
26
  if not os.path.exists(output_path):
27
  os.makedirs(output_path)
28
 
29
- with yt_dlp.YoutubeDL() as ydl:
30
  info_dict = ydl.extract_info(url, download=False)
31
  if info_dict.get("duration", 0) > 360:
32
  st.error("Song is too long. Please use a song no longer than 6 minutes.")
@@ -43,7 +44,7 @@ def download_audio_from_youtube(url, output_path):
43
  }
44
  ],
45
  "outtmpl": os.path.join(output_path, video_title),
46
- #'quiet': True,
47
  }
48
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
49
  ydl.download([url])
@@ -56,6 +57,7 @@ def query_youtube(query: str) -> Search:
56
 
57
 
58
  def search_youtube(query: str, limit=5) -> List:
 
59
  if len(query) > 3:
60
  search = query_youtube(query + " lyrics")
61
  st.session_state.search_results = search.results
 
4
  import string
5
  from typing import List
6
 
7
+ from loguru import logger as log
8
  import streamlit as st
9
  import yt_dlp
10
  from pytube import Search
 
27
  if not os.path.exists(output_path):
28
  os.makedirs(output_path)
29
 
30
+ with yt_dlp.YoutubeDL({"quiet": True}) as ydl:
31
  info_dict = ydl.extract_info(url, download=False)
32
  if info_dict.get("duration", 0) > 360:
33
  st.error("Song is too long. Please use a song no longer than 6 minutes.")
 
44
  }
45
  ],
46
  "outtmpl": os.path.join(output_path, video_title),
47
+ "quiet": True,
48
  }
49
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
50
  ydl.download([url])
 
57
 
58
 
59
  def search_youtube(query: str, limit=5) -> List:
60
+ log.info(f"{query}")
61
  if len(query) > 3:
62
  search = query_youtube(query + " lyrics")
63
  st.session_state.search_results = search.results