Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from gnews import GNews
|
| 3 |
from transformers import GPT2Tokenizer, GPT2LMHeadModel
|
|
|
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
def fetch_news(topic):
|
| 7 |
-
google_news = GNews(language='
|
| 8 |
news_list = google_news.get_news(topic)
|
| 9 |
|
| 10 |
articles = []
|
|
@@ -18,26 +20,8 @@ def fetch_news(topic):
|
|
| 18 |
})
|
| 19 |
return articles
|
| 20 |
|
| 21 |
-
from gnews import GNews
|
| 22 |
|
| 23 |
-
|
| 24 |
-
def get_article_content(url):
|
| 25 |
-
try:
|
| 26 |
-
response = requests.get(url)
|
| 27 |
-
response.raise_for_status() # Raises an HTTPError if the HTTP request returned an unsuccessful status code
|
| 28 |
-
|
| 29 |
-
# Use BeautifulSoup to parse the HTML content
|
| 30 |
-
soup = BeautifulSoup(response.content, 'html.parser')
|
| 31 |
-
|
| 32 |
-
# Assuming article text is within <article> tags
|
| 33 |
-
article = soup.find('article')
|
| 34 |
-
# Extract text from the article tag
|
| 35 |
-
# This may vary depending on the structure of the web page
|
| 36 |
-
article_text = article.get_text(separator=' ', strip=True) if article else 'Article content could not be retrieved.'
|
| 37 |
-
return article_text
|
| 38 |
-
except requests.RequestException as e:
|
| 39 |
-
st.error(f"Error fetching article from URL: {e}")
|
| 40 |
-
return "Could not retrieve the article text."
|
| 41 |
|
| 42 |
def page_trending_niche():
|
| 43 |
st.title("What is trending in my niche?")
|
|
@@ -60,32 +44,30 @@ def page_trending_niche():
|
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
-
|
| 64 |
|
| 65 |
# Initialize the summarization pipeline with BART
|
| 66 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
return
|
| 73 |
|
|
|
|
| 74 |
def page_social_media_generator():
|
| 75 |
st.title("Social Media Content Generator")
|
| 76 |
-
|
| 77 |
-
# Retrieve the
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
if
|
| 81 |
-
st.write(f"Selected Article
|
| 82 |
-
|
| 83 |
-
# Fetch the content of the article from the URL
|
| 84 |
-
article_text = get_article_content(article_url)
|
| 85 |
|
| 86 |
-
if
|
| 87 |
with st.spinner('Generating...'):
|
| 88 |
-
post_content = generate_social_media_post(
|
| 89 |
st.success('Generated Content:')
|
| 90 |
st.write(post_content)
|
| 91 |
else:
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from gnews import GNews
|
| 3 |
from transformers import GPT2Tokenizer, GPT2LMHeadModel
|
| 4 |
+
from transformers import pipeline
|
| 5 |
+
from gnews import GNews
|
| 6 |
|
| 7 |
|
| 8 |
def fetch_news(topic):
|
| 9 |
+
google_news = GNews(language='german', country='Germany') # You can customize this
|
| 10 |
news_list = google_news.get_news(topic)
|
| 11 |
|
| 12 |
articles = []
|
|
|
|
| 20 |
})
|
| 21 |
return articles
|
| 22 |
|
|
|
|
| 23 |
|
| 24 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
def page_trending_niche():
|
| 27 |
st.title("What is trending in my niche?")
|
|
|
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
+
|
| 48 |
|
| 49 |
# Initialize the summarization pipeline with BART
|
| 50 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 51 |
|
| 52 |
+
# Function to generate social media post
|
| 53 |
+
def generate_social_media_post(description):
|
| 54 |
+
# Generate text with GPT-2 based on the article's description
|
| 55 |
+
generated_texts = text_generator(description, max_length=200, num_return_sequences=1)
|
| 56 |
+
return generated_texts[0]['generated_text']
|
| 57 |
|
| 58 |
+
# Define the page for social media content generation
|
| 59 |
def page_social_media_generator():
|
| 60 |
st.title("Social Media Content Generator")
|
| 61 |
+
|
| 62 |
+
# Retrieve the description saved in the session state on the trending niche page
|
| 63 |
+
description = st.session_state.get('selected_article_description', '')
|
| 64 |
+
|
| 65 |
+
if description:
|
| 66 |
+
st.write(f"Selected Article Description: {description}")
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
+
if st.button('Generate Social Media Post'):
|
| 69 |
with st.spinner('Generating...'):
|
| 70 |
+
post_content = generate_social_media_post(description)
|
| 71 |
st.success('Generated Content:')
|
| 72 |
st.write(post_content)
|
| 73 |
else:
|