Spaces:
Sleeping
Sleeping
File size: 6,318 Bytes
a235177 1748047 a235177 75642d2 c2542f3 419f14a b1081f1 10ac278 341551d 10ac278 341551d 10ac278 ff0a552 10ac278 1ab460b 777324c 1ab460b b46d61b 7b00e7b 777324c 7b00e7b 310b87d b862fa4 310b87d a5e39a0 a4d4c8f a5e39a0 10ac278 b089d6a 6bf8b90 b089d6a c2da80d 5c46438 c786d64 055e117 2b2d395 e01ef92 2b2d395 bbe1467 4598a69 001f294 bbe1467 777324c 2e65244 777324c e624d12 777324c 4da7dd9 2b2d395 8e92529 2b2d395 bd42d08 8e92529 a33e7cb 4598a69 001f294 a33e7cb 4598a69 001f294 a33e7cb 8e92529 2b2d395 a3c2554 bda4d01 9ca0fe5 c881a86 2b2d395 8461fa2 93b762a a33e7cb 001f294 a33e7cb 98209df c881a86 98209df a3c2554 98209df b089d6a 09cf596 c2542f3 867cecb a3c2554 7997510 a3c2554 dfb4288 a3c2554 2fbd6b6 a235177 c2da80d 3c03888 8e92529 3c03888 8e92529 9c0b4b8 be9b837 777324c 8ecffb4 867cecb 688fae6 867cecb 688fae6 867cecb 688fae6 b3b21d5 688fae6 b3b21d5 b1081f1 867cecb b089d6a 6212d30 b0ce3c4 c54e11c 09f8707 c54e11c a5e39a0 a4d4c8f c1bf04e a4d4c8f c1bf04e a4d4c8f 9a9808f a4d4c8f c2542f3 8ecffb4 867cecb 8ecffb4 867cecb 8ecffb4 a5e39a0 |
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
import gradio as gr
import xmltodict
import requests
import json
import uuid
from pypipertts import PyPiper
pp=PyPiper()
style="""
.title_div{
font-size: x-large;
font-weight: 700;
margin-bottom: 10px;
color: white;
}
.card_div{
background: #050523;
color: white;
margin: 10px;
padding: 15px;
border-radius: 5px;
cursor: pointer;
}
.x_btn{
font-size: xx-large;
font-weight: 900;
background: chocolate;
width: fit-content;
padding: 0 10px;
border-radius: 10px 10px 0 0;
float: right;
cursor: pointer;
}
.read_btn{
font-size: xx-large;
font-weight: 900;
background: chocolate;
width: fit-content;
padding: 0 10px;
border-radius: 10px 10px 0 0;
float: left;
cursor: pointer;
}
.frame_class{
display:none;
}
#big_btn {
height:5em;
border-radius:15px;
}
"""
head = """
<script>
function run(inn, url_in) {
let url = String(url_in)
console.log(inn);
console.log(url);
var frame_on = document.getElementById('frame' + String(inn));
frame_on.style.display = 'block';
var framediv = document.getElementById('framediv' + String(inn));
let child0 = framediv.lastElementChild;
while (child0) {
framediv.removeChild(child0);
child0=framediv.lastElementChild;
}
const iframediv = document.createElement('iframe');
iframediv.src = 'https://docs.google.com/viewer?url=' + url +'&embedded=true';
iframediv.width = '100%';
iframediv.height = '1000px';
iframediv.frameborder="0";
framediv.appendChild(iframediv);
}
</script>
<script>
function closefn(inn) {
console.log(inn);
var frame_off = document.getElementById('frame' + String(inn));
var aud = document.getElementById('aud' + String(inn));
var framediv = document.getElementById('framediv' + String(inn));
frame_off.style.display = 'none';
let child1 = aud.lastElementChild;
while (child1) {
aud.removeChild(child1);
child1=aud.lastElementChild;
}
let child2 = framediv.lastElementChild;
while (child2) {
framediv.removeChild(child2);
child2 = framediv.lastElementChild;
}
}
</script>
<script>
function readfn(inn, url_in, payload) {
let url = String(url_in);
console.log(inn);
console.log(url);
var readit = document.getElementById('aud' + String(inn));
let api = 'https://broadfield-fast-voice.hf.space/?pdfurl=' + url + '&mod=' + payload['model'] + '&len=' + payload['length']+ '&nos=' + payload['noise']+ '&wid=' + payload['width'] + '&pau=' + payload['pause'];
console.log(api);
let child = readit.lastElementChild;
while (child) {
readit.removeChild(child);
child=readit.lastElementChild;
}
const iframe = document.createElement('iframe');
iframe.src = api;
iframe.width = '100%';
iframe.height = '220px';
readit.appendChild(iframe);
}
</script>
"""
def search(q,rn,st):
payload={
"model": "en_US-lessac-high",
"length": 1,
"noise": 0.5,
"width": 0.5,
"pause": 1
}
api=f"http://export.arxiv.org/api/query?search_query={str(q)}&start={str(st)}&max_results={str(rn)}"
r=requests.get(api)
cont=xmltodict.parse(r.content)['feed']['entry']
html=""
for i,c in enumerate(cont):
pdflink=c['id'].replace('/abs/','/pdf/').replace('http:','https:')
print(pdflink)
html+=f"""<div class='card_div' id='id{i}' onclick="run('{i}','{pdflink}')">
<div class='title_div'>{c['title']}</div>
<div style='color:white;'>{c['summary']}</div>
<div><a href='{pdflink}' target='_blank'>{pdflink}</a></div>
</div>
<div id=frame{i} class='frame_class'>
<div id=read{i} class='read_btn' onclick="readfn('{i}','{pdflink}',{payload})">Read</div>
<div id=close{i} class='x_btn' onclick='closefn({i})'>X</div>
<div id=aud{i}></div>
<div id=framediv{i}></div>
</div>"""
return html
def next_show(cur):
new=int(cur)+10
return gr.update(interactive=True),new
def prev_show(cur):
if int(cur)-10 <=0:
new=0
out_gr=gr.update(interactive=False)
else:
new=int(cur)-10
out_gr=gr.update(interactive=True)
return out_gr,new
def show_num(cur):
new=int(cur)+10
html_out=f"<div><center>Showing {cur} through {new}</center></div>"
return html_out
def stream_aud(inp):
txt=inp[0]['text']
pp=PyPiper()
pp.load_mod()
yield(pp.stream_tts(in_text=txt,model="en_US-joe-medium"))
with gr.Blocks(css=style,head=head) as b:
gr.HTML("""<center><div><h1 style='font-size:xxx-large;font-weight:900;'>arXiv Reader with Voice</h1>
<h2>Read arXiv papers using Piper Text-to-Voice</h2>
<div style="position:relative;">
<h7 style="float:left;">Piper: <a href='https://github.com/rhasspy/piper' target='_blank'>https://github.com/rhasspy/piper</a></h7><br>
<h7 style="float:left;">PyPiperTTS: <a href='https://github.com/broadfield-dev/PyPiperTTS' target='_blank'>https://github.com/broadfield-dev/PyPiperTTS</a></h7>
</div></div></center>""")
with gr.Row():
gr.Column(scale=1)
with gr.Column(scale=3):
query=gr.Textbox(label="Query")
sub=gr.Button(elem_id='big_btn')
with gr.Group():
with gr.Row():
prev_btn=gr.Button("Previous",interactive=False)
next_btn=gr.Button("Next")
show_html=gr.HTML()
gr.Column(scale=1)
html_out=gr.HTML()
with gr.Column(visible=False):
num=gr.Number(label="Count",step=1,value=10,interactive=False)
json_out=gr.JSON()
hid_start=gr.Number(step=1,value=0,visible=False, interactive=False)
next_btn.click(next_show,[hid_start],[prev_btn,hid_start]).then(show_num,hid_start,show_html).then(search,[query,num,hid_start],[html_out])
prev_btn.click(prev_show,[hid_start],[prev_btn,hid_start]).then(show_num,hid_start,show_html).then(search,[query,num,hid_start],[html_out])
sub.click(search,[query,num,hid_start],[html_out]).then(show_num,hid_start,show_html)
b.queue(default_concurrency_limit=20).launch(max_threads=40) |