Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
model_name = "gpt2"
|
| 4 |
+
text_generator = pipeline("text-generation", model=model_name)
|
| 5 |
+
def generate_blog(topic, word_count):
|
| 6 |
+
try:
|
| 7 |
+
word_count = int(word_count)
|
| 8 |
+
prompt = f"Write a detailed blog about: {topic}\n\n"
|
| 9 |
+
generated_text = text_generator(prompt, max_length=word_count, num_return_sequences=1)
|
| 10 |
+
return generated_text[0]["generated_text"]
|
| 11 |
+
except Exception as e:
|
| 12 |
+
return f"Error: {str(e)}"
|
| 13 |
+
st.title("Blog Generator")
|
| 14 |
+
st.write("Provide a topic and word count to generate a blog.")
|
| 15 |
+
topic = st.text_input("Blog Topic", placeholder="Enter the topic here")
|
| 16 |
+
word_count = st.text_input("Word Count", placeholder="Enter the desired word count")
|
| 17 |
+
if st.button("Generate Blog"):
|
| 18 |
+
if topic and word_count.isdigit():
|
| 19 |
+
with st.spinner("Generating blog..."):
|
| 20 |
+
blog_content = generate_blog(topic, word_count)
|
| 21 |
+
st.text_area("Generated Blog Content", value=blog_content, height=300)
|
| 22 |
+
else:
|
| 23 |
+
st.error("Please enter a valid topic and numerical word count.")
|