import streamlit as st import arxiv import os import pdfminer from pdfminer.high_level import extract_text, extract_pages from pdfminer.layout import LTTextContainer from search import search from get_paper import get_paper from get_pages import get_pages from tts import tts import IPython.display as ipd st.title("ArXiV Audio") with st.form(key = "search_form"): col1, col2, col3 = st.columns(3) with col1: query = st.text_input("Search Paper") with col2: sort_by = st.selectbox(label = "Sort By", options=('Relevance', 'Last Updated Date','Submitted Date')) with col3: order_by = st.selectbox(label = "Order By", options=('Ascending', 'Descending')) submit = st.form_submit_button(label = "Search") lst = search(query=query, sort_by=sort_by, sort_order=order_by) if len(lst) != 0: label = "Papers for " + query with st.form(key = "paper_form"): pname = st.selectbox(label = label, options=lst) submit_paper = st.form_submit_button(label = "Fetch Paper") else: with st.form(key = "paper_form"): pname = st.selectbox(label = "NO PAPERS", options=lst) submit_paper = st.form_submit_button(label = "Fetch Paper") paper="" if submit_paper: paper = get_paper(pname) name="" if paper: name = paper.title+'.pdf' name = name.replace('?', '') name = "downloads/" + name tpages = len(list(extract_pages(name))) print("total pages=", tpages) pgs = [i+1 for i in range(tpages)] start_page = 1 end_page = 1 with st.form(key = "page_form"): col1, col2 = st.columns(2) with col1: s_page = st.selectbox(label = "Start Page", options = pgs) with col2: e_page = st.selectbox(label = "End Page", options = pgs, index = pgs[-1]-1) submit_pages = st.form_submit_button(label = "Convert To Audio") if submit_pages: if start_page > end_page: st.write("Wrong Sequence, cannot process") else: content = get_pages(name, start_page, end_page) wav, rate = tts(content) ipd.Audio(wav, rate=rate) else: st.write("No Paper Selected")