Solshine commited on
Commit
ef156fb
Β·
verified Β·
1 Parent(s): 9153151

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -1,8 +1,10 @@
1
  import streamlit as st
2
  from gtts import gTTS
3
  from io import BytesIO
4
- import pdfminer
5
- from pdfminer.high_level import extract_pages
 
 
6
 
7
  x = st.slider('Select a value')
8
  slider_reply = x, 'squared is', x * x
@@ -10,9 +12,16 @@ st.write(slider_reply)
10
 
11
  uploaded_file = st.file_uploader("Choose a file", "pdf")
12
  if uploaded_file is not None:
13
- for page_layout in extract_pages(uploaded_file):
14
- for element in page_layout:
15
- st.write(element)
 
 
 
 
 
 
 
16
  with st.popover("Open popover"):
17
  sound_file = BytesIO()
18
  tts = gTTS(element, lang='en')
 
1
  import streamlit as st
2
  from gtts import gTTS
3
  from io import BytesIO
4
+ from cStringIO import StringIO
5
+ from pdfminer.pdfinterp import PDFResourceManager, process_pdf
6
+ from pdfminer.converter import TextConverter
7
+ from pdfminer.layout import LAParams
8
 
9
  x = st.slider('Select a value')
10
  slider_reply = x, 'squared is', x * x
 
12
 
13
  uploaded_file = st.file_uploader("Choose a file", "pdf")
14
  if uploaded_file is not None:
15
+ def to_txt(uploaded_file):
16
+ input_ = file(uploaded_file, 'rb')
17
+ output = StringIO()
18
+
19
+ manager = PDFResourceManager()
20
+ converter = TextConverter(manager, output, laparams=LAParams())
21
+ process_pdf(manager, converter, input_)
22
+
23
+ element = output.getvalue()
24
+ st.write(element)
25
  with st.popover("Open popover"):
26
  sound_file = BytesIO()
27
  tts = gTTS(element, lang='en')