File size: 2,113 Bytes
c040d38
 
a8d8832
0b3905f
a8d8832
c040d38
a8d8832
0b3905f
c040d38
0b3905f
c040d38
0b3905f
c040d38
 
 
0b3905f
 
c040d38
 
0b3905f
 
 
 
 
 
 
c040d38
 
0b3905f
 
 
 
 
c040d38
0b3905f
 
 
 
 
 
 
c040d38
 
 
0b3905f
c040d38
0b3905f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from transformers import AutoTokenizer
import transformers
import torch
import streamlit as st

model_name = "tiiuae/falcon-7b-instruct"
tokenizer = AutoTokenizer.from_pretrained(model_name)

generator = transformers.pipeline(
    "text-generation",
    model=model_name,
    tokenizer=tokenizer,
    torch_dtype=torch.bfloat16,
    trust_remote_code=True,
    device_map="auto"
)

def generate_text(prompt, section, max_length=200, top_k=50, temperature=0.7):
    sequences = generator(
        f"{section} - {prompt}",
        max_length=max_length,
        do_sample=True,
        top_k=top_k,
        temperature=temperature,
        num_return_sequences=1,
        eos_token_id=tokenizer.eos_token_id,
    )
    return sequences[0]["generated_text"]

# Streamlit app
st.title("AI-Generated Blog Post")

# Keyword selection input
keywords_input = st.text_input("Step 1: Keyword Selection (Separate keywords with commas)", "Artificial Intelligence")
keywords = [word.strip() for word in keywords_input.split(',')]

# Display generated content on button click
if st.button('Generate Article'):
    if keywords_input:

        generated_text = " ".join(keywords)
        intro_text = generate_text(generated_text, "Introduction", max_length=200, top_k=50, temperature=0.7)
        body_text = generate_text(generated_text, "Body", max_length=500, top_k=50, temperature=0.7)
        conclusion_text = generate_text(generated_text, "Conclusion", max_length=150, top_k=50, temperature=0.7)

        # Displaying the sections
        st.header("Introduction")
        st.write(intro_text)

        st.header("Body")
        st.write(body_text)

        st.header("Conclusion")
        st.write(conclusion_text)
    else:
        st.warning("Please input keywords to generate content.")

# Sidebar with instructions
st.sidebar.title("Instructions")
st.sidebar.write(
    "1. Enter keywords related to the topic you want to generate content about."
    "\n2. Click 'Generate Article' to create the AI-generated blog post."
    "\n3. Explore the Introduction, Body, and Conclusion sections of the generated content."
)