Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,129 +1,145 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
from enhanced_text_humanizer import EnhancedTextHumanizer
|
| 3 |
-
import time
|
| 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 |
-
st.
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from enhanced_text_humanizer import EnhancedTextHumanizer
|
| 3 |
+
import time
|
| 4 |
+
import nltk
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
# Create nltk_data directory in the project
|
| 8 |
+
if not os.path.exists('nltk_data'):
|
| 9 |
+
os.makedirs('nltk_data')
|
| 10 |
+
|
| 11 |
+
# Set NLTK data path to the project directory
|
| 12 |
+
nltk.data.path.append(os.path.join(os.getcwd(), 'nltk_data'))
|
| 13 |
+
|
| 14 |
+
# Download required NLTK data
|
| 15 |
+
try:
|
| 16 |
+
nltk.data.find('tokenizers/punkt')
|
| 17 |
+
except LookupError:
|
| 18 |
+
nltk.download('punkt')
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def initialize_humanizer():
|
| 22 |
+
with st.spinner('Loading language models... This may take a moment.'):
|
| 23 |
+
humanizer = EnhancedTextHumanizer()
|
| 24 |
+
return humanizer
|
| 25 |
+
|
| 26 |
+
def main():
|
| 27 |
+
st.set_page_config(
|
| 28 |
+
page_title="Text Humanizer App",
|
| 29 |
+
page_icon="🤖",
|
| 30 |
+
layout="wide"
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
st.title("🤖 Enhanced Text Humanizer")
|
| 34 |
+
st.markdown("""
|
| 35 |
+
Transform formal text into more natural, human-like language with various personality styles and regional dialects.
|
| 36 |
+
""")
|
| 37 |
+
|
| 38 |
+
# Initialize the humanizer
|
| 39 |
+
if 'humanizer' not in st.session_state:
|
| 40 |
+
st.session_state.humanizer = initialize_humanizer()
|
| 41 |
+
|
| 42 |
+
# Create two columns for input and output
|
| 43 |
+
col1, col2 = st.columns(2)
|
| 44 |
+
|
| 45 |
+
with col1:
|
| 46 |
+
st.subheader("Input Text")
|
| 47 |
+
input_text = st.text_area(
|
| 48 |
+
"Enter your text here:",
|
| 49 |
+
height=200,
|
| 50 |
+
placeholder="Type or paste your text here..."
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
st.subheader("Customization Options")
|
| 54 |
+
|
| 55 |
+
# Personality selection
|
| 56 |
+
personality = st.selectbox(
|
| 57 |
+
"Select Personality Style:",
|
| 58 |
+
['casual', 'formal', 'academic', 'enthusiastic'],
|
| 59 |
+
help="Choose the personality style for the output text"
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
# Regional dialect selection
|
| 63 |
+
dialect = st.selectbox(
|
| 64 |
+
"Select Regional Dialect:",
|
| 65 |
+
[None, 'us_south', 'british'],
|
| 66 |
+
help="Choose a regional dialect (optional)"
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
# Emotional tone selection
|
| 70 |
+
emotional_tone = st.selectbox(
|
| 71 |
+
"Select Emotional Tone:",
|
| 72 |
+
[None, 'positive', 'negative', 'neutral'],
|
| 73 |
+
help="Choose the emotional tone (optional)"
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
# Transformation intensity
|
| 77 |
+
intensity = st.slider(
|
| 78 |
+
"Transformation Intensity:",
|
| 79 |
+
min_value=0.0,
|
| 80 |
+
max_value=1.0,
|
| 81 |
+
value=0.7,
|
| 82 |
+
step=0.1,
|
| 83 |
+
help="Control how much the text is transformed"
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
# Error inclusion
|
| 87 |
+
add_errors = st.checkbox(
|
| 88 |
+
"Include Natural Speech Errors",
|
| 89 |
+
value=True,
|
| 90 |
+
help="Add realistic speech/typing errors"
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
with col2:
|
| 94 |
+
st.subheader("Output Text")
|
| 95 |
+
if st.button("Transform Text", type="primary"):
|
| 96 |
+
if input_text.strip():
|
| 97 |
+
try:
|
| 98 |
+
with st.spinner('Transforming text...'):
|
| 99 |
+
humanized_text = st.session_state.humanizer.humanize_text(
|
| 100 |
+
input_text,
|
| 101 |
+
intensity=intensity,
|
| 102 |
+
personality=personality,
|
| 103 |
+
add_errors=add_errors,
|
| 104 |
+
regional_dialect=dialect,
|
| 105 |
+
emotional_tone=emotional_tone
|
| 106 |
+
)
|
| 107 |
+
st.text_area(
|
| 108 |
+
"Transformed Text:",
|
| 109 |
+
value=humanized_text,
|
| 110 |
+
height=400,
|
| 111 |
+
disabled=True
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
# Show transformation details
|
| 115 |
+
st.success("Text transformation complete!")
|
| 116 |
+
st.markdown("### Transformation Details")
|
| 117 |
+
st.markdown(f"""
|
| 118 |
+
- **Personality**: {personality}
|
| 119 |
+
- **Dialect**: {dialect if dialect else 'None'}
|
| 120 |
+
- **Emotional Tone**: {emotional_tone if emotional_tone else 'Auto-detected'}
|
| 121 |
+
- **Intensity**: {intensity}
|
| 122 |
+
- **Speech Errors**: {'Enabled' if add_errors else 'Disabled'}
|
| 123 |
+
""")
|
| 124 |
+
except Exception as e:
|
| 125 |
+
st.error(f"An error occurred: {str(e)}")
|
| 126 |
+
else:
|
| 127 |
+
st.warning("Please enter some text to transform.")
|
| 128 |
+
|
| 129 |
+
# Add footer with information
|
| 130 |
+
st.markdown("---")
|
| 131 |
+
st.markdown("""
|
| 132 |
+
### About This Tool
|
| 133 |
+
This text humanizer uses advanced NLP techniques to transform formal text into more natural, human-like language.
|
| 134 |
+
It can apply different personality styles, regional dialects, and emotional tones to the text.
|
| 135 |
+
|
| 136 |
+
**Features:**
|
| 137 |
+
- Multiple personality styles
|
| 138 |
+
- Regional dialect support
|
| 139 |
+
- Emotional tone adjustment
|
| 140 |
+
- Controllable transformation intensity
|
| 141 |
+
- Natural speech error simulation
|
| 142 |
+
""")
|
| 143 |
+
|
| 144 |
+
if __name__ == "__main__":
|
| 145 |
+
main()
|