sabssag commited on
Commit
5f37b42
·
verified ·
1 Parent(s): ee5e01f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -12,7 +12,7 @@ st.title("GPT-2 Blog Post Generator")
12
  # Text input for the user
13
  text = st.text_area("Enter your Topic: ")
14
 
15
- if text:
16
  try:
17
  # Encode input text
18
  encoded_input = tokenizer(text, return_tensors='pt')
@@ -33,10 +33,13 @@ if text:
33
 
34
  # Decode generated text
35
  generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
 
36
 
37
  # Display the generated text
38
  st.subheader("Generated Blog Post")
39
  st.write(generated_text)
40
  except Exception as e:
41
  st.error(f"An error occurred: {e}")
42
-
 
 
 
12
  # Text input for the user
13
  text = st.text_area("Enter your Topic: ")
14
 
15
+ def generate_text(text):
16
  try:
17
  # Encode input text
18
  encoded_input = tokenizer(text, return_tensors='pt')
 
33
 
34
  # Decode generated text
35
  generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
36
+ return generate_text
37
 
38
  # Display the generated text
39
  st.subheader("Generated Blog Post")
40
  st.write(generated_text)
41
  except Exception as e:
42
  st.error(f"An error occurred: {e}")
43
+ if st.button("Generate"):
44
+ generated_text = generate_text(text)
45
+ st.write(generated_text)