abdulllah01 commited on
Commit
2e7855d
·
verified ·
1 Parent(s): 52101ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -0
app.py CHANGED
@@ -5,6 +5,21 @@ model_name = "gpt2"
5
  tokenizer = GPT2Tokenizer.from_pretrained(model_name)
6
  model = GPT2LMHeadModel.from_pretrained(model_name)
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  def generate_blog(title):
9
  input_ids = tokenizer.encode(title, return_tensors='pt')
10
  output = model.generate(input_ids, max_length=800, num_return_sequences=1, no_repeat_ngram_size=2)
@@ -19,6 +34,7 @@ title = st.text_input("Blog Title", "")
19
 
20
  if st.button("Generate Blog"):
21
  if title:
 
22
  blog_content = generate_blog(title)
23
  st.subheader("Generated Blog")
24
  st.write(blog_content)
 
5
  tokenizer = GPT2Tokenizer.from_pretrained(model_name)
6
  model = GPT2LMHeadModel.from_pretrained(model_name)
7
 
8
+ def make_prompt(example_title, example_content, new_title):
9
+ prompt = f"""
10
+ Title: The Benefits of Daily Meditation
11
+
12
+ Blog Content:
13
+ Meditation is a practice where an individual uses a technique – such as mindfulness,
14
+ or focusing the mind on a particular object, thought, or activity – to train attention and awareness,
15
+ and achieve a mentally clear and emotionally calm and stable state. Daily meditation can bring numerous
16
+ benefits such as reducing stress, improving concentration, and promoting a healthy lifestyle.
17
+
18
+ Title: {new_title}
19
+
20
+ Blog Content:
21
+ """
22
+ return prompt
23
  def generate_blog(title):
24
  input_ids = tokenizer.encode(title, return_tensors='pt')
25
  output = model.generate(input_ids, max_length=800, num_return_sequences=1, no_repeat_ngram_size=2)
 
34
 
35
  if st.button("Generate Blog"):
36
  if title:
37
+ title=make_prompt(title)
38
  blog_content = generate_blog(title)
39
  st.subheader("Generated Blog")
40
  st.write(blog_content)