Spaces:
Sleeping
Sleeping
| # 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) |