Update backup7.app.py
Browse files- backup7.app.py +34 -12
backup7.app.py
CHANGED
|
@@ -23,9 +23,28 @@ st.set_page_config(layout="wide", initial_sidebar_state="collapsed")
|
|
| 23 |
def get_timestamp_prefix():
|
| 24 |
central = pytz.timezone("US/Central")
|
| 25 |
now = datetime.now(central)
|
| 26 |
-
# Format: three-letter day, MMDD,
|
| 27 |
return now.strftime("%a %m%d %I%M%p").upper()
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
async def generate_audio(text, voice, filename):
|
| 30 |
communicate = edge_tts.Communicate(text, voice)
|
| 31 |
await communicate.save(filename)
|
|
@@ -40,6 +59,7 @@ def apply_emoji_font(text, emoji_font):
|
|
| 40 |
r"\U0001F780-\U0001F7FF"
|
| 41 |
r"\U0001F800-\U0001F8FF"
|
| 42 |
r"\U0001F900-\U0001F9FF"
|
|
|
|
| 43 |
r"\U0001FA00-\U0001FA6F"
|
| 44 |
r"\U0001FA70-\U0001FAFF"
|
| 45 |
r"\u2600-\u26FF"
|
|
@@ -90,10 +110,6 @@ def create_pdf(markdown_text, base_font_size, render_with_bold, auto_bold_number
|
|
| 90 |
'ItemStyle', parent=styles['Normal'], fontName="DejaVuSans",
|
| 91 |
fontSize=base_font_size, leading=base_font_size * 1.15, spaceAfter=1
|
| 92 |
)
|
| 93 |
-
bold_style = ParagraphStyle(
|
| 94 |
-
'BoldStyle', parent=styles['Normal'], fontName="NotoEmoji-Bold",
|
| 95 |
-
fontSize=base_font_size, leading=base_font_size * 1.15, spaceAfter=1
|
| 96 |
-
)
|
| 97 |
numbered_bold_style = ParagraphStyle(
|
| 98 |
'NumberedBoldStyle', parent=styles['Normal'], fontName="NotoEmoji-Bold",
|
| 99 |
fontSize=base_font_size + 1 if enlarge_numbered else base_font_size,
|
|
@@ -208,14 +224,14 @@ with st.sidebar:
|
|
| 208 |
if selected_md:
|
| 209 |
with open(f"{selected_md}.md", "w", encoding="utf-8") as f:
|
| 210 |
f.write(edited_markdown)
|
| 211 |
-
st.
|
| 212 |
|
| 213 |
# Create a timestamp prefix for file naming
|
| 214 |
prefix = get_timestamp_prefix()
|
| 215 |
|
| 216 |
-
# Download button for Markdown with new naming convention
|
| 217 |
st.download_button(
|
| 218 |
-
label="Save Markdown",
|
| 219 |
data=st.session_state.markdown_content,
|
| 220 |
file_name=f"{prefix} {selected_md}.md" if selected_md else f"{prefix} default.md",
|
| 221 |
mime="text/markdown"
|
|
@@ -225,13 +241,20 @@ with st.sidebar:
|
|
| 225 |
VOICES = ["en-US-AriaNeural", "en-US-JennyNeural", "en-GB-SoniaNeural", "en-US-GuyNeural", "en-US-AnaNeural"]
|
| 226 |
selected_voice = st.selectbox("Select Voice for TTS", options=VOICES, index=0)
|
| 227 |
if st.button("Generate Audio"):
|
|
|
|
|
|
|
| 228 |
# Create a filename for the audio file using the timestamp, markdown name, and selected voice
|
| 229 |
audio_filename = f"{prefix} {selected_md} {selected_voice}.mp3" if selected_md else f"{prefix} default {selected_voice}.mp3"
|
| 230 |
-
audio_file = asyncio.run(generate_audio(
|
| 231 |
st.audio(audio_file)
|
| 232 |
with open(audio_file, "rb") as f:
|
| 233 |
audio_bytes = f.read()
|
| 234 |
-
st.download_button(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
|
| 236 |
with st.spinner("Generating PDF..."):
|
| 237 |
pdf_bytes = create_pdf(st.session_state.markdown_content, base_font_size, render_with_bold, auto_bold_numbers, enlarge_numbered, num_columns)
|
|
@@ -244,10 +267,9 @@ with st.container():
|
|
| 244 |
else:
|
| 245 |
st.info("Download the PDF to view it locally.")
|
| 246 |
|
| 247 |
-
# Download button for PDF with new naming convention
|
| 248 |
with st.sidebar:
|
| 249 |
st.download_button(
|
| 250 |
-
label="
|
| 251 |
data=pdf_bytes,
|
| 252 |
file_name=f"{prefix} {selected_md}.pdf" if selected_md else f"{prefix} output.pdf",
|
| 253 |
mime="application/pdf"
|
|
|
|
| 23 |
def get_timestamp_prefix():
|
| 24 |
central = pytz.timezone("US/Central")
|
| 25 |
now = datetime.now(central)
|
| 26 |
+
# Format: three-letter day, MMDD, HHMM + AM/PM (all uppercase)
|
| 27 |
return now.strftime("%a %m%d %I%M%p").upper()
|
| 28 |
|
| 29 |
+
def clean_for_speech(text):
|
| 30 |
+
# Remove hash marks
|
| 31 |
+
text = text.replace("#", "")
|
| 32 |
+
# Remove emojis using a regex pattern that covers a wide range
|
| 33 |
+
emoji_pattern = re.compile(
|
| 34 |
+
r"[\U0001F300-\U0001F5FF"
|
| 35 |
+
r"\U0001F600-\U0001F64F"
|
| 36 |
+
r"\U0001F680-\U0001F6FF"
|
| 37 |
+
r"\U0001F700-\U0001F77F"
|
| 38 |
+
r"\U0001F780-\U0001F7FF"
|
| 39 |
+
r"\U0001F800-\U0001F8FF"
|
| 40 |
+
r"\U0001F900-\U0001F9FF"
|
| 41 |
+
r"\U0001FA00-\U0001FA6F"
|
| 42 |
+
r"\U0001FA70-\U0001FAFF"
|
| 43 |
+
r"\u2600-\u26FF"
|
| 44 |
+
r"\u2700-\u27BF]+", flags=re.UNICODE)
|
| 45 |
+
text = emoji_pattern.sub('', text)
|
| 46 |
+
return text
|
| 47 |
+
|
| 48 |
async def generate_audio(text, voice, filename):
|
| 49 |
communicate = edge_tts.Communicate(text, voice)
|
| 50 |
await communicate.save(filename)
|
|
|
|
| 59 |
r"\U0001F780-\U0001F7FF"
|
| 60 |
r"\U0001F800-\U0001F8FF"
|
| 61 |
r"\U0001F900-\U0001F9FF"
|
| 62 |
+
r"\U0001FAD0-\U0001FAD9" # additional range if needed
|
| 63 |
r"\U0001FA00-\U0001FA6F"
|
| 64 |
r"\U0001FA70-\U0001FAFF"
|
| 65 |
r"\u2600-\u26FF"
|
|
|
|
| 110 |
'ItemStyle', parent=styles['Normal'], fontName="DejaVuSans",
|
| 111 |
fontSize=base_font_size, leading=base_font_size * 1.15, spaceAfter=1
|
| 112 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
numbered_bold_style = ParagraphStyle(
|
| 114 |
'NumberedBoldStyle', parent=styles['Normal'], fontName="NotoEmoji-Bold",
|
| 115 |
fontSize=base_font_size + 1 if enlarge_numbered else base_font_size,
|
|
|
|
| 224 |
if selected_md:
|
| 225 |
with open(f"{selected_md}.md", "w", encoding="utf-8") as f:
|
| 226 |
f.write(edited_markdown)
|
| 227 |
+
st.rerun()
|
| 228 |
|
| 229 |
# Create a timestamp prefix for file naming
|
| 230 |
prefix = get_timestamp_prefix()
|
| 231 |
|
| 232 |
+
# Download button for Markdown with new naming convention and double emoji label
|
| 233 |
st.download_button(
|
| 234 |
+
label="๐พ๐ Save Markdown",
|
| 235 |
data=st.session_state.markdown_content,
|
| 236 |
file_name=f"{prefix} {selected_md}.md" if selected_md else f"{prefix} default.md",
|
| 237 |
mime="text/markdown"
|
|
|
|
| 241 |
VOICES = ["en-US-AriaNeural", "en-US-JennyNeural", "en-GB-SoniaNeural", "en-US-GuyNeural", "en-US-AnaNeural"]
|
| 242 |
selected_voice = st.selectbox("Select Voice for TTS", options=VOICES, index=0)
|
| 243 |
if st.button("Generate Audio"):
|
| 244 |
+
# Clean markdown input for speech generation
|
| 245 |
+
cleaned_text = clean_for_speech(st.session_state.markdown_content)
|
| 246 |
# Create a filename for the audio file using the timestamp, markdown name, and selected voice
|
| 247 |
audio_filename = f"{prefix} {selected_md} {selected_voice}.mp3" if selected_md else f"{prefix} default {selected_voice}.mp3"
|
| 248 |
+
audio_file = asyncio.run(generate_audio(cleaned_text, selected_voice, audio_filename))
|
| 249 |
st.audio(audio_file)
|
| 250 |
with open(audio_file, "rb") as f:
|
| 251 |
audio_bytes = f.read()
|
| 252 |
+
st.download_button(
|
| 253 |
+
label="๐พ๐ Save Audio",
|
| 254 |
+
data=audio_bytes,
|
| 255 |
+
file_name=audio_filename,
|
| 256 |
+
mime="audio/mpeg"
|
| 257 |
+
)
|
| 258 |
|
| 259 |
with st.spinner("Generating PDF..."):
|
| 260 |
pdf_bytes = create_pdf(st.session_state.markdown_content, base_font_size, render_with_bold, auto_bold_numbers, enlarge_numbered, num_columns)
|
|
|
|
| 267 |
else:
|
| 268 |
st.info("Download the PDF to view it locally.")
|
| 269 |
|
|
|
|
| 270 |
with st.sidebar:
|
| 271 |
st.download_button(
|
| 272 |
+
label="๐พ๐ Save PDF",
|
| 273 |
data=pdf_bytes,
|
| 274 |
file_name=f"{prefix} {selected_md}.pdf" if selected_md else f"{prefix} output.pdf",
|
| 275 |
mime="application/pdf"
|