Shuja007 commited on
Commit
19d2f32
1 Parent(s): d3f25bc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+
4
+ # Load the GPT-2 large model and tokenizer
5
+ model_name = "gpt2-large"
6
+ model = AutoModelForCausalLM.from_pretrained(model_name)
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+
9
+ def generate_blogpost(topic):
10
+ input_text = f"Write a blog post about {topic}:"
11
+ inputs = tokenizer.encode(input_text, return_tensors="pt")
12
+ outputs = model.generate(inputs, max_length=500, num_return_sequences=1)
13
+ generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
14
+ return generated_text
15
+
16
+ # Streamlit UI
17
+ st.title("Blog Post Generator")
18
+ st.write("Generate a blog post for a given topic using GPT-2 large.")
19
+
20
+ topic = st.text_input("Enter the topic:")
21
+ if st.button("Generate"):
22
+ if topic:
23
+ blog_post = generate_blogpost(topic)
24
+ st.write(blog_post)
25
+ else:
26
+ st.write("Please enter a topic to generate a blog post.")