Spaces:
Running
Running
import streamlit as st | |
from gnews import GNews | |
def fetch_news(topic): | |
google_news = GNews(language='en', country='US') # You can customize this | |
news_list = google_news.get_news(topic) | |
articles = [] | |
for news in news_list[:5]: # Get top 5 news articles | |
articles.append({ | |
'title': news['title'], | |
'published_date': news['published date'], | |
'description': news['description'], | |
'url': news['url'], | |
'publisher': news['publisher'] | |
}) | |
return articles | |
from gnews import GNews | |
def page_trending_niche(): | |
st.title("What is trending in my niche?") | |
niche = st.text_input('Enter your niche', 'Technology') | |
if niche: | |
news_items = fetch_news(niche) | |
article_titles = [item['title'] for item in news_items] | |
selected_article = st.selectbox("Select an article to generate a social media post about:", article_titles) | |
selected_article_url = next((item['url'] for item in news_items if item['title'] == selected_article), None) | |
# Save the selected article's URL in the session state to use in another page | |
st.session_state['selected_article_url'] = selected_article_url | |
for item in news_items: | |
st.write(f"**Title:** {item['title']}") | |
st.write(f"**Published Date:** {item['published_date']}") | |
st.write(f"**Description:** {item['description']}") | |
st.write(f"**Publisher:** {item['publisher']}") | |
st.write(f"**URL:** [Read more]({item['url']})") | |
st.write("---") | |
from transformers import pipeline, set_seed | |
generator = pipeline('text-generation', model='gpt2') | |
set_seed(42) | |
def page_social_media_generator(): | |
st.title("Social Media Content Generator") | |
# Using st.columns to create a two-column layout | |
col1, col2 = st.columns([3, 1]) | |
with col1: | |
st.title("German Medical Content Manager") | |
with col2: | |
st.image('Content_Creation_Pic.png', use_column_width=True) | |
# Retrieve the URL saved in the session state on the trending niche page | |
article_url = st.session_state.get('selected_article_url', '') | |
if article_url: | |
st.write(f"Selected Article URL: {article_url}") | |
input_text = st.text_area("Enter additional context or leave empty to use only the article URL:", value=article_url) | |
if st.button('Generate Social Media Post'): | |
with st.spinner('Generating...'): | |
post_content = generator(input_text, max_length=100, num_return_sequences=1)[0]['generated_text'] | |
st.success('Generated Content:') | |
st.write(post_content) | |
else: | |
st.write("Please select an article from the 'What is trending in my niche?' page.") | |
def page_test(): | |
st.title('Test Page') | |
st.write('This is a test page with a test name.') | |
# Setup the sidebar with page selection | |
st.sidebar.title("Anne's Current Projects :star2:") | |
page = st.sidebar.selectbox( | |
'What project do you like to see first?', | |
('trending_niche', 'Social Media Content Generator', 'Test Page')) | |
# Display the selected page | |
if page == 'trending_niche': | |
page_trending_niche() | |
elif page == 'Social Media Content Generator': | |
page_social_media_generator() | |
elif page == 'Test Page': | |
page_test() | |