awacke1 commited on
Commit
fbb5261
β€’
1 Parent(s): 2af7e21

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -23
app.py CHANGED
@@ -1,42 +1,91 @@
1
  import streamlit as st
2
- from gtts import gTTS
3
  from io import BytesIO
4
  from PyPDF2 import PdfReader
5
 
6
- st.image('OIG3 (4).jpeg', caption='Your host on this PDF-to-Speech adventure!')
7
 
8
- x = st.slider('Select the number of pages you wish to transcribe')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
- uploaded_file = st.file_uploader("Choose a file", "pdf")
11
- if uploaded_file is not None:
12
- # creating a pdf reader object
 
 
 
 
 
 
 
 
 
 
13
  reader = PdfReader(uploaded_file)
14
- # printing number of pages in pdf file
15
  X = len(reader.pages)
16
- print(X)
17
 
18
  i = 0
19
  while i <= X and i <= x:
20
- # getting a specific page from the pdf file
21
  page = reader.pages[i]
22
- # extracting text from page
23
- text = page.extract_text()
24
- print("Created text of page", i )
25
  sound_file = BytesIO()
26
  tts = gTTS(text, lang='en')
27
  tts.write_to_fp(sound_file)
28
- st.audio(sound_file)
29
- print("Read aloud", i, "pages of", X, "total pages.")
30
  i = i + 1
31
- st.write("πŸŽ‰ That's the whole PDF! Have an awesome day! πŸŽ‰")
32
-
33
 
34
- prompt = st.chat_input("Copy/Paste or type in text to have read aloud")
 
 
 
 
 
35
  if prompt:
36
  st.write(prompt)
37
- with st.popover("✨ Open your text-to-speech from text input ✨"):
38
- sound_file = BytesIO()
39
- tts = gTTS(prompt, lang='en')
40
- tts.write_to_fp(sound_file)
41
-
42
- st.audio(sound_file)
 
 
 
 
1
  import streamlit as st
2
+ from gtts import gTTS
3
  from io import BytesIO
4
  from PyPDF2 import PdfReader
5
 
6
+ st.set_page_config(page_title="πŸ“š PDF to Audio 🎧", page_icon="πŸŽ‰")
7
 
8
+ st.markdown("""
9
+ <style>
10
+ body {
11
+ background-color: #F0F8FF;
12
+ font-family: 'Arial', sans-serif;
13
+ }
14
+ h1 {
15
+ color: #1E90FF;
16
+ font-size: 36px;
17
+ text-align: center;
18
+ margin-bottom: 30px;
19
+ }
20
+ h2 {
21
+ color: #00BFFF;
22
+ font-size: 24px;
23
+ margin-bottom: 10px;
24
+ }
25
+ p {
26
+ color: #333;
27
+ font-size: 18px;
28
+ }
29
+ .stAudio {
30
+ margin-bottom: 20px;
31
+ }
32
+ .stTextArea {
33
+ font-size: 18px;
34
+ padding: 10px;
35
+ }
36
+ .stButton {
37
+ background-color: #1E90FF;
38
+ color: #FFF;
39
+ font-size: 18px;
40
+ padding: 10px 20px;
41
+ border-radius: 5px;
42
+ margin-top: 20px;
43
+ }
44
+ </style>
45
+ """, unsafe_allow_html=True)
46
 
47
+ st.markdown("<h1>πŸ“š PDF to Audio Converter 🎧</h1>", unsafe_allow_html=True)
48
+
49
+ col1, col2 = st.columns(2)
50
+
51
+ with col1:
52
+ st.markdown("<h2>πŸ“œ PDF File</h2>", unsafe_allow_html=True)
53
+ uploaded_file = st.file_uploader("Choose a file", "pdf")
54
+
55
+ with col2:
56
+ st.markdown("<h2>πŸ”’ Pages</h2>", unsafe_allow_html=True)
57
+ x = st.slider('Select the number of pages you wish to transcribe', min_value=1, max_value=100, value=1)
58
+
59
+ if uploaded_file is not None:
60
  reader = PdfReader(uploaded_file)
 
61
  X = len(reader.pages)
62
+ st.markdown(f"<p>Total pages in the PDF: {X}</p>", unsafe_allow_html=True)
63
 
64
  i = 0
65
  while i <= X and i <= x:
 
66
  page = reader.pages[i]
67
+ text = page.extract_text()
 
 
68
  sound_file = BytesIO()
69
  tts = gTTS(text, lang='en')
70
  tts.write_to_fp(sound_file)
71
+ st.audio(sound_file, format='audio/mp3')
72
+ st.markdown(f"<p>Read aloud page {i+1} of {X} total pages.</p>", unsafe_allow_html=True)
73
  i = i + 1
 
 
74
 
75
+ st.balloons()
76
+ st.markdown("<h2>πŸŽ‰ That's the whole PDF! Have an awesome day! πŸŽ‰</h2>", unsafe_allow_html=True)
77
+
78
+ st.markdown("<h2>✍️ Text to Audio</h2>", unsafe_allow_html=True)
79
+ prompt = st.text_area("Copy/Paste or type in text to have read aloud", height=200)
80
+
81
  if prompt:
82
  st.write(prompt)
83
+ sound_file = BytesIO()
84
+ tts = gTTS(prompt, lang='en')
85
+ tts.write_to_fp(sound_file)
86
+ st.audio(sound_file, format='audio/mp3')
87
+
88
+ st.markdown("<button class='stButton'>Convert to Audio</button>", unsafe_allow_html=True)
89
+
90
+
91
+