File size: 1,733 Bytes
47a983d
67df1ec
 
 
 
 
 
 
 
 
 
 
 
297872e
 
67df1ec
223aa24
67df1ec
9213359
67df1ec
 
 
 
 
6d5b659
67df1ec
 
 
 
 
6d5b659
08c3cd4
72e3223
67df1ec
c0f4dec
67df1ec
 
47a983d
 
09e540a
19e5205
 
b8a0b1e
47a983d
 
 
67df1ec
297872e
80fda39
a50eb64
19e5205
a50eb64
6d5b659
19e5205
6d5b659
72e3223
19e5205
 
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
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
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 start() {
    const urlParams = new URLSearchParams(window.location.search);
    var parampdf = urlParams.get('pdfurl')
    var parammod = urlParams.get('mod')
    return parampdf,parammod
}"""

with gr.Blocks() as app:
    a=gr.Audio(streaming=True,autoplay=True)
    h=gr.HTML()
    with gr.Column(visible=True):    
        t=gr.Textbox(label="url",interactive=False,visible=True)
        m=gr.Textbox(label="mod",interactive=False,visible=True)
        bulk=gr.Textbox(label="bulk",interactive=False,visible=True)
    
    app.load(None,None,[t,m],js=js)
    
    t.change(read_pdf,t,bulk)
    m.change(pp.load_mod,m,None)
    bulk.change(pp.stream_tts,[bulk,m],a)
app.queue(default_concurrency_limit=20).launch(max_threads=40)