Spaces:
Sleeping
Sleeping
yunuseduran
commited on
Commit
•
b09bae2
1
Parent(s):
4c6fdbe
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import os
|
2 |
-
from PyPDF2 import PdfReader
|
3 |
from gtts import gTTS
|
4 |
from pydub import AudioSegment
|
5 |
import gradio as gr
|
@@ -11,8 +11,8 @@ def pdf_to_text(pdf_file):
|
|
11 |
for page in reader.pages:
|
12 |
text += page.extract_text()
|
13 |
return text
|
14 |
-
except
|
15 |
-
return
|
16 |
|
17 |
def text_to_speech(text, lang='en', file_format='mp3'):
|
18 |
tts = gTTS(text=text, lang=lang)
|
@@ -30,11 +30,11 @@ def text_to_speech(text, lang='en', file_format='mp3'):
|
|
30 |
|
31 |
def convert_pdf_to_speech(pdf_file, lang='en', file_format='mp3'):
|
32 |
text = pdf_to_text(pdf_file)
|
33 |
-
if text:
|
34 |
audio_file = text_to_speech(text, lang=lang, file_format=file_format)
|
35 |
return audio_file
|
36 |
else:
|
37 |
-
return
|
38 |
|
39 |
# Gradio arayüzü
|
40 |
def interface(pdf_file, lang, file_format):
|
|
|
1 |
import os
|
2 |
+
from PyPDF2 import PdfReader
|
3 |
from gtts import gTTS
|
4 |
from pydub import AudioSegment
|
5 |
import gradio as gr
|
|
|
11 |
for page in reader.pages:
|
12 |
text += page.extract_text()
|
13 |
return text
|
14 |
+
except Exception as e:
|
15 |
+
return f"Error: {str(e)}"
|
16 |
|
17 |
def text_to_speech(text, lang='en', file_format='mp3'):
|
18 |
tts = gTTS(text=text, lang=lang)
|
|
|
30 |
|
31 |
def convert_pdf_to_speech(pdf_file, lang='en', file_format='mp3'):
|
32 |
text = pdf_to_text(pdf_file)
|
33 |
+
if text and not text.startswith("Error:"):
|
34 |
audio_file = text_to_speech(text, lang=lang, file_format=file_format)
|
35 |
return audio_file
|
36 |
else:
|
37 |
+
return text
|
38 |
|
39 |
# Gradio arayüzü
|
40 |
def interface(pdf_file, lang, file_format):
|