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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -41,22 +41,20 @@ def page_trending_niche():
41
 
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")
@@ -69,9 +67,13 @@ def page_social_media_generator():
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:
 
41
 
42
 
43
 
44
+ from transformers import pipeline
 
 
 
45
 
46
+ # Initialize the summarization pipeline with BART
47
+ 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] # BART has a limit on the length of the text it can process
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
  col1, col2 = st.columns([3, 1])
59
  with col1:
60
  st.title("Social Media Content Generator")
 
67
  if article_url:
68
  st.write(f"Selected Article URL: {article_url}")
69
 
70
+ # Example placeholder for article text fetching
71
+ # In a real application, replace the following line with code to fetch the article's text from `article_url`
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:')
78
  st.write(post_content)
79
  else: