Anne314159 commited on
Commit
90e5033
·
verified ·
1 Parent(s): 0f70347

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -9
app.py CHANGED
@@ -1,5 +1,7 @@
1
  import streamlit as st
2
  from gnews import GNews
 
 
3
 
4
  def fetch_news(topic):
5
  google_news = GNews(language='en', country='US') # You can customize this
@@ -40,35 +42,43 @@ def page_trending_niche():
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')
 
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='en', country='US') # You can customize this
 
42
 
43
 
44
 
45
+ # Load pre-trained model and tokenizer
46
+ tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
47
+ model = GPT2LMHeadModel.from_pretrained('gpt2')
48
+
49
+ def generate_social_media_post(article_url):
50
+ prompt = f"Write a social media post about this article: {article_url}"
51
+ inputs = tokenizer.encode(prompt, return_tensors='pt')
52
+ outputs = model.generate(inputs, max_length=100, num_return_sequences=1, no_repeat_ngram_size=2)
53
+ post = tokenizer.decode(outputs[0], skip_special_tokens=True)
54
+ return post
55
+
56
 
57
  def page_social_media_generator():
 
58
 
59
  # Using st.columns to create a two-column layout
60
  col1, col2 = st.columns([3, 1])
61
  with col1:
62
+ st.title("Social Media Content Generator")
63
  with col2:
64
  st.image('Content_Creation_Pic.png', use_column_width=True)
65
+
66
  # Retrieve the URL saved in the session state on the trending niche page
67
  article_url = st.session_state.get('selected_article_url', '')
68
+
69
  if article_url:
70
  st.write(f"Selected Article URL: {article_url}")
 
71
 
72
  if st.button('Generate Social Media Post'):
73
  with st.spinner('Generating...'):
74
+ post_content = generate_social_media_post(article_url)
75
  st.success('Generated Content:')
76
  st.write(post_content)
77
  else:
78
  st.write("Please select an article from the 'What is trending in my niche?' page.")
79
 
80
+
81
+
82
 
83
  def page_test():
84
  st.title('Test Page')