AhsanShahid commited on
Commit
386e9b4
·
verified ·
1 Parent(s): 155abd5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -4
app.py CHANGED
@@ -2,7 +2,7 @@ import streamlit as st
2
  import torch
3
  from transformers import AutoTokenizer, AutoModelForCausalLM
4
 
5
- # Load GPT-2 model and tokenizer
6
  @st.cache(allow_output_mutation=True)
7
  def load_model():
8
  tokenizer = AutoTokenizer.from_pretrained("gpt2-large")
@@ -12,7 +12,7 @@ def load_model():
12
  tokenizer, model = load_model()
13
 
14
  st.title("Blog Post Generator")
15
- st.write("Generate a blog post for a given topic using GPT-2.")
16
 
17
  # User input for the blog post topic
18
  topic = st.text_input("Enter the topic for your blog post:")
@@ -24,7 +24,7 @@ if st.button("Generate Blog Post"):
24
  input_text = f"Write a blog post about {topic}."
25
  inputs = tokenizer.encode(input_text, return_tensors="pt")
26
 
27
- # Generate the blog post using GPT-2
28
  outputs = model.generate(inputs, max_length=500, num_return_sequences=1, no_repeat_ngram_size=2, early_stopping=True)
29
 
30
  # Decode the generated text
@@ -35,4 +35,3 @@ if st.button("Generate Blog Post"):
35
  else:
36
  st.write("Please enter a topic to generate a blog post.")
37
 
38
-
 
2
  import torch
3
  from transformers import AutoTokenizer, AutoModelForCausalLM
4
 
5
+ # Load GPT-2 large model and tokenizer
6
  @st.cache(allow_output_mutation=True)
7
  def load_model():
8
  tokenizer = AutoTokenizer.from_pretrained("gpt2-large")
 
12
  tokenizer, model = load_model()
13
 
14
  st.title("Blog Post Generator")
15
+ st.write("Generate a blog post for a given topic using GPT-2 Large.")
16
 
17
  # User input for the blog post topic
18
  topic = st.text_input("Enter the topic for your blog post:")
 
24
  input_text = f"Write a blog post about {topic}."
25
  inputs = tokenizer.encode(input_text, return_tensors="pt")
26
 
27
+ # Generate the blog post using GPT-2 large
28
  outputs = model.generate(inputs, max_length=500, num_return_sequences=1, no_repeat_ngram_size=2, early_stopping=True)
29
 
30
  # Decode the generated text
 
35
  else:
36
  st.write("Please enter a topic to generate a blog post.")
37