Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
| 55 |
|
| 56 |
|
| 57 |
-
def page_social_media_generator():
|
| 58 |
|
| 59 |
-
|
| 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(
|
| 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:
|