Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import requests
|
| 4 |
+
import json
|
| 5 |
+
import os
|
| 6 |
+
from PIL import Image
|
| 7 |
+
import moviepy.video.io.ImageSequenceClip as ic
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
import bs4
|
| 10 |
+
import datetime
|
| 11 |
+
import urllib.request
|
| 12 |
+
import uuid
|
| 13 |
+
main_directory = "https://services.swpc.noaa.gov/"
|
| 14 |
+
sdo_source = "https://sdo.gsfc.nasa.gov/assets/img/browse/"
|
| 15 |
+
sdo_source_format = "https://sdo.gsfc.nasa.gov/assets/img/browse/YEAR/MONTH/DAY/DATE_IDENT_SIZE_TOOL.jpg"
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def make_tree(url1="",url2="",url3="",url4="",url5="",url6="",url7="",url8=""):
|
| 21 |
+
link_box=[]
|
| 22 |
+
html_out=""
|
| 23 |
+
get_url=f'{main_directory}{url1}{url2}{url3}{url4}{url5}{url6}{url7}{url8}'
|
| 24 |
+
print(f'######### :: {get_url}')
|
| 25 |
+
if not get_url.endswith('.json'):
|
| 26 |
+
feed1 = requests.get(get_url)
|
| 27 |
+
spl = feed1.text.split("href=")
|
| 28 |
+
for line in spl:
|
| 29 |
+
spl2 = line.split(">")[0]
|
| 30 |
+
print(spl2)
|
| 31 |
+
if spl2.endswith('/"') or spl2.endswith('.json"') or spl2.endswith('.png"') or spl2.endswith('.gif"') or spl2.endswith('.jpg"'):
|
| 32 |
+
fin=line.split(">")[0].strip('""')
|
| 33 |
+
link_box.append(fin)
|
| 34 |
+
#html_out=html_out+html.replace("PAGE_LINK",fin)
|
| 35 |
+
return gr.update(choices=[l for l in link_box],interactive=True)
|
| 36 |
+
else:
|
| 37 |
+
return None
|
| 38 |
+
|
| 39 |
+
def get_images():
|
| 40 |
+
html_out=f"<style>{css}</style><div class='img_box'>"
|
| 41 |
+
get_url=f'{main_directory}images/geospace/'
|
| 42 |
+
feed1 = requests.get(get_url)
|
| 43 |
+
spl = feed1.text.split("href=")
|
| 44 |
+
for line in spl:
|
| 45 |
+
spl2 = line.split(">")[0].strip('""')
|
| 46 |
+
if spl2.endswith(".png") or spl2.endswith(".gif") or spl2.endswith(".jpg"):
|
| 47 |
+
print(spl2)
|
| 48 |
+
html_out+=f'<div class="img_class"><a href="{get_url}{spl2}" target="_blank">{spl2}</a><br><img src={get_url}{spl2}></div>'
|
| 49 |
+
else:
|
| 50 |
+
print(spl2)
|
| 51 |
+
get_url2=f'{main_directory}images/'
|
| 52 |
+
feed2 = requests.get(get_url2)
|
| 53 |
+
spl = feed2.text.split("href=")
|
| 54 |
+
for line2 in spl:
|
| 55 |
+
spl2 = line2.split(">")[0].strip('""')
|
| 56 |
+
if spl2.endswith(".png") or spl2.endswith(".gif") or spl2.endswith(".jpg"):
|
| 57 |
+
print(spl2)
|
| 58 |
+
html_out+=f'<div class="img_class"><a href="{get_url2}{spl2}" target="_blank">{spl2}</a><br><img src={get_url2}{spl2}></div>'
|
| 59 |
+
else:
|
| 60 |
+
print(spl2)
|
| 61 |
+
html_out+="</div>"
|
| 62 |
+
return html_out
|
| 63 |
+
|
| 64 |
+
def run():
|
| 65 |
+
out=make_tree()
|
| 66 |
+
im_html=get_images()
|
| 67 |
+
return im_html
|
| 68 |
+
with gr.Blocks() as app:
|
| 69 |
+
#datetimestamp=gr.Textbox()
|
| 70 |
+
#datestamp=gr.Textbox()
|
| 71 |
+
#timestamp=gr.State()
|
| 72 |
+
datetimestamp=str(datetime.datetime.now()).split(".")[0]
|
| 73 |
+
datestamp=datetimestamp.replace(" ","-").split("-")
|
| 74 |
+
timestamp=datestamp[3].split(":")
|
| 75 |
+
with gr.Tab("Raw"):
|
| 76 |
+
with gr.Row():
|
| 77 |
+
drop1=gr.Dropdown()
|
| 78 |
+
drop2=gr.Dropdown()
|
| 79 |
+
drop3=gr.Dropdown()
|
| 80 |
+
drop4=gr.Dropdown()
|
| 81 |
+
with gr.Row():
|
| 82 |
+
drop5=gr.Dropdown()
|
| 83 |
+
drop6=gr.Dropdown()
|
| 84 |
+
drop7=gr.Dropdown()
|
| 85 |
+
drop8=gr.Dropdown()
|
| 86 |
+
load_btn=gr.Button("Load")
|
| 87 |
+
html_raw=gr.HTML()
|
| 88 |
+
links=gr.JSON()
|
| 89 |
+
drop1.change(make_tree,drop1,[drop2])
|
| 90 |
+
drop2.change(make_tree,[drop1,drop2],[drop3])
|
| 91 |
+
drop3.change(make_tree,[drop1,drop2,drop3],[drop4])
|
| 92 |
+
drop4.change(make_tree,[drop1,drop2,drop3,drop4],[drop5])
|
| 93 |
+
drop5.change(make_tree,[drop1,drop2,drop3,drop4,drop5],[drop6])
|
| 94 |
+
drop6.change(make_tree,[drop1,drop2,drop3,drop4,drop5,drop6],[drop7])
|
| 95 |
+
drop7.change(make_tree,[drop1,drop2,drop3,drop4,drop5,drop6,drop7],[drop8])
|
| 96 |
+
|
| 97 |
+
first_btn.click(run,None,[html_im])
|
| 98 |
+
#app.load(make_tree,None,drop1)
|
| 99 |
+
app.queue(default_concurrency_limit=10).launch()
|
| 100 |
+
|