BlogWriter / app.py
Siri23's picture
Create app.py
268b556 verified
raw
history blame
1.16 kB
from transformers import pipeline
import streamlit as st
# Load the text generation pipeline
pipe = pipeline("text-generation", model="meta-llama/Meta-Llama-3-8B")
def generate_blog(topic, no_words):
# Create the prompt
prompt = f"Write a blog on the topic '{topic}' within {no_words} words."
# Generate the blog content
result = pipe(prompt, max_length=int(no_words), num_return_sequences=1)
# Extract the generated text
blog_content = result[0]['generated_text']
return blog_content
# Streamlit app
st.set_page_config(page_title="Blog Generator", page_icon="πŸ“")
st.title("Blog Content Generator πŸ“")
# Input fields
topic = st.text_input("Enter the Blog Topic")
no_words = st.number_input("Enter the Number of Words", min_value=50, max_value=1000, value=200, step=50)
if st.button("Generate Blog"):
if topic and no_words:
with st.spinner("Generating blog content..."):
blog_content = generate_blog(topic, no_words)
st.subheader("Generated Blog Content")
st.write(blog_content)
else:
st.error("Please provide both the blog topic and the number of words.")