Anne314159 commited on
Commit
53717a6
·
verified ·
1 Parent(s): 11cf617

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -16
app.py CHANGED
@@ -89,30 +89,38 @@ def page_social_media_generator():
89
  st.write("Please select an article from the 'What is trending in my niche?' page.")
90
 
91
 
92
- def page_article_to_social_post():
93
  st.title("Article to Social Media Post")
94
 
95
- # User input for the niche
96
  niche = st.text_input('Enter your niche', 'Technology')
97
  if niche:
98
  google_news = GNews(language='en', country='US')
99
  news_list = google_news.get_news(niche)
100
 
101
- # Display articles as options in a selectbox
102
- article_urls = [news['url'] for news in news_list[:5]]
 
 
 
103
  article_titles = [news['title'] for news in news_list[:5]]
104
- selected_url = st.selectbox("Select an article:", article_titles, format_func=lambda x: article_titles[article_urls.index(x)])
105
-
106
- if st.button('Fetch Full Article'):
107
- article_text = fetch_full_article(selected_url)
108
- st.write(article_text[:500], "...") # Display a snippet of the article text
109
-
110
- if st.button('Generate Social Media Post'):
111
- with st.spinner('Generating...'):
112
- # Call the function to generate the post using the full article text
113
- post_content = summarizer(article_text, max_length=130, min_length=30, do_sample=False)[0]['summary_text']
114
- st.success('Generated Content:')
115
- st.write(post_content)
 
 
 
 
 
 
116
 
117
 
118
  def page_test():
 
89
  st.write("Please select an article from the 'What is trending in my niche?' page.")
90
 
91
 
92
+ def article_to_social_post():
93
  st.title("Article to Social Media Post")
94
 
 
95
  niche = st.text_input('Enter your niche', 'Technology')
96
  if niche:
97
  google_news = GNews(language='en', country='US')
98
  news_list = google_news.get_news(niche)
99
 
100
+ if not news_list:
101
+ st.write("No news found for the given niche.")
102
+ return
103
+
104
+ # Use the titles directly for the selectbox
105
  article_titles = [news['title'] for news in news_list[:5]]
106
+ selected_title = st.selectbox("Select an article:", article_titles)
107
+
108
+ # Find the selected article's URL based on the title
109
+ selected_article = next((item for item in news_list if item['title'] == selected_title), None)
110
+ if selected_article:
111
+ selected_url = selected_article['url']
112
+ # The rest of your code to fetch and display the article or generate the post...
113
+ if st.button('Fetch Full Article'):
114
+ article_text = fetch_full_article(selected_url)
115
+ st.write(article_text[:500], "...") # Display a snippet of the article text
116
+
117
+ if st.button('Generate Social Media Post'):
118
+ with st.spinner('Generating...'):
119
+ post_content = summarizer(article_text, max_length=130, min_length=30, do_sample=False)[0]['summary_text']
120
+ st.success('Generated Content:')
121
+ st.write(post_content)
122
+ else:
123
+ st.error("Failed to find the selected article.")
124
 
125
 
126
  def page_test():