File size: 1,567 Bytes
4ed94a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69c5fe7
4ed94a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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.")