Spaces:
Running
Running
File size: 2,360 Bytes
47a983d 67df1ec 297872e 67df1ec 223aa24 67df1ec 9213359 67df1ec 6d5b659 67df1ec 6d5b659 08c3cd4 25da55d 67df1ec c0f4dec 67df1ec 47a983d 7362783 09e540a 162a4cb 0a1ff49 affba00 0a1ff49 affba00 162a4cb 8083ec5 47a983d 67df1ec 297872e 297adbb a50eb64 ca06bc0 a50eb64 6d5b659 162a4cb 6d5b659 72e3223 19e5205 162a4cb a50eb64 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
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"""<iframe src="https://docs.google.com/viewer?url={url})&embedded=true" frameborder="0" height="1200px" width="100%"></iframe></div>"""
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";
};
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) |