File size: 1,164 Bytes
268b556
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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.")