Spaces:
Runtime error
Runtime error
File size: 2,444 Bytes
474f4cc fbb5261 cc84c76 9f8e59c 474f4cc fbb5261 9e1c381 fbb5261 4b5b0e4 fbb5261 c626652 fbb5261 9f8e59c 29a0691 fbb5261 ad135b5 29a0691 de0a7fd 29a0691 fbb5261 44e6c56 9f8e59c 44e6c56 fbb5261 0b298e3 cc84c76 fbb5261 e2bb816 b56acb6 fbb5261 |
1 2 3 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 |
import streamlit as st
from gtts import gTTS
from io import BytesIO
from PyPDF2 import PdfReader
st.set_page_config(page_title="π PDF to Audio π§", page_icon="π")
st.markdown("""
<style>
body {
background-color: #F0F8FF;
font-family: 'Arial', sans-serif;
}
h1 {
color: #1E90FF;
font-size: 36px;
text-align: center;
margin-bottom: 30px;
}
h2 {
color: #00BFFF;
font-size: 24px;
margin-bottom: 10px;
}
p {
color: #333;
font-size: 18px;
}
.stAudio {
margin-bottom: 20px;
}
.stTextArea {
font-size: 18px;
padding: 10px;
}
.stButton {
background-color: #1E90FF;
color: #FFF;
font-size: 18px;
padding: 10px 20px;
border-radius: 5px;
margin-top: 20px;
}
</style>
""", unsafe_allow_html=True)
st.markdown("<h1>π PDF to Audio Converter π§</h1>", unsafe_allow_html=True)
col1, col2 = st.columns(2)
with col1:
st.markdown("<h2>π PDF File</h2>", unsafe_allow_html=True)
uploaded_file = st.file_uploader("Choose a file", "pdf")
with col2:
st.markdown("<h2>π’ Pages</h2>", unsafe_allow_html=True)
x = st.slider('Select the number of pages you wish to transcribe', min_value=1, max_value=100, value=10)
if uploaded_file is not None:
reader = PdfReader(uploaded_file)
X = len(reader.pages)
st.markdown(f"<p>Total pages in the PDF: {X}</p>", unsafe_allow_html=True)
i = 0
while i <= X and i <= x:
page = reader.pages[i]
text = page.extract_text()
sound_file = BytesIO()
tts = gTTS(text, lang='en')
tts.write_to_fp(sound_file)
st.audio(sound_file, format='audio/mp3')
st.markdown(f"<p>Read aloud page {i+1} of {X} total pages.</p>", unsafe_allow_html=True)
i = i + 1
st.balloons()
st.markdown("<h2>π That's the whole PDF! Have an awesome day! π</h2>", unsafe_allow_html=True)
st.markdown("<h2>βοΈ Text to Audio</h2>", unsafe_allow_html=True)
prompt = st.text_area("Copy/Paste or type in text to have read aloud", height=200)
if prompt:
st.write(prompt)
sound_file = BytesIO()
tts = gTTS(prompt, lang='en')
tts.write_to_fp(sound_file)
st.audio(sound_file, format='audio/mp3')
st.markdown("<button class='stButton'>Convert to Audio</button>", unsafe_allow_html=True)
|