File size: 2,301 Bytes
9048c0f
 
 
 
 
 
 
 
 
 
5ae54b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4f498ca
f4878eb
5ae54b6
 
 
f4878eb
 
 
 
5ae54b6
 
95c453c
 
5ae54b6
95c453c
5ae54b6
 
95c453c
 
5ae54b6
 
 
 
9048c0f
5ae54b6
 
 
9048c0f
5ae54b6
 
 
 
 
 
 
9048c0f
 
 
4f498ca
9048c0f
23ea006
 
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
66
67
68
69
70
71
72
73
74
75
76
77
78
# import streamlit as st
# from transformers import pipeline

# # x = st.slider('Select a value')
# # st.write(x, 'squared is', x * x)

# classifier = pipeline("sentiment-analysis")
# sentiment = classifier("I've been waiting for HuggingFace course my whole life.")


# import streamlit as st
# from transformers import pipeline

# # Initialize the sentiment-analysis pipeline
# classifier = pipeline("sentiment-analysis")

# # Streamlit app layout
# st.title("Sentiment Analysis with Hugging Face")
# st.write("Enter a sentence to analyze its sentiment:")

# # Text input for the user
# user_input = st.text_input("Sentence", "")

# # Perform sentiment analysis when the user provides input
# if user_input:
#     sentiment = classifier(user_input)
#     label = sentiment[0]['label']
#     score = sentiment[0]['score']

#     # Display the result
#     st.write(f"**Sentiment:** {label}")
#     st.write(f"**Confidence Score:** {score:.4f}")




import streamlit as st
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

# Load the tokenizer and model
# tokenizer = GPT2Tokenizer.from_pretrained("gpt2-large")
# model = GPT2LMHeadModel.from_pretrained("gpt2-large")
tokenizer = AutoTokenizer.from_pretrained("gpt2-large")
model = AutoModelForCausalLM.from_pretrained("gpt2-large")

def generate_blog(title):

    prompt = f"write a blog about {title}"
    # Encode the input text
    inputs = tokenizer.encode(prompt, return_tensors='pt')
    
    # Generate the output
    # outputs = model.generate(inputs, max_length=500, num_return_sequences=1, pad_token_id=tokenizer.eos_token_id)
    outputs = model.generate(inputs, max_length=500, num_return_sequences=1, do_sample=True, top_p=0.95, top_k=60)

    # Decode the output text
    blog_post = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return blog_post

# Streamlit app
st.title("Blog Post Generator")
title = st.text_input("Enter the blog title")

if st.button("Generate Blog"):
    if title:
        blog_post = generate_blog(title)
        st.subheader("Generated Blog Post")
        st.write(blog_post)
    else:
        st.warning("Please enter a blog title.")




# Optional: Add a slider example (unrelated to sentiment analysis)
# x = st.slider('Select a value')
# st.write(x, 'squared is', x * x)