Spaces:
Sleeping
Sleeping
import streamlit as st | |
from transformers import GPT2LMHeadModel, GPT2Tokenizer | |
model_name = "gpt2" | |
tokenizer = GPT2Tokenizer.from_pretrained(model_name) | |
model = GPT2LMHeadModel.from_pretrained(model_name) | |
def make_prompt(example_title, example_content, new_title): | |
prompt = f""" | |
Title: The Benefits of Daily Meditation | |
Blog Content: | |
Meditation is a practice where an individual uses a technique β such as mindfulness, | |
or focusing the mind on a particular object, thought, or activity β to train attention and awareness, | |
and achieve a mentally clear and emotionally calm and stable state. Daily meditation can bring numerous | |
benefits such as reducing stress, improving concentration, and promoting a healthy lifestyle. | |
Title: {new_title} | |
Blog Content: | |
""" | |
return prompt | |
def generate_blog(title): | |
input_ids = tokenizer.encode(title, return_tensors='pt') | |
output = model.generate(input_ids, max_length=800, num_return_sequences=1, no_repeat_ngram_size=2) | |
if st.button("Generate Blog"): | |
if title: | |
title=make_prompt(title) | |
blog_content = generate_blog(title) | |
st.subheader("Generated Blog") | |
st.write(blog_content) | |