Spaces:
Sleeping
Sleeping
| 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 | |
| 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() | |