Spaces:
Build error
Build error
File size: 5,448 Bytes
d5faf9b 44bf8a4 f3620c1 d5faf9b f3620c1 eb9df21 f3620c1 d5faf9b f3620c1 d5faf9b f3620c1 d5faf9b | 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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | import streamlit as st
import nltk
import os
from enhanced_text_humanizer import EnhancedTextHumanizer
import time
# Set NLTK data path
nltk.data.path.append('./nltk_data')
# Download required NLTK resources at startup
@st.cache_resource
def download_nltk_resources():
try:
# Create NLTK data directory if it doesn't exist
os.makedirs('nltk_data', exist_ok=True)
# Download required resources
nltk.download('punkt', download_dir='./nltk_data')
nltk.download('punkt_tab', download_dir='./nltk_data')
nltk.download('averaged_perceptron_tagger', download_dir='./nltk_data')
nltk.download('wordnet', download_dir='./nltk_data')
nltk.download('omw-1.4', download_dir='./nltk_data')
return True
except Exception as e:
st.error(f"Error downloading NLTK resources: {e}")
return False
def initialize_humanizer():
# First ensure NLTK resources are downloaded
resources_downloaded = download_nltk_resources()
with st.spinner('Loading language models... This may take a moment.'):
humanizer = EnhancedTextHumanizer()
return humanizer
def main():
st.set_page_config(
page_title="Text Humanizer App",
page_icon="🤖",
layout="wide"
)
st.title("🤖 Enhanced Text Humanizer")
st.markdown("""
Transform formal text into more natural, human-like language with various personality styles and regional dialects.
""")
# Initialize the humanizer
if 'humanizer' not in st.session_state:
st.session_state.humanizer = initialize_humanizer()
# Create two columns for input and output
col1, col2 = st.columns(2)
with col1:
st.subheader("Input Text")
input_text = st.text_area(
"Enter your text here:",
height=200,
placeholder="Type or paste your text here..."
)
st.subheader("Customization Options")
# Personality selection
personality = st.selectbox(
"Select Personality Style:",
['casual', 'formal', 'academic', 'enthusiastic'],
help="Choose the personality style for the output text"
)
# Regional dialect selection
dialect = st.selectbox(
"Select Regional Dialect:",
[None, 'us_south', 'british'],
help="Choose a regional dialect (optional)"
)
# Emotional tone selection
emotional_tone = st.selectbox(
"Select Emotional Tone:",
[None, 'positive', 'negative', 'neutral'],
help="Choose the emotional tone (optional)"
)
# Transformation intensity
intensity = st.slider(
"Transformation Intensity:",
min_value=0.0,
max_value=1.0,
value=0.7,
step=0.1,
help="Control how much the text is transformed"
)
# Error inclusion
add_errors = st.checkbox(
"Include Natural Speech Errors",
value=True,
help="Add realistic speech/typing errors"
)
with col2:
st.subheader("Output Text")
if st.button("Transform Text", type="primary"):
if input_text.strip():
try:
with st.spinner('Transforming text...'):
humanized_text = st.session_state.humanizer.humanize_text(
input_text,
intensity=intensity,
personality=personality,
add_errors=add_errors,
regional_dialect=dialect,
emotional_tone=emotional_tone
)
st.text_area(
"Transformed Text:",
value=humanized_text,
height=400,
disabled=True
)
# Show transformation details
st.success("Text transformation complete!")
st.markdown("### Transformation Details")
st.markdown(f"""
- **Personality**: {personality}
- **Dialect**: {dialect if dialect else 'None'}
- **Emotional Tone**: {emotional_tone if emotional_tone else 'Auto-detected'}
- **Intensity**: {intensity}
- **Speech Errors**: {'Enabled' if add_errors else 'Disabled'}
""")
except Exception as e:
st.error(f"An error occurred: {str(e)}")
else:
st.warning("Please enter some text to transform.")
# Add footer with information
st.markdown("---")
st.markdown("""
### About This Tool
This text humanizer uses advanced NLP techniques to transform formal text into more natural, human-like language.
It can apply different personality styles, regional dialects, and emotional tones to the text.
**Features:**
- Multiple personality styles
- Regional dialect support
- Emotional tone adjustment
- Controllable transformation intensity
- Natural speech error simulation
""")
if __name__ == "__main__":
main()
|