humanize / app.py
Mavhas's picture
Update app.py
69c5fe7 verified
import streamlit as st
from transformers import pipeline
def humanize_text(input_text):
"""
Humanizes the input text using a Hugging Face language model.
Args:
input_text: The text to humanize.
Returns:
The humanized text.
"""
# Choose a suitable model (you might need to experiment)
model_name = "google/flan-t5-large" # Or try other summarization/generation models
try:
humanizer = pipeline("text2text-generation", model=model_name)
# Craft the prompt (this is crucial for good results)
prompt = f"""
Rewrite the following text to make it sound more human, conversational, and engaging.
Use more informal language, add personal touches, and make it less robotic.
Original Text:
{input_text}
Humanized Text:
"""
# Generate the humanized text
humanized_output = humanizer(prompt, max_length=500, num_beams=5, early_stopping=True)[0]['generated_text']
return humanized_output
except Exception as e:
print(f"Error during text humanization: {e}")
return "An error occurred while processing the text."
st.title("Text Humanizer")
input_text = st.text_area("Enter the text you want to humanize:", height=200)
if st.button("Humanize"):
if input_text:
with st.spinner("Humanizing..."):
humanized_text = humanize_text(input_text)
st.subheader("Humanized Output:")
st.write(humanized_text)
else:
st.warning("Please enter some text to humanize.")