Anne314159 commited on
Commit
d2b5ac1
·
verified ·
1 Parent(s): 8c1f127

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py CHANGED
@@ -21,6 +21,13 @@ def fetch_news(topic):
21
  return articles
22
 
23
 
 
 
 
 
 
 
 
24
 
25
 
26
  def page_trending_niche():
@@ -81,6 +88,30 @@ def page_social_media_generator():
81
  st.write("Please select an article from the 'What is trending in my niche?' page.")
82
 
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
 
86
  def page_test():
@@ -100,6 +131,8 @@ if page == 'trending_niche':
100
  page_trending_niche()
101
  elif page == 'Social Media Content Generator':
102
  page_social_media_generator()
 
 
103
  elif page == 'Test Page':
104
  page_test()
105
 
 
21
  return articles
22
 
23
 
24
+ def fetch_full_article(url):
25
+ """Fetches the full text of an article given its URL."""
26
+ article = Article(url)
27
+ article.download()
28
+ article.parse()
29
+ return article.text
30
+
31
 
32
 
33
  def page_trending_niche():
 
88
  st.write("Please select an article from the 'What is trending in my niche?' page.")
89
 
90
 
91
+ def page_article_to_social_post():
92
+ st.title("Article to Social Media Post")
93
+
94
+ # User input for the niche
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
+ # Display articles as options in a selectbox
101
+ article_urls = [news['url'] for news in news_list[:5]]
102
+ article_titles = [news['title'] for news in news_list[:5]]
103
+ selected_url = st.selectbox("Select an article:", article_titles, format_func=lambda x: article_titles[article_urls.index(x)])
104
+
105
+ if st.button('Fetch Full Article'):
106
+ article_text = fetch_full_article(selected_url)
107
+ st.write(article_text[:500], "...") # Display a snippet of the article text
108
+
109
+ if st.button('Generate Social Media Post'):
110
+ with st.spinner('Generating...'):
111
+ # Call the function to generate the post using the full article text
112
+ post_content = summarizer(article_text, max_length=130, min_length=30, do_sample=False)[0]['summary_text']
113
+ st.success('Generated Content:')
114
+ st.write(post_content)
115
 
116
 
117
  def page_test():
 
131
  page_trending_niche()
132
  elif page == 'Social Media Content Generator':
133
  page_social_media_generator()
134
+ elif page == 'page_article_to_social_post':
135
+ page_article_to_social_post()
136
  elif page == 'Test Page':
137
  page_test()
138