Spaces:
Runtime error
Runtime error
File size: 2,233 Bytes
511891d 6f2a024 0b73570 6f2a024 288aecc 5b2b36d a716d77 c721296 7839cc0 288aecc c721296 67949b6 25ec869 6f2a024 0d0db28 5b2b36d c721296 7839cc0 c721296 01f064c eea38a1 01f064c 0b73570 cb3b6d4 01f064c 6f2a024 e8ad872 01f064c 288aecc 01f064c e8ad872 |
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 |
import gradio as gr
import requests
import json
main_directory = "https://services.swpc.noaa.gov/"
html = """
<div>
PAGE_LINK
</div>
"""
def load_json(url1="",url2="",url3="",url4=""):
get_url=f'{main_directory}{url1}{url2}{url3}{url4}'
print(f'{get_url}')
get_url=get_url.split(".json")[0]+".json"
if get_url.endswith('.json'):
feed1 = requests.get(get_url)
return feed1.text
return None
def make_tree(url1="",url2="",url3="",url4=""):
link_box=[]
html_out=""
get_url=f'{main_directory}{url1}{url2}{url3}{url4}'
print(f'######### :: {get_url}')
if not get_url.endswith('.json'):
feed1 = requests.get(get_url)
spl = feed1.text.split("href=")
for line in spl:
spl2 = line.split(">")[0]
print(spl2)
if spl2.endswith('/"') or spl2.endswith('.json"'):
fin=line.split(">")[0].strip('""')
link_box.append(fin)
#html_out=html_out+html.replace("PAGE_LINK",fin)
return gr.update(choices=[l for l in link_box],interactive=True)
else:
return None
def get_images():
html_out="<div>"
get_url=f'{main_directory}images/'
feed1 = requests.get(get_url)
spl = feed1.text.split("href=")
for line in spl:
spl2 = line.split(">")[0].strip('""')
print(spl2)
html_out+=f'<div><img src={get_url}{spl2}></div>'
html_out+="</div>"
return html_out
def run():
out=make_tree()
im_html=get_images()
return out, im_html
with gr.Blocks() as app:
with gr.Tab("Images"):
html_im=gr.HTML()
with gr.Tab("Raw"):
with gr.Row():
drop1=gr.Dropdown()
drop2=gr.Dropdown()
drop3=gr.Dropdown()
drop4=gr.Dropdown()
load_btn=gr.Button("Load JSON")
links=gr.JSON()
###### Images ##########
####### Raw ############
load_btn.click(load_json,[drop1,drop2,drop3,drop4],links)
drop1.change(make_tree,drop1,[drop2])
drop2.change(make_tree,[drop1,drop2],[drop3])
drop3.change(make_tree,[drop1,drop2,drop3],[drop4])
######################
app.load(run,None,[drop1,html_im])
app.launch() |