Spaces:
Sleeping
Sleeping
AhsanShahid
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,28 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
if text:
|
8 |
-
out = pipe(text)
|
9 |
-
st.json(out)
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Load GPT-2 model and tokenizer
|
5 |
+
@st.cache(allow_output_mutation=True)
|
6 |
+
def load_model():
|
7 |
+
return pipeline("text-generation", model="gpt-2")
|
8 |
+
|
9 |
+
model = load_model()
|
10 |
+
|
11 |
+
st.title("Blog Post Generator")
|
12 |
+
st.write("Generate a blog post for a given topic using GPT-2.")
|
13 |
+
|
14 |
+
# User input for the blog post topic
|
15 |
+
topic = st.text_input("Enter the topic for your blog post:")
|
16 |
+
|
17 |
+
# Generate blog post button
|
18 |
+
if st.button("Generate Blog Post"):
|
19 |
+
if topic:
|
20 |
+
# Generate the blog post using GPT-2
|
21 |
+
result = model(f"Write a blog post about {topic}.", max_length=500, num_return_sequences=1)
|
22 |
+
blog_post = result[0]['generated_text']
|
23 |
+
|
24 |
+
st.write("### Generated Blog Post:")
|
25 |
+
st.write(blog_post)
|
26 |
+
else:
|
27 |
+
st.write("Please enter a topic to generate a blog post.")
|
28 |
|
|
|
|
|
|