text2speech / app.py
aritheanalyst's picture
Create app.py
5cddb5b
raw
history blame
No virus
1.46 kB
#**************** IMPORT PACKAGES ********************
import gradio as gr
import numpy as np
import pytesseract as pt
import pdf2image
import os
import tempfile
from fpdf import FPDF
import re
import pdfkit
import yake
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
summary_ids = model.generate(inputs["input_ids"], num_beams=2,min_length=Min, max_length=Min+1000)
output_text = tokenizer.batch_decode(summary_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
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)