Spaces:
Sleeping
Sleeping
import streamlit as st | |
from transformers import pipeline | |
import time | |
# Load the text generation pipeline (Use a smaller model if 2.7B is too resource-intensive) | |
generator = pipeline("text-generation", model="EleutherAI/gpt-neo-2.7B") | |
def generate_article(title, intro, key_points, tone, style): | |
# Prompt to guide the model toward a humanized output | |
prompt = ( | |
f"Write an article with the following details:\n" | |
f"Title: {title}\n\n" | |
f"Introduction: {intro}\n\n" | |
f"Main Points:\n{key_points}\n\n" | |
f"Tone: {tone}\nStyle: {style}\n\n" | |
f"Please write in a human-like, engaging, and coherent manner.\n\n" | |
f"Full Article:\n" | |
) | |
start_time = time.time() | |
result = generator( | |
prompt, | |
max_length=4000, # Approximate length for 2000 words | |
temperature=0.85, # Increased temperature for a more human-like output | |
top_p=0.9, # Nucleus sampling for coherence | |
repetition_penalty=1.2 # Reduces repetitiveness | |
) | |
end_time = time.time() | |
generated_text = result[0]['generated_text'] | |
time_taken = f"Time taken: {round(end_time - start_time, 2)} seconds" | |
return generated_text, time_taken | |
# Streamlit App Structure | |
st.title("Humanized Article Writer Chatbot") | |
st.write("Generate a human-like, 2000-word article by providing structured prompts. This tool is designed to produce natural, engaging text.") | |
# Input fields | |
title = st.text_input("Article Title") | |
intro = st.text_area("Introduction (What is the article about?)", placeholder="Enter the main theme or opening lines...") | |
key_points = st.text_area("Key Points (Provide bullet points or main ideas)", placeholder="List the main points or topics to cover...") | |
tone = st.text_input("Tone (e.g., Informative, Casual, Formal)", placeholder="Enter the desired tone...") | |
style = st.text_input("Style (e.g., Blog Post, Essay, News Article)", placeholder="Enter the desired style...") | |
# Generate article button | |
if st.button("Generate Article"): | |
if title and intro and key_points and tone and style: | |
with st.spinner("Generating article..."): | |
generated_text, time_taken = generate_article(title, intro, key_points, tone, style) | |
st.success(time_taken) | |
st.write(generated_text) | |
else: | |
st.warning("Please fill in all fields before generating the article.") | |