Skip to content

Commit

Permalink
Made some changes
Browse files Browse the repository at this point in the history
Added Validations
  • Loading branch information
deadmantfa committed Feb 22, 2021
1 parent 45b7636 commit f346075
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
from gtts import gTTS
from poppler import load_from_data, PageRenderer

st.set_page_config(page_title='AudioBook Maker', page_icon='https://i.postimg.cc/mk0CgTnh/logo-transparent-200.png',
layout='wide', initial_sidebar_state='expanded')
st.header(
"[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/E1E226KBO) [![GitHub release ("
"latest by date)](https://img.shields.io/github/v/release/deadmantfa/audiobookmaker?style=for-the-badge)]("
"https://github.com/deadmantfa/audiobookmaker)")


def convert(pdf_reader, start, end):
try:
Expand Down Expand Up @@ -37,26 +44,10 @@ def render_page(file, page):
return pil_image


def main():
with st.sidebar:
st.title('Audio Book Maker')
uploaded_file = st.file_uploader("Upload a PDF", type=['pdf'])
start_page = st.number_input("Start Page", 1)
end_page = st.number_input("End Page", 1)
st.info('Conversion takes time, so please be patient')
convert_to_audio = st.button('Convert')
pdf_document = None
if uploaded_file is not None:
read_file = uploaded_file.read()
pdf_document = load_from_data(read_file)
if convert_to_audio and uploaded_file is not None:
audio_file = convert(pdf_document, start_page, end_page)
if audio_file is not None:
st.audio(audio_file, format='audio/mp3')

'''
def preview(pdf_document, read_file):
"""
# Preview PDF
'''
"""
st.warning('Before switching pages be sure to download any converted pages or you will need to reconvert')
if pdf_document is not None:
input_page = st.number_input('Page number', 1, step=2)
Expand All @@ -72,5 +63,26 @@ def main():
st.info('Upload a PDF to preview')


def main():
with st.sidebar:
st.title('Audio Book Maker')
uploaded_file = st.file_uploader("Upload a PDF", type=['pdf'])
start_page = st.number_input("Start Page", 1)
end_page = st.number_input("End Page", 1)
st.info('Conversion takes time, so please be patient')
convert_to_audio = st.button('Convert')
pdf_document = None
if uploaded_file is not None:
read_file = uploaded_file.read()
pdf_document = load_from_data(read_file)
if start_page > end_page:
st.error('Start Page cannot be greater than end page')
elif start_page <= end_page:
if convert_to_audio and uploaded_file is not None:
audio_file = convert(pdf_document, start_page, end_page)
st.audio(audio_file, format='audio/mp3')
preview(pdf_document, read_file)


if __name__ == "__main__":
main()

0 comments on commit f346075

Please sign in to comment.