Spaces:
Sleeping
Sleeping
yunuseduran
commited on
Commit
•
f5e0882
1
Parent(s):
5717ba8
Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,32 @@
|
|
1 |
-
import os
|
2 |
-
from PyPDF2 import PdfReader
|
3 |
-
from gtts import gTTS
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
tts
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
return "Seslendirme tamamlandı."
|
34 |
-
|
35 |
-
iface = gr.Interface(fn=interface, inputs="file", outputs="text")
|
36 |
-
iface.launch()
|
|
|
1 |
+
import os
|
2 |
+
from PyPDF2 import PdfReader
|
3 |
+
from gtts import gTTS
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
def pdf_to_text(pdf_file):
|
7 |
+
reader = PdfReader(pdf_file)
|
8 |
+
text = ""
|
9 |
+
for page in reader.pages:
|
10 |
+
text += page.extract_text()
|
11 |
+
return text
|
12 |
+
|
13 |
+
def text_to_speech(text, lang='en'):
|
14 |
+
tts = gTTS(text=text, lang=lang)
|
15 |
+
output_path = "output.mp3"
|
16 |
+
tts.save(output_path)
|
17 |
+
return output_path
|
18 |
+
|
19 |
+
def convert_pdf_to_speech(pdf_file):
|
20 |
+
text = pdf_to_text(pdf_file)
|
21 |
+
audio_file = text_to_speech(text)
|
22 |
+
return audio_file
|
23 |
+
|
24 |
+
# Gradio arayüzü
|
25 |
+
def interface(pdf_file):
|
26 |
+
audio_file = convert_pdf_to_speech(pdf_file.name)
|
27 |
+
return audio_file
|
28 |
+
|
29 |
+
iface = gr.Interface(fn=interface, inputs="file", outputs="file",
|
30 |
+
title="PDF to Speech Converter",
|
31 |
+
description="Upload a PDF file and convert it to MP3 format audio.")
|
32 |
+
iface.launch()
|
|
|
|
|
|
|
|