Spaces:
Running
Running
import streamlit as st | |
from transformers import pipeline | |
from pygooglenews import GoogleNews | |
# Initialize a text generation pipeline | |
generator = pipeline('text-generation', model='dbmdz/german-gpt2') | |
# Function to fetch top stories related to a specific topic | |
def fetch_top_stories(topic, language='de', country='GER'): | |
gn = GoogleNews(lang=language, country=country) | |
search_results = gn.search(topic) | |
top_stories = [] | |
for story in search_results['entries']: | |
story_data = { | |
'title': story.title, | |
'link': story.link, | |
'published': story.published | |
} | |
top_stories.append(story_data) | |
return top_stories | |
# Define the page for trending niche news | |
def page_trending_niche(): | |
col1, col2 = st.columns([3, 1]) | |
with col1: | |
st.title("What is trending in my niche?") | |
with col2: | |
st.image('Robot.png', use_column_width=True) | |
niche = st.text_input('Enter your niche', 'German clinics') | |
if niche: | |
news_items = fetch_top_stories(niche) | |
for item in news_items: | |
st.write(f"**Title:** {item['title']}") | |
st.write(f"**Link:** [Read more]({item['link']})") | |
st.write(f"**Published:** {item['published']}") | |
st.write("---") | |
# Define the pages | |
def page_social_media_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) | |
input_topic = st.text_input('Enter a medical topic', 'Type 1 Diabetes') | |
st.write(f"Creating social media content for: {input_topic}") | |
def generate_content(topic): | |
generated_text = generator(f"Letzte Nachrichten über {topic}:", max_length=50, num_return_sequences=1) | |
return generated_text[0]['generated_text'] | |
if st.button('Generate Social Media Post'): | |
with st.spinner('Generating...'): | |
post_content = generate_content(input_topic) | |
st.success('Generated Content:') | |
st.write(post_content) | |
st.write('Generated social media posts will appear here after clicking the "Generate" button.') | |
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() | |