Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,6 +20,25 @@ def fetch_news(topic):
|
|
| 20 |
|
| 21 |
from gnews import GNews
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
def page_trending_niche():
|
| 24 |
st.title("What is trending in my niche?")
|
| 25 |
niche = st.text_input('Enter your niche', 'Technology')
|
|
@@ -48,30 +67,23 @@ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
|
| 48 |
|
| 49 |
def generate_social_media_post(article_text):
|
| 50 |
# Ensure the article text is not too long for the model
|
| 51 |
-
article_text = article_text[:1024] #
|
| 52 |
summary = summarizer(article_text, max_length=130, min_length=30, do_sample=False)[0]['summary_text']
|
| 53 |
return summary
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
def page_social_media_generator():
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
st.title("Social Media Content Generator")
|
| 61 |
-
with col2:
|
| 62 |
-
st.image('Content_Creation_Pic.png', use_column_width=True)
|
| 63 |
-
|
| 64 |
# Retrieve the URL saved in the session state on the trending niche page
|
| 65 |
article_url = st.session_state.get('selected_article_url', '')
|
| 66 |
-
|
| 67 |
if article_url:
|
| 68 |
st.write(f"Selected Article URL: {article_url}")
|
| 69 |
|
| 70 |
-
#
|
| 71 |
-
|
| 72 |
-
article_text = "The full text of the article goes here."
|
| 73 |
|
| 74 |
-
if st.button('Generate Social Media Post'):
|
| 75 |
with st.spinner('Generating...'):
|
| 76 |
post_content = generate_social_media_post(article_text)
|
| 77 |
st.success('Generated Content:')
|
|
|
|
| 20 |
|
| 21 |
from gnews import GNews
|
| 22 |
|
| 23 |
+
# Function to fetch the content from a URL
|
| 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?")
|
| 44 |
niche = st.text_input('Enter your niche', 'Technology')
|
|
|
|
| 67 |
|
| 68 |
def generate_social_media_post(article_text):
|
| 69 |
# Ensure the article text is not too long for the model
|
| 70 |
+
article_text = article_text[:1024] # Truncate the text to fit the model's maximum length capacity
|
| 71 |
summary = summarizer(article_text, max_length=130, min_length=30, do_sample=False)[0]['summary_text']
|
| 72 |
return summary
|
| 73 |
|
|
|
|
|
|
|
| 74 |
def page_social_media_generator():
|
| 75 |
+
st.title("Social Media Content Generator")
|
| 76 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
# Retrieve the URL saved in the session state on the trending niche page
|
| 78 |
article_url = st.session_state.get('selected_article_url', '')
|
| 79 |
+
|
| 80 |
if article_url:
|
| 81 |
st.write(f"Selected Article URL: {article_url}")
|
| 82 |
|
| 83 |
+
# Fetch the content of the article from the URL
|
| 84 |
+
article_text = get_article_content(article_url)
|
|
|
|
| 85 |
|
| 86 |
+
if article_text and st.button('Generate Social Media Post'):
|
| 87 |
with st.spinner('Generating...'):
|
| 88 |
post_content = generate_social_media_post(article_text)
|
| 89 |
st.success('Generated Content:')
|