Spaces:
Sleeping
Sleeping
Download app.py from Zain4s/Blog-Post-Creation-Bot: direct link, hf CLI and curl.
- Browser
- Download file 969 Bytes
-
https://huggingface.co/spaces/Zain4s/Blog-Post-Creation-Bot/resolve/main/app.py
- Command line
-
hf download hf://spaces/Zain4s/Blog-Post-Creation-Bot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Zain4s/Blog-Post-Creation-Bot/resolve/main/app.py
969 Bytes
| # Run app again with same input if model gives repeating output. | |
| import transformers | |
| from transformers import GPT2LMHeadModel, GPT2Tokenizer, GenerationConfig | |
| import streamlit as st | |
| st.markdown( | |
| """ | |
| <style> | |
| .title-input textarea { | |
| height: 100px; | |
| padding-top: 20px; | |
| } | |
| </style> | |
| """, | |
| unsafe_allow_html=True | |
| ) | |
| model_name = "gpt2-large" | |
| model = GPT2LMHeadModel.from_pretrained(model_name) | |
| tokenizer = GPT2Tokenizer.from_pretrained(model_name) | |
| title = st.text_input("Enter a title to generate a blog post:") | |
| if title: | |
| input_prompt = f"Blog Title: {title}\n\nBlog Post:\n" | |
| input_ids = tokenizer.encode(input_prompt, return_tensors='pt') | |
| generation_config = GenerationConfig(max_new_tokens=100, do_sample=True, temperature=0.7) | |
| output_ids = model.generate(input_ids, generation_config=generation_config)[0] | |
| output_text = tokenizer.decode(output_ids, skip_special_tokens=True) | |
| st.write(output_text) | |