Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -251,26 +251,21 @@ def make_nasa_soho_image_trigger():
|
|
251 |
|
252 |
def nasa_sdo_images(obj,size,date1,date2):
|
253 |
html_in=f"<style>{css}</style><div class='img_box_soho'>"
|
254 |
-
|
255 |
-
|
256 |
if int(date2[6:8])-int(date1[6:8]) >0:
|
257 |
return ("<div style='font-size:xxx-large'>Reduce Timespan to 24 hours</div>")
|
258 |
|
259 |
in_year=f"{date2[0:4]}"
|
260 |
in_month=f"{date2[4:6]}"
|
261 |
in_day=f"{date2[6:8]}"
|
262 |
-
file_name="
|
263 |
sdo_source_format = f"https://sdo.gsfc.nasa.gov/assets/img/browse/{in_year}/{in_month}/{in_day}/"
|
264 |
get_url=sdo_source_format
|
265 |
print(get_url)
|
266 |
feed1 = requests.get(get_url)
|
267 |
-
|
268 |
-
|
269 |
if "All" in size:
|
270 |
size = sdo_size
|
271 |
if "All" in obj:
|
272 |
obj = sdo_obj
|
273 |
-
|
274 |
link_box=[]
|
275 |
# Parse the HTML content using BeautifulSoup
|
276 |
soup = bs4.BeautifulSoup(feed1.content, 'html.parser')
|
@@ -291,6 +286,46 @@ def nasa_sdo_images(obj,size,date1,date2):
|
|
291 |
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>'
|
292 |
html_in+="</div>"
|
293 |
return html_in
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
294 |
def run():
|
295 |
out=make_tree()
|
296 |
im_html=get_images()
|
@@ -344,13 +379,13 @@ with gr.Blocks() as app:
|
|
344 |
with gr.Tab("NASA"):
|
345 |
with gr.Tab("SDO Images"):
|
346 |
with gr.Row():
|
347 |
-
gr.Markdown("<h5>From:")
|
348 |
year1=gr.Number(label="Year",minimum=2000,maximum=2024,precision=0,value=int(datestamp[0]),min_width=10)
|
349 |
month1=gr.Number(label="Month",minimum=1,maximum=12,precision=0,value=int(datestamp[1]),min_width=10)
|
350 |
day1=gr.Number(label="Day",minimum=1,maximum=31,precision=0,value=int(datestamp[2]),min_width=10)
|
351 |
hour1=gr.Number(label="Hour",minimum=0,maximum=23,precision=0,value=int(timestamp[0]),min_width=10)
|
352 |
minute1=gr.Number(label="Minute",minimum=0,maximum=59,precision=0,value=int(timestamp[1]),min_width=10)
|
353 |
-
gr.Markdown("<h5>To:")
|
354 |
year2=gr.Number(label="Year",minimum=2000,maximum=2024,precision=0,value=int(datestamp[0]),min_width=10)
|
355 |
month2=gr.Number(label="Month",minimum=1,maximum=12,precision=0,value=int(datestamp[1]),min_width=10)
|
356 |
day2=gr.Number(label="Day",minimum=1,maximum=31,precision=0,value=int(datestamp[2]),min_width=10)
|
@@ -360,11 +395,17 @@ with gr.Blocks() as app:
|
|
360 |
with gr.Row():
|
361 |
sdo_drop1=gr.Dropdown(label="Instrument", multiselect=True, choices=["All"]+sdo_obj, value="0094")
|
362 |
sdo_drop2=gr.Dropdown(label="Size", multiselect=True, choices=["All"]+sdo_size,value=512)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
363 |
|
364 |
-
|
365 |
-
|
366 |
-
date1=gr.Textbox()
|
367 |
-
date2=gr.Textbox()
|
368 |
#sdo_json=gr.JSON()
|
369 |
with gr.Tab("SOHO Images"):
|
370 |
soho_btn=gr.Button("Load")
|
@@ -374,6 +415,7 @@ with gr.Blocks() as app:
|
|
374 |
html_vid_nasa=gr.HTML()
|
375 |
|
376 |
###### NASA Images ##########
|
|
|
377 |
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)
|
378 |
soho_btn.click(make_nasa_soho_image_trigger,None,html_nasa)
|
379 |
soho_vid_btn.click(make_nasa_soho_videos,None,html_vid_nasa)
|
|
|
251 |
|
252 |
def nasa_sdo_images(obj,size,date1,date2):
|
253 |
html_in=f"<style>{css}</style><div class='img_box_soho'>"
|
|
|
|
|
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=f"{date2[0:4]}"
|
258 |
in_month=f"{date2[4:6]}"
|
259 |
in_day=f"{date2[6:8]}"
|
260 |
+
file_name="DATE_TIME_SIZE_TOOL.jpg"
|
261 |
sdo_source_format = f"https://sdo.gsfc.nasa.gov/assets/img/browse/{in_year}/{in_month}/{in_day}/"
|
262 |
get_url=sdo_source_format
|
263 |
print(get_url)
|
264 |
feed1 = requests.get(get_url)
|
|
|
|
|
265 |
if "All" in size:
|
266 |
size = sdo_size
|
267 |
if "All" in obj:
|
268 |
obj = sdo_obj
|
|
|
269 |
link_box=[]
|
270 |
# Parse the HTML content using BeautifulSoup
|
271 |
soup = bs4.BeautifulSoup(feed1.content, 'html.parser')
|
|
|
286 |
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>'
|
287 |
html_in+="</div>"
|
288 |
return html_in
|
289 |
+
|
290 |
+
def nasa_sdo_composite(obj,size,date1,date2):
|
291 |
+
html_in=f"<style>{css}</style><div class='img_box_soho'>"
|
292 |
+
if int(date2[6:8])-int(date1[6:8]) >0:
|
293 |
+
return ("<div style='font-size:xxx-large'>Reduce Timespan to 24 hours</div>")
|
294 |
+
in_year=f"{date2[0:4]}"
|
295 |
+
in_month=f"{date2[4:6]}"
|
296 |
+
in_day=f"{date2[6:8]}"
|
297 |
+
file_name="DATE_TIME_SIZE_TOOL.jpg"
|
298 |
+
sdo_source_format = f"https://sdo.gsfc.nasa.gov/assets/img/browse/{in_year}/{in_month}/{in_day}/"
|
299 |
+
get_url=sdo_source_format
|
300 |
+
print(get_url)
|
301 |
+
feed1 = requests.get(get_url)
|
302 |
+
if "All" in size:
|
303 |
+
size = sdo_size
|
304 |
+
if "All" in obj:
|
305 |
+
obj = sdo_obj
|
306 |
+
link_box=[]
|
307 |
+
soup = bs4.BeautifulSoup(feed1.content, 'html.parser')
|
308 |
+
anchor_elements = soup.find_all('a')
|
309 |
+
anchor_elements.sort()
|
310 |
+
cnt=0
|
311 |
+
max_cnt=4
|
312 |
+
for element in anchor_elements:
|
313 |
+
if cnt<=max_cnt:
|
314 |
+
href=element.get('href')
|
315 |
+
if href.endswith('.jpg'):
|
316 |
+
for o in obj:
|
317 |
+
for s in size:
|
318 |
+
ls=href.split("_")
|
319 |
+
print(ls[1][0:4])
|
320 |
+
print(date1[8:13])
|
321 |
+
if ls[1][0:4]>=date1[8:13]:
|
322 |
+
src_obj=ls[3].split('.jpg')[0]
|
323 |
+
if src_obj == o:
|
324 |
+
if int(ls[2]) == int(s):
|
325 |
+
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>'
|
326 |
+
html_in+="</div>"
|
327 |
+
return html_in
|
328 |
+
|
329 |
def run():
|
330 |
out=make_tree()
|
331 |
im_html=get_images()
|
|
|
379 |
with gr.Tab("NASA"):
|
380 |
with gr.Tab("SDO Images"):
|
381 |
with gr.Row():
|
382 |
+
gr.Markdown("<h5 style='font-size:xx-large;'>From:")
|
383 |
year1=gr.Number(label="Year",minimum=2000,maximum=2024,precision=0,value=int(datestamp[0]),min_width=10)
|
384 |
month1=gr.Number(label="Month",minimum=1,maximum=12,precision=0,value=int(datestamp[1]),min_width=10)
|
385 |
day1=gr.Number(label="Day",minimum=1,maximum=31,precision=0,value=int(datestamp[2]),min_width=10)
|
386 |
hour1=gr.Number(label="Hour",minimum=0,maximum=23,precision=0,value=int(timestamp[0]),min_width=10)
|
387 |
minute1=gr.Number(label="Minute",minimum=0,maximum=59,precision=0,value=int(timestamp[1]),min_width=10)
|
388 |
+
gr.Markdown("<h5 style='font-size:xx-large;'>To:")
|
389 |
year2=gr.Number(label="Year",minimum=2000,maximum=2024,precision=0,value=int(datestamp[0]),min_width=10)
|
390 |
month2=gr.Number(label="Month",minimum=1,maximum=12,precision=0,value=int(datestamp[1]),min_width=10)
|
391 |
day2=gr.Number(label="Day",minimum=1,maximum=31,precision=0,value=int(datestamp[2]),min_width=10)
|
|
|
395 |
with gr.Row():
|
396 |
sdo_drop1=gr.Dropdown(label="Instrument", multiselect=True, choices=["All"]+sdo_obj, value="0094")
|
397 |
sdo_drop2=gr.Dropdown(label="Size", multiselect=True, choices=["All"]+sdo_size,value=512)
|
398 |
+
|
399 |
+
with gr.Tab("Composite"):
|
400 |
+
sdo_comp_btn=gr.Button("Load")
|
401 |
+
sdo_comp_html=gr.HTML()
|
402 |
+
with gr.Tab("Images"):
|
403 |
+
sdo_btn=gr.Button("Load")
|
404 |
+
sdo_html=gr.HTML()
|
405 |
+
|
406 |
|
407 |
+
date1=gr.Textbox(visible=False)
|
408 |
+
date2=gr.Textbox(visible=False)
|
|
|
|
|
409 |
#sdo_json=gr.JSON()
|
410 |
with gr.Tab("SOHO Images"):
|
411 |
soho_btn=gr.Button("Load")
|
|
|
415 |
html_vid_nasa=gr.HTML()
|
416 |
|
417 |
###### NASA Images ##########
|
418 |
+
sdo_comp_btn.click(get_date,[year1,month1,day1,hour1,minute1,year2,month2,day2,hour2,minute2],[date1,date2]).then(nasa_sdo_composite,[sdo_drop1,sdo_drop2,date1,date2],sdo_comp_html)
|
419 |
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)
|
420 |
soho_btn.click(make_nasa_soho_image_trigger,None,html_nasa)
|
421 |
soho_vid_btn.click(make_nasa_soho_videos,None,html_vid_nasa)
|