Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,45 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from transformers import
|
| 3 |
|
| 4 |
# Load model and tokenizer
|
| 5 |
-
model_name = "
|
| 6 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
-
model =
|
| 8 |
|
| 9 |
-
def generate_blog_post(topic):
|
| 10 |
-
prompt = f"Write a detailed blog post about {topic}."
|
| 11 |
-
inputs = tokenizer
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
# Streamlit interface
|
| 17 |
st.title("Blog Post Generator")
|
| 18 |
-
st.write("Enter a topic to generate a detailed blog post.")
|
| 19 |
|
| 20 |
-
topic = st.text_input("
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
st.write(blog_post)
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
|
| 4 |
# Load model and tokenizer
|
| 5 |
+
model_name = "google/flan-t5-large" # You can use "google/flan-t5-xl" for better results if you have more computational resources
|
| 6 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 8 |
|
| 9 |
+
def generate_blog_post(topic, max_length=1000):
|
| 10 |
+
prompt = f"Write a detailed blog post about {topic}. The blog post should be informative, engaging, and well-structured."
|
| 11 |
+
inputs = tokenizer(prompt, return_tensors="pt", max_length=512, truncation=True)
|
| 12 |
+
|
| 13 |
+
outputs = model.generate(
|
| 14 |
+
inputs.input_ids,
|
| 15 |
+
max_length=max_length,
|
| 16 |
+
num_return_sequences=1,
|
| 17 |
+
do_sample=True,
|
| 18 |
+
top_k=50,
|
| 19 |
+
top_p=0.95,
|
| 20 |
+
temperature=0.7,
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 24 |
+
return generated_text
|
| 25 |
|
| 26 |
# Streamlit interface
|
| 27 |
st.title("Blog Post Generator")
|
|
|
|
| 28 |
|
| 29 |
+
topic = st.text_input("Enter a topic for your blog post:")
|
| 30 |
+
max_length = st.slider("Maximum length of the blog post", min_value=100, max_value=1000, value=500, step=50)
|
| 31 |
+
generate_button = st.button("Generate Blog Post")
|
| 32 |
+
|
| 33 |
+
if generate_button and topic:
|
| 34 |
+
with st.spinner("Generating blog post... This may take a moment."):
|
| 35 |
+
blog_post = generate_blog_post(topic, max_length)
|
| 36 |
+
|
| 37 |
+
# Display the generated blog post
|
| 38 |
+
st.subheader("Generated Blog Post")
|
| 39 |
st.write(blog_post)
|
| 40 |
+
|
| 41 |
+
st.sidebar.title("About")
|
| 42 |
+
st.sidebar.info(
|
| 43 |
+
"This app generates a blog post on a given topic using a large language model. "
|
| 44 |
+
"Enter a topic and click 'Generate Blog Post' to create your content."
|
| 45 |
+
)
|