Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
import time
|
4 |
+
|
5 |
+
# Load the text generation pipeline (Use a smaller model if 2.7B is too resource-intensive)
|
6 |
+
generator = pipeline("text-generation", model="EleutherAI/gpt-neo-2.7B")
|
7 |
+
|
8 |
+
def generate_article(title, intro, key_points, tone, style):
|
9 |
+
# Prompt to guide the model toward a humanized output
|
10 |
+
prompt = (
|
11 |
+
f"Write an article with the following details:\n"
|
12 |
+
f"Title: {title}\n\n"
|
13 |
+
f"Introduction: {intro}\n\n"
|
14 |
+
f"Main Points:\n{key_points}\n\n"
|
15 |
+
f"Tone: {tone}\nStyle: {style}\n\n"
|
16 |
+
f"Please write in a human-like, engaging, and coherent manner.\n\n"
|
17 |
+
f"Full Article:\n"
|
18 |
+
)
|
19 |
+
|
20 |
+
start_time = time.time()
|
21 |
+
result = generator(
|
22 |
+
prompt,
|
23 |
+
max_length=4000, # Approximate length for 2000 words
|
24 |
+
temperature=0.85, # Increased temperature for a more human-like output
|
25 |
+
top_p=0.9, # Nucleus sampling for coherence
|
26 |
+
repetition_penalty=1.2 # Reduces repetitiveness
|
27 |
+
)
|
28 |
+
end_time = time.time()
|
29 |
+
|
30 |
+
generated_text = result[0]['generated_text']
|
31 |
+
time_taken = f"Time taken: {round(end_time - start_time, 2)} seconds"
|
32 |
+
return generated_text, time_taken
|
33 |
+
|
34 |
+
# Streamlit App Structure
|
35 |
+
st.title("Humanized Article Writer Chatbot")
|
36 |
+
st.write("Generate a human-like, 2000-word article by providing structured prompts. This tool is designed to produce natural, engaging text.")
|
37 |
+
|
38 |
+
# Input fields
|
39 |
+
title = st.text_input("Article Title")
|
40 |
+
intro = st.text_area("Introduction (What is the article about?)", placeholder="Enter the main theme or opening lines...")
|
41 |
+
key_points = st.text_area("Key Points (Provide bullet points or main ideas)", placeholder="List the main points or topics to cover...")
|
42 |
+
tone = st.text_input("Tone (e.g., Informative, Casual, Formal)", placeholder="Enter the desired tone...")
|
43 |
+
style = st.text_input("Style (e.g., Blog Post, Essay, News Article)", placeholder="Enter the desired style...")
|
44 |
+
|
45 |
+
# Generate article button
|
46 |
+
if st.button("Generate Article"):
|
47 |
+
if title and intro and key_points and tone and style:
|
48 |
+
with st.spinner("Generating article..."):
|
49 |
+
generated_text, time_taken = generate_article(title, intro, key_points, tone, style)
|
50 |
+
st.success(time_taken)
|
51 |
+
st.write(generated_text)
|
52 |
+
else:
|
53 |
+
st.warning("Please fill in all fields before generating the article.")
|