Prince-29 commited on
Commit
d3b75ed
·
1 Parent(s): 7a2c23f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -3,9 +3,17 @@ from api import get_news, NewsRequest
3
  from utils import text_to_speech
4
  import time
5
  import base64
6
-
7
  import nltk
8
- nltk.download('punkt')
 
 
 
 
 
 
 
 
 
9
 
10
  # Function to play audio automatically
11
  def autoplay_audio(file_path):
@@ -64,17 +72,11 @@ def main():
64
  </div>
65
  """, unsafe_allow_html=True)
66
 
67
- # all_headlines = ". ".join([article['title'] for article in articles])
68
- # audio_file = text_to_speech(all_headlines)
69
- # if audio_file:
70
- # autoplay_audio(audio_file)
71
- # Generate numbered headlines for audio
72
  all_headlines = ". ".join([f"{idx + 1}. {article['title']}" for idx, article in enumerate(articles)])
73
  audio_file = text_to_speech(all_headlines)
74
  if audio_file:
75
  autoplay_audio(audio_file)
76
 
77
-
78
  st.write("## Latest News Articles")
79
 
80
  for idx, article in enumerate(articles, start=1):
 
3
  from utils import text_to_speech
4
  import time
5
  import base64
 
6
  import nltk
7
+ import os
8
+
9
+ # Make sure nltk knows where to store and search for data
10
+ nltk_data_dir = "/home/user/nltk_data"
11
+ os.environ["NLTK_DATA"] = nltk_data_dir
12
+ nltk.data.path.append(nltk_data_dir)
13
+
14
+ # Download punkt if not already present (won't redownload if present)
15
+ if not os.path.exists(os.path.join(nltk_data_dir, "tokenizers/punkt")):
16
+ nltk.download("punkt", download_dir=nltk_data_dir)
17
 
18
  # Function to play audio automatically
19
  def autoplay_audio(file_path):
 
72
  </div>
73
  """, unsafe_allow_html=True)
74
 
 
 
 
 
 
75
  all_headlines = ". ".join([f"{idx + 1}. {article['title']}" for idx, article in enumerate(articles)])
76
  audio_file = text_to_speech(all_headlines)
77
  if audio_file:
78
  autoplay_audio(audio_file)
79
 
 
80
  st.write("## Latest News Articles")
81
 
82
  for idx, article in enumerate(articles, start=1):