import gradio as gr import io import os import uuid import requests import gradio as gr from pypdf import PdfReader from pypipertts import PyPiper import subprocess pp=PyPiper() pp.load_mod() def read_pdf(pdf_url): print(pdf_url) file_name=f"{uuid.uuid4()}.pdf" response = requests.get(pdf_url.replace('http:','https:'), stream=True) if response.status_code == 200: with open(file_name, "wb") as f: f.write(response.content) else: print(response.status_code) txt_out="" reader = PdfReader(file_name) number_of_pages = len(reader.pages) #file_name=str(pdf_path).split("\\")[-1] for i in range(number_of_pages): page = reader.pages[i] txt_out+=page.extract_text() #return txt_out return txt_out.replace("\n","") def load_html(url): html=f"""""" return html js=""" function () { const urlParams = new URLSearchParams(window.location.search); var p_pdf = urlParams.get('pdfurl') var p_mod = urlParams.get('mod') var p_len = urlParams.get('len') var p_nos = urlParams.get('nos') var p_wid = urlParams.get('wid') var p_pau = urlParams.get('pau') if (p_mod) { console.log(p_mod) } else { p_mod = "en_US-joe-medium"; }; if (p_len) { console.log(p_len) } else { p_len = "1"; }; if (p_nos) { console.log(p_nos) } else { p_nos = "0.5"; }; if (p_wid) { console.log(p_wid) } else { p_wid = "0.5"; }; if (p_pau) { console.log(p_pau) } else { p_pau = "1"; }; return [p_pdf, p_mod, p_len, p_nos, p_wid, p_pau]; } """ with gr.Blocks() as app: a=gr.Audio(streaming=True,autoplay=True) h=gr.HTML() with gr.Column(visible=False): t=gr.Textbox(label="url",interactive=False,visible=True) m=gr.Textbox(label="mod",value="en_US-joe-medium",interactive=False,visible=True) l=gr.Textbox(label="len",value="1",interactive=False,visible=True) n=gr.Textbox(label="nos",value="0.5",interactive=False,visible=True) w=gr.Textbox(label="wid",value="0.5",interactive=False,visible=True) p=gr.Textbox(label="pau",value="1",interactive=False,visible=True) bulk=gr.Textbox(label="bulk",interactive=False,visible=True) app.load(None,None,[t,m,l,n,w,p],js=js) t.change(read_pdf,t,bulk) m.change(pp.load_mod,m,None) bulk.change(pp.stream_tts,[bulk,m,l,n,w,p],a) app.queue(default_concurrency_limit=20).launch(max_threads=40)