Spaces:
Sleeping
Sleeping
abdulllah01
commited on
Commit
•
4e630e1
1
Parent(s):
87773f6
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,28 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import
|
3 |
|
4 |
-
|
5 |
-
|
|
|
|
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
3 |
|
4 |
+
# Load GPT-2 model and tokenizer
|
5 |
+
model_name = "gpt2"
|
6 |
+
tokenizer = GPT2Tokenizer.from_pretrained(model_name)
|
7 |
+
model = GPT2LMHeadModel.from_pretrained(model_name)
|
8 |
|
9 |
+
def generate_blog(title):
|
10 |
+
input_ids = tokenizer.encode(title, return_tensors='pt')
|
11 |
+
output = model.generate(input_ids, max_length=500, num_return_sequences=1, no_repeat_ngram_size=2, early_stopping=True)
|
12 |
+
blog = tokenizer.decode(output[0], skip_special_tokens=True)
|
13 |
+
return blog
|
14 |
+
|
15 |
+
# Streamlit app
|
16 |
+
st.title("AI Blog Generator")
|
17 |
+
st.write("Enter a blog title and the AI will generate the blog content for you.")
|
18 |
+
|
19 |
+
# Input blog title
|
20 |
+
title = st.text_input("Blog Title", "")
|
21 |
+
|
22 |
+
if st.button("Generate Blog"):
|
23 |
+
if title:
|
24 |
+
blog_content = generate_blog(title)
|
25 |
+
st.subheader("Generated Blog")
|
26 |
+
st.write(blog_content)
|
27 |
+
else:
|
28 |
+
st.error("Please enter a blog title.")
|