Anne314159 commited on
Commit
4e47031
·
verified ·
1 Parent(s): e930297

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -22
app.py CHANGED
@@ -16,16 +16,19 @@ def fetch_news(topic):
16
  })
17
  return articles
18
 
 
 
19
  def page_trending_niche():
20
- col1, col2 = st.columns([3, 1])
21
- with col1:
22
- st.title("What is trending in my niche?")
23
- with col2:
24
- st.image('Robot.png', use_column_width=True)
25
-
26
  niche = st.text_input('Enter your niche', 'Technology')
27
  if niche:
28
  news_items = fetch_news(niche)
 
 
 
 
 
 
29
  for item in news_items:
30
  st.write(f"**Title:** {item['title']}")
31
  st.write(f"**Published Date:** {item['published_date']}")
@@ -36,31 +39,36 @@ def page_trending_niche():
36
 
37
 
38
 
39
- # Define the pages
40
- def page_social_media_generator():
41
 
 
 
 
 
 
 
 
42
  # Using st.columns to create a two-column layout
43
  col1, col2 = st.columns([3, 1])
44
  with col1:
45
  st.title("German Medical Content Manager")
46
  with col2:
47
  st.image('Content_Creation_Pic.png', use_column_width=True)
48
-
49
 
50
- input_topic = st.text_input('Enter a medical topic', 'Type 1 Diabetes')
51
- st.write(f"Creating social media content for: {input_topic}")
52
-
53
- def generate_content(topic):
54
- generated_text = generator(f"Letzte Nachrichten über {topic}:", max_length=50, num_return_sequences=1)
55
- return generated_text[0]['generated_text']
56
-
57
- if st.button('Generate Social Media Post'):
58
- with st.spinner('Generating...'):
59
- post_content = generate_content(input_topic)
60
- st.success('Generated Content:')
61
- st.write(post_content)
 
 
62
 
63
- st.write('Generated social media posts will appear here after clicking the "Generate" button.')
64
 
65
  def page_test():
66
  st.title('Test Page')
 
16
  })
17
  return articles
18
 
19
+ from gnews import GNews
20
+
21
  def page_trending_niche():
22
+ st.title("What is trending in my niche?")
 
 
 
 
 
23
  niche = st.text_input('Enter your niche', 'Technology')
24
  if niche:
25
  news_items = fetch_news(niche)
26
+ article_titles = [item['title'] for item in news_items]
27
+ selected_article = st.selectbox("Select an article to generate a social media post about:", article_titles)
28
+ selected_article_url = next((item['url'] for item in news_items if item['title'] == selected_article), None)
29
+
30
+ # Save the selected article's URL in the session state to use in another page
31
+ st.session_state['selected_article_url'] = selected_article_url
32
  for item in news_items:
33
  st.write(f"**Title:** {item['title']}")
34
  st.write(f"**Published Date:** {item['published_date']}")
 
39
 
40
 
41
 
 
 
42
 
43
+ from transformers import pipeline, set_seed
44
+ generator = pipeline('text-generation', model='gpt2')
45
+ set_seed(42)
46
+
47
+ def page_social_media_generator():
48
+ st.title("Social Media Content Generator")
49
+
50
  # Using st.columns to create a two-column layout
51
  col1, col2 = st.columns([3, 1])
52
  with col1:
53
  st.title("German Medical Content Manager")
54
  with col2:
55
  st.image('Content_Creation_Pic.png', use_column_width=True)
 
56
 
57
+ # Retrieve the URL saved in the session state on the trending niche page
58
+ article_url = st.session_state.get('selected_article_url', '')
59
+
60
+ if article_url:
61
+ st.write(f"Selected Article URL: {article_url}")
62
+ input_text = st.text_area("Enter additional context or leave empty to use only the article URL:", value=article_url)
63
+
64
+ if st.button('Generate Social Media Post'):
65
+ with st.spinner('Generating...'):
66
+ post_content = generator(input_text, max_length=100, num_return_sequences=1)[0]['generated_text']
67
+ st.success('Generated Content:')
68
+ st.write(post_content)
69
+ else:
70
+ st.write("Please select an article from the 'What is trending in my niche?' page.")
71
 
 
72
 
73
  def page_test():
74
  st.title('Test Page')