VarunRavichander commited on
Commit
d5faf9b
·
verified ·
1 Parent(s): 8ffe8f1

Update app.py

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