Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ from PIL import Image
|
|
6 |
import moviepy.video.io.ImageSequenceClip as ic
|
7 |
from pathlib import Path
|
8 |
import bs4
|
9 |
-
|
10 |
import urllib.request
|
11 |
import uuid
|
12 |
main_directory = "https://services.swpc.noaa.gov/"
|
@@ -245,14 +245,15 @@ def make_nasa_soho_image_trigger():
|
|
245 |
html_in+="</div>"
|
246 |
return html_in
|
247 |
|
248 |
-
def nasa_sdo_images(obj,size):
|
249 |
html_in=f"<style>{css}</style><div class='img_box_soho'>"
|
250 |
-
|
251 |
if size=="All":
|
252 |
size1=9999
|
253 |
else:
|
254 |
size1=size
|
255 |
-
|
|
|
|
|
256 |
in_year="2024"
|
257 |
in_month="03"
|
258 |
in_day="24"
|
@@ -271,21 +272,41 @@ def nasa_sdo_images(obj,size):
|
|
271 |
href=element.get('href')
|
272 |
if href.endswith('.jpg'):
|
273 |
ls=href.split("_")
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
|
|
|
|
|
|
|
|
281 |
html_in+="</div>"
|
282 |
return html_in
|
283 |
def run():
|
284 |
out=make_tree()
|
285 |
im_html=get_images()
|
286 |
return out, im_html
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
287 |
|
288 |
with gr.Blocks() as app:
|
|
|
289 |
with gr.Tab("NOAA"):
|
290 |
with gr.Tab("Images"):
|
291 |
html_im=gr.HTML()
|
@@ -304,6 +325,20 @@ with gr.Blocks() as app:
|
|
304 |
links=gr.JSON()
|
305 |
with gr.Tab("NASA"):
|
306 |
with gr.Tab("SDO Images"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
307 |
with gr.Row():
|
308 |
sdo_drop1=gr.Dropdown(label="Instrument", choices=["All","HMIB","HMIBC","HMIIC","HMIIF","HMID","HMII","HMI171",
|
309 |
"0094","0131","0171","0193","0211",
|
@@ -314,6 +349,8 @@ with gr.Blocks() as app:
|
|
314 |
|
315 |
sdo_btn=gr.Button("Load")
|
316 |
sdo_html=gr.HTML()
|
|
|
|
|
317 |
#sdo_json=gr.JSON()
|
318 |
with gr.Tab("SOHO Images"):
|
319 |
soho_btn=gr.Button("Load")
|
@@ -323,7 +360,7 @@ with gr.Blocks() as app:
|
|
323 |
html_vid_nasa=gr.HTML()
|
324 |
|
325 |
###### NASA Images ##########
|
326 |
-
sdo_btn.click(nasa_sdo_images,[sdo_drop1,sdo_drop2],sdo_html)
|
327 |
soho_btn.click(make_nasa_soho_image_trigger,None,html_nasa)
|
328 |
soho_vid_btn.click(make_nasa_soho_videos,None,html_vid_nasa)
|
329 |
###### NOAA Images ##########
|
|
|
6 |
import moviepy.video.io.ImageSequenceClip as ic
|
7 |
from pathlib import Path
|
8 |
import bs4
|
9 |
+
import datetime
|
10 |
import urllib.request
|
11 |
import uuid
|
12 |
main_directory = "https://services.swpc.noaa.gov/"
|
|
|
245 |
html_in+="</div>"
|
246 |
return html_in
|
247 |
|
248 |
+
def nasa_sdo_images(obj,size,date1,date2):
|
249 |
html_in=f"<style>{css}</style><div class='img_box_soho'>"
|
|
|
250 |
if size=="All":
|
251 |
size1=9999
|
252 |
else:
|
253 |
size1=size
|
254 |
+
if int(date2[6:8])-int(date1[6:8]) >0:
|
255 |
+
return ("<div style='font-size:xxx-large'>Reduce Timespan to 24 hours</div>")
|
256 |
+
|
257 |
in_year="2024"
|
258 |
in_month="03"
|
259 |
in_day="24"
|
|
|
272 |
href=element.get('href')
|
273 |
if href.endswith('.jpg'):
|
274 |
ls=href.split("_")
|
275 |
+
print(ls[1][0:4])
|
276 |
+
print(date1[8:13])
|
277 |
+
if ls[1][0:4]>=date1[8:13]:
|
278 |
+
src_obj=ls[3].split('.jpg')[0]
|
279 |
+
if src_obj == obj or obj=="All":
|
280 |
+
if int(ls[2]) == int(size1) or size=="All":
|
281 |
+
|
282 |
+
#link_json={'year':ls[0][0:4],'month':ls[0][4:6],'day':ls[0][6:8],'time':ls[1],'size':ls[2],'obj':src_obj}
|
283 |
+
#print(href)
|
284 |
+
#link_box.append(link_json)
|
285 |
+
html_in+=f'<div class="img_class_sdo"><a href="{sdo_source_format}{href}" target="_blank">{href}</a><br><img src={sdo_source_format}{href}></div>'
|
286 |
html_in+="</div>"
|
287 |
return html_in
|
288 |
def run():
|
289 |
out=make_tree()
|
290 |
im_html=get_images()
|
291 |
return out, im_html
|
292 |
+
def get_date(year1,month1,day1,hour1,minute1,year2,month2,day2,hour2,minute2):
|
293 |
+
m1 = 0 if len(month1)<2 else m1=None
|
294 |
+
d1 = 0 if len(day1)<2 else d1=None
|
295 |
+
h1 = 0 if len(hour1)<2 else h1=None
|
296 |
+
mi1 = 0 if len(minute1)<2 else mi1=None
|
297 |
+
date1=f'{year1}{m1}{month1}{d1}{day1}{h1}{hour1}{mi1}{minute1}'
|
298 |
+
|
299 |
+
m2 = 0 if len(month1)<2 else m2=None
|
300 |
+
d2 = 0 if len(day1)<2 else d2=None
|
301 |
+
h2 = 0 if len(hour1)<2 else h2=None
|
302 |
+
mi2 = 0 if len(minute1)<2 else mi2=None
|
303 |
+
date2=f'{year2}{m2}{month2}{d2}{day2}{h2}{hour2}{mi2}{minute2}'
|
304 |
+
print(date1)
|
305 |
+
print(date2)
|
306 |
+
return date1,date2
|
307 |
|
308 |
with gr.Blocks() as app:
|
309 |
+
gr.HTML(f"""<div style='font-size:xxx-large;'>Current: {datetime.datetime.now().split(".")[0]} UTC</div>""")
|
310 |
with gr.Tab("NOAA"):
|
311 |
with gr.Tab("Images"):
|
312 |
html_im=gr.HTML()
|
|
|
325 |
links=gr.JSON()
|
326 |
with gr.Tab("NASA"):
|
327 |
with gr.Tab("SDO Images"):
|
328 |
+
with gr.Row():
|
329 |
+
gr.Markdown("<h5>From:")
|
330 |
+
year1=gr.Number(label="Year",minimum=2000,maximum=2024,precision=0,value=2024,min_width=10)
|
331 |
+
month1=gr.Number(label="Month",minimum=1,maximum=12,precision=0,value=1,min_width=10)
|
332 |
+
day1=gr.Number(label="Day",minimum=1,maximum=31,precision=0,value=1,min_width=10)
|
333 |
+
hour1=gr.Number(label="Hour",minimum=0,maximum=23,precision=0,value=0,min_width=10)
|
334 |
+
minute1=gr.Number(label="Minute",minimum=0,maximum=59,precision=0,value=0,min_width=10)
|
335 |
+
gr.Markdown("<h5>To:")
|
336 |
+
year2=gr.Number(label="Year",minimum=2000,maximum=2024,precision=0,value=2024,min_width=10)
|
337 |
+
month2=gr.Number(label="Month",minimum=1,maximum=12,precision=0,value=1,min_width=10)
|
338 |
+
day2=gr.Number(label="Day",minimum=1,maximum=31,precision=0,value=1,min_width=10)
|
339 |
+
hour2=gr.Number(label="Hour",minimum=0,maximum=23,precision=0,value=0,min_width=10)
|
340 |
+
minute2=gr.Number(label="Minute",minimum=0,maximum=59,precision=0,value=0,min_width=10)
|
341 |
+
|
342 |
with gr.Row():
|
343 |
sdo_drop1=gr.Dropdown(label="Instrument", choices=["All","HMIB","HMIBC","HMIIC","HMIIF","HMID","HMII","HMI171",
|
344 |
"0094","0131","0171","0193","0211",
|
|
|
349 |
|
350 |
sdo_btn=gr.Button("Load")
|
351 |
sdo_html=gr.HTML()
|
352 |
+
date1=gr.Textbox()
|
353 |
+
date2=gr.Textbox()
|
354 |
#sdo_json=gr.JSON()
|
355 |
with gr.Tab("SOHO Images"):
|
356 |
soho_btn=gr.Button("Load")
|
|
|
360 |
html_vid_nasa=gr.HTML()
|
361 |
|
362 |
###### NASA Images ##########
|
363 |
+
sdo_btn.click(get_date,[year1,month1,day1,hour1,minute1,year2,month2,day2,hour2,minute2],[date1,date2]).then(nasa_sdo_images,[sdo_drop1,sdo_drop2,date1,date2],sdo_html)
|
364 |
soho_btn.click(make_nasa_soho_image_trigger,None,html_nasa)
|
365 |
soho_vid_btn.click(make_nasa_soho_videos,None,html_vid_nasa)
|
366 |
###### NOAA Images ##########
|