text2speech / app.py
aritheanalyst's picture
Update app.py
a6b5bfa
raw
history blame
1.17 kB
#**************** IMPORT PACKAGES ********************
import gradio as gr
import numpy as np
import os
import tempfile
from fpdf import FPDF
import re
import pdfkit
from zipfile import ZipFile
from gtts import gTTS
from pdfminer.high_level import extract_text
def pdf_to_text(text, PDF):
if text == "":
# The setup of huggingface.co
file_obj = PDF
#n = int(Percent.replace('%', ''))
text = extract_text(file_obj.name)
outpit_text = text
else:
output_text = text
# Generate Summary
pdf = FPDF()
pdf.add_page()
pdf.set_font("Times", size = 12)
# open the text file in read mode
f = output_text
# insert the texts in pdf
pdf.multi_cell(190, 10, txt = f, align = 'C')
# save the pdf with name .pdf
pdf.output("text.pdf")
myobj = gTTS(text=output_text, lang='en', slow=False)
myobj.save("audio.wav")
return "audio.wav", output_text, "text.pdf"
# return path
#pageObject.extractText()
iface = gr.Interface(fn = pdf_to_text,
inputs =["text", "file"], outputs=["audio","text", "file"] )
if __name__ == "__main__":
iface.launch(share=True)