Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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
|
| 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 |
-
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
| 103 |
article_titles = [news['title'] for news in news_list[:5]]
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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():
|