aghilTQ commited on
Commit
a04d78d
Β·
verified Β·
1 Parent(s): 9e04f20

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +14 -22
src/streamlit_app.py CHANGED
@@ -8,7 +8,8 @@ from typing import List, Tuple
8
  st.set_page_config(
9
  page_title="Text Syllabification Tool",
10
  page_icon="πŸ”€",
11
- layout="wide"
 
12
  )
13
 
14
  # Initialize pyphen dictionary for English
@@ -106,12 +107,12 @@ def display_colored_text(colored_words: List[Tuple[str, str]]):
106
  html_parts = []
107
  for word, color in colored_words:
108
  if word.strip():
109
- html_parts.append(f'<span style="color: {color}; font-weight: bold; font-size: 18px;">{word}</span>')
110
  else:
111
  html_parts.append(word)
112
 
113
  html_content = ''.join(html_parts)
114
- st.markdown(f'<div style="font-size: 18px; line-height: 1.8; padding: 20px; border: 2px solid #ddd; border-radius: 10px; background-color: #f9f9f9;">{html_content}</div>', unsafe_allow_html=True)
115
 
116
  def display_syllable_breakdown(syllable_breakdown: List[Tuple[str, List[Tuple[str, str]]]]):
117
  """Display syllable breakdown with hyphens"""
@@ -122,7 +123,7 @@ def display_syllable_breakdown(syllable_breakdown: List[Tuple[str, List[Tuple[st
122
  # Create hyphenated syllable display
123
  syllable_spans = []
124
  for syl, color in syllables:
125
- syllable_spans.append(f'<span style="color: {color}; font-weight: bold; font-size: 18px;">{syl}</span>')
126
 
127
  # Join with hyphens for multi-syllable words
128
  if len(syllables) > 1:
@@ -130,22 +131,22 @@ def display_syllable_breakdown(syllable_breakdown: List[Tuple[str, List[Tuple[st
130
  else:
131
  syllable_display = syllable_spans[0]
132
 
133
- html_parts.append(f'<span style="margin-right: 25px; display: inline-block; margin-bottom: 12px;">{syllable_display}</span>')
134
 
135
  if html_parts:
136
  html_content = ''.join(html_parts)
137
- st.markdown(f'<div style="font-size: 18px; line-height: 2.2; padding: 20px; border: 2px solid #ddd; border-radius: 10px; background-color: #f0f8ff;">{html_content}</div>', unsafe_allow_html=True)
138
 
139
  # Main app
140
  def main():
141
  st.title("πŸ”€ Text Syllabification Tool")
142
- st.markdown("Enter text below to see accurate syllable breakdown with color coding using **pyphen** library!")
143
 
144
  # Input text area
145
  input_text = st.text_area(
146
  "Enter your text:",
147
  placeholder="Type or paste your text here...",
148
- height=150,
149
  help="Enter any text to see how words are broken down into syllables"
150
  )
151
 
@@ -168,22 +169,13 @@ def main():
168
  total_words = len([word for word, _ in syllable_breakdown])
169
  total_syllables = sum(len(syls) for _, syls in syllable_breakdown)
170
 
171
- st.markdown("---")
172
- st.markdown(f"**Statistics:** {total_words} words, {total_syllables} syllables")
173
 
174
- # Show syllable counts
175
  if syllable_breakdown:
176
- st.subheader("Syllable Counts per Word")
177
- counts_data = []
178
- for word, syllables in syllable_breakdown:
179
- count = len(syllables)
180
- counts_data.append(f"**{word}**: {count}")
181
-
182
- # Display in columns for better readability
183
- cols = st.columns(3)
184
- for i, count_info in enumerate(counts_data):
185
- with cols[i % 3]:
186
- st.markdown(count_info)
187
 
188
  else:
189
  st.info("πŸ‘† Enter some text above to see the syllabification in action!")
 
8
  st.set_page_config(
9
  page_title="Text Syllabification Tool",
10
  page_icon="πŸ”€",
11
+ layout="wide",
12
+ initial_sidebar_state="collapsed"
13
  )
14
 
15
  # Initialize pyphen dictionary for English
 
107
  html_parts = []
108
  for word, color in colored_words:
109
  if word.strip():
110
+ html_parts.append(f'<span style="color: {color}; font-weight: bold; font-size: 16px;">{word}</span>')
111
  else:
112
  html_parts.append(word)
113
 
114
  html_content = ''.join(html_parts)
115
+ st.markdown(f'<div style="font-size: 16px; line-height: 1.6; padding: 15px; border: 2px solid #ddd; border-radius: 8px; background-color: #f9f9f9;">{html_content}</div>', unsafe_allow_html=True)
116
 
117
  def display_syllable_breakdown(syllable_breakdown: List[Tuple[str, List[Tuple[str, str]]]]):
118
  """Display syllable breakdown with hyphens"""
 
123
  # Create hyphenated syllable display
124
  syllable_spans = []
125
  for syl, color in syllables:
126
+ syllable_spans.append(f'<span style="color: {color}; font-weight: bold; font-size: 16px;">{syl}</span>')
127
 
128
  # Join with hyphens for multi-syllable words
129
  if len(syllables) > 1:
 
131
  else:
132
  syllable_display = syllable_spans[0]
133
 
134
+ html_parts.append(f'<span style="margin-right: 12px; display: inline-block; margin-bottom: 6px;">{syllable_display}</span>')
135
 
136
  if html_parts:
137
  html_content = ''.join(html_parts)
138
+ st.markdown(f'<div style="font-size: 16px; line-height: 1.6; padding: 15px; border: 2px solid #ddd; border-radius: 8px; background-color: #f0f8ff;">{html_content}</div>', unsafe_allow_html=True)
139
 
140
  # Main app
141
  def main():
142
  st.title("πŸ”€ Text Syllabification Tool")
143
+ st.markdown("*Enter text to see accurate syllable breakdown with color coding*")
144
 
145
  # Input text area
146
  input_text = st.text_area(
147
  "Enter your text:",
148
  placeholder="Type or paste your text here...",
149
+ height=100,
150
  help="Enter any text to see how words are broken down into syllables"
151
  )
152
 
 
169
  total_words = len([word for word, _ in syllable_breakdown])
170
  total_syllables = sum(len(syls) for _, syls in syllable_breakdown)
171
 
172
+ st.markdown(f"**πŸ“Š {total_words} words β€’ {total_syllables} syllables**")
 
173
 
174
+ # Show syllable counts in a more compact way
175
  if syllable_breakdown:
176
+ with st.expander("πŸ“ˆ Syllable Counts per Word", expanded=False):
177
+ counts_text = " β€’ ".join([f"{word}: {len(syllables)}" for word, syllables in syllable_breakdown])
178
+ st.markdown(f"<small>{counts_text}</small>", unsafe_allow_html=True)
 
 
 
 
 
 
 
 
179
 
180
  else:
181
  st.info("πŸ‘† Enter some text above to see the syllabification in action!")