KevlarVK commited on
Commit
4eeb48c
1 Parent(s): e3e2bbf

Fixed code repetition and improved code flow

Browse files
Files changed (1) hide show
  1. app.py +22 -38
app.py CHANGED
@@ -5,28 +5,6 @@ from summarizer import BARTSummarizer
5
  from Utils import fetch_article_text, get_text_from_youtube_url
6
  from pytube import YouTube
7
 
8
- st.markdown(
9
- """
10
- <style>
11
- section[data-testid="stSidebar"] div[role="radiogroup"] label {
12
- padding: 0px 0px 20px 20px;
13
- }
14
- section[data-testid="stSidebar"] h2 {
15
- margin: 10px;
16
- }
17
- section.main div[role="radiogroup"] label {
18
- padding: 10px 10px 10px 0px;
19
- }
20
- </style>
21
- """,
22
- unsafe_allow_html=True,
23
- )
24
-
25
- with st.sidebar:
26
- st.header("CHOOSE INPUT TYPE")
27
- input_type = st.radio("", ["Text", "Media"], label_visibility = "hidden")
28
-
29
-
30
  def generate_summary(overall_summary, auto_chapters_summarize, text_to_summarize, show_text = False):
31
  if overall_summary:
32
  with st.spinner("Generating overall summary..."):
@@ -109,7 +87,27 @@ def get_yt_video(youtube_url):
109
  media_processor = MediaProcessor()
110
  text = media_processor.process_video(video_buffer.getvalue())
111
  return text
112
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
 
114
  if input_type == "Text":
115
 
@@ -149,20 +147,6 @@ elif input_type == "Media":
149
  else:
150
  youtube_url = st.text_input("Enter YouTube URL here", placeholder="Enter URL to an YouTube video", label_visibility="visible")
151
  if youtube_url:
152
- if not get_text(url):
153
- try:
154
- try:
155
- with st.spinner("Fetching text from video..."):
156
- text_to_summarize = get_text_from_youtube_url(youtube_url)
157
- except:
158
- with st.spinner("Captions not available. Downloading video..."):
159
- get_yt_video(youtube_url)
160
- text_to_summarize = get_text(url)
161
- except:
162
- st.error("Unable to fetch text from video. Please try a different video.")
163
- text_to_summarize = None
164
- else:
165
- text_to_summarize = get_text(url)
166
- st.markdown("#### Text from video:")
167
 
168
 
 
5
  from Utils import fetch_article_text, get_text_from_youtube_url
6
  from pytube import YouTube
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  def generate_summary(overall_summary, auto_chapters_summarize, text_to_summarize, show_text = False):
9
  if overall_summary:
10
  with st.spinner("Generating overall summary..."):
 
87
  media_processor = MediaProcessor()
88
  text = media_processor.process_video(video_buffer.getvalue())
89
  return text
90
+
91
+ st.markdown(
92
+ """
93
+ <style>
94
+ section[data-testid="stSidebar"] div[role="radiogroup"] label {
95
+ padding: 0px 0px 20px 20px;
96
+ }
97
+ section[data-testid="stSidebar"] h2 {
98
+ margin: 10px;
99
+ }
100
+ section.main div[role="radiogroup"] label {
101
+ padding: 10px 10px 10px 0px;
102
+ }
103
+ </style>
104
+ """,
105
+ unsafe_allow_html=True,
106
+ )
107
+
108
+ with st.sidebar:
109
+ st.header("CHOOSE INPUT TYPE")
110
+ input_type = st.radio("", ["Text", "Media"], label_visibility = "hidden")
111
 
112
  if input_type == "Text":
113
 
 
147
  else:
148
  youtube_url = st.text_input("Enter YouTube URL here", placeholder="Enter URL to an YouTube video", label_visibility="visible")
149
  if youtube_url:
150
+ show_buttons("youtube_url", youtube_url)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
 
152