Spaces:
Sleeping
Sleeping
Download app.py from omair14/BlogPost_Omair: direct link, hf CLI and curl.
- Browser
- Download file 961 Bytes
-
https://huggingface.co/spaces/omair14/BlogPost_Omair/resolve/main/app.py
- Command line
-
hf download hf://spaces/omair14/BlogPost_Omair/app.py
-
curl -L -o app.py https://huggingface.co/spaces/omair14/BlogPost_Omair/resolve/main/app.py
961 Bytes
| import streamlit as st | |
| from transformers import pipeline | |
| # Load the text generation pipeline with gpt2-large | |
| try: | |
| generator = pipeline('text-generation', model='gpt2-large') | |
| st.write("Model loaded successfully.") | |
| except Exception as e: | |
| st.write(f"Error loading model: {e}") | |
| def generate_blog_post(topic): | |
| try: | |
| # Generate a blog post based on the given topic | |
| command = f"Here is a blog post on the topic - \"{topic}\": " | |
| command = command.lower() | |
| response = generator(command, max_length=500, num_return_sequences=1) | |
| return response[0]['generated_text'][len(command):] | |
| except Exception as e: | |
| return f"Error generating blog post: {e}" | |
| # Streamlit app | |
| st.title("Blog Post Generator") | |
| topic = st.text_input("Enter the topic for the blog post:") | |
| if st.button("Generate"): | |
| with st.spinner('Generating blog post...'): | |
| blog_post = generate_blog_post(topic) | |
| st.write(blog_post) | |