Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -287,6 +287,31 @@ def nasa_sdo_images(obj,size,date1,date2):
|
|
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:
|
@@ -326,13 +351,16 @@ def nasa_sdo_composite(obj,size,date1,date2):
|
|
326 |
print("$$$$$$$$$$$$$$$$$")
|
327 |
link_box.sort(reverse=True)
|
328 |
print(link_box)
|
|
|
329 |
for ea in link_box:
|
330 |
if cnt<=max_cnt:
|
|
|
|
|
331 |
cnt+=1
|
332 |
html_in+=f'<div class="img_class_sdo"><a href="{sdo_source_format}{ea}" target="_blank">{ea}</a><br><img src={sdo_source_format}{ea}></div>'
|
333 |
|
334 |
html_in+="</div>"
|
335 |
-
return html_in
|
336 |
|
337 |
def run():
|
338 |
out=make_tree()
|
@@ -361,7 +389,37 @@ def get_date(year1,month1,day1,hour1,minute1,year2,month2,day2,hour2,minute2):
|
|
361 |
print(date1)
|
362 |
print(date2)
|
363 |
return date1,date2
|
364 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
365 |
with gr.Blocks() as app:
|
366 |
datetimestamp=str(datetime.datetime.now()).split(".")[0]
|
367 |
datestamp=datetimestamp.replace(" ","-").split("-")
|
@@ -405,8 +463,17 @@ with gr.Blocks() as app:
|
|
405 |
sdo_drop2=gr.Dropdown(label="Size", multiselect=True, choices=["All"]+sdo_size,value=512)
|
406 |
|
407 |
with gr.Tab("Composite"):
|
408 |
-
|
409 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
410 |
with gr.Tab("Images"):
|
411 |
sdo_btn=gr.Button("Load")
|
412 |
sdo_html=gr.HTML()
|
@@ -422,8 +489,11 @@ with gr.Blocks() as app:
|
|
422 |
soho_vid_btn=gr.Button("Load")
|
423 |
html_vid_nasa=gr.HTML()
|
424 |
|
|
|
|
|
|
|
|
|
425 |
###### NASA Images ##########
|
426 |
-
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)
|
427 |
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)
|
428 |
soho_btn.click(make_nasa_soho_image_trigger,None,html_nasa)
|
429 |
soho_vid_btn.click(make_nasa_soho_videos,None,html_vid_nasa)
|
|
|
287 |
html_in+="</div>"
|
288 |
return html_in
|
289 |
|
290 |
+
def get_concat_h_cut(in1, in2):
|
291 |
+
im1=Image.open(in1)
|
292 |
+
im2=Image.open(in2)
|
293 |
+
dst = Image.new('RGB', (im1.width + im2.width,
|
294 |
+
min(im1.height, im2.height)))
|
295 |
+
dst.paste(im1, (0, 0))
|
296 |
+
dst.paste(im2, (im1.width, 0))
|
297 |
+
return dst
|
298 |
+
|
299 |
+
|
300 |
+
def get_concat_v_cut(in1, in2, theme='dark'):
|
301 |
+
im1=Image.open(in1)
|
302 |
+
im2=Image.open(in2)
|
303 |
+
if theme=='dark':
|
304 |
+
color=(31,41,55)
|
305 |
+
if theme=='light':
|
306 |
+
color=(255,255,255)
|
307 |
+
dst = Image.new('RGB', (min(im1.width, im2.width), im1.height + im2.height),color=color)
|
308 |
+
dst.paste(im1, (0, 0))
|
309 |
+
dst.paste(im2, (0, im1.height))
|
310 |
+
return dst
|
311 |
+
|
312 |
+
|
313 |
+
|
314 |
+
|
315 |
def nasa_sdo_composite(obj,size,date1,date2):
|
316 |
html_in=f"<style>{css}</style><div class='img_box_soho'>"
|
317 |
if int(date2[6:8])-int(date1[6:8]) >0:
|
|
|
351 |
print("$$$$$$$$$$$$$$$$$")
|
352 |
link_box.sort(reverse=True)
|
353 |
print(link_box)
|
354 |
+
out_box=[]
|
355 |
for ea in link_box:
|
356 |
if cnt<=max_cnt:
|
357 |
+
out_link=f'{sdo_source_format}{ea}'
|
358 |
+
out_box.append(out_link)
|
359 |
cnt+=1
|
360 |
html_in+=f'<div class="img_class_sdo"><a href="{sdo_source_format}{ea}" target="_blank">{ea}</a><br><img src={sdo_source_format}{ea}></div>'
|
361 |
|
362 |
html_in+="</div>"
|
363 |
+
return html_in, out_box
|
364 |
|
365 |
def run():
|
366 |
out=make_tree()
|
|
|
389 |
print(date1)
|
390 |
print(date2)
|
391 |
return date1,date2
|
392 |
+
def comp_combine(inp_ims: list):
|
393 |
+
im_box=[]
|
394 |
+
v_box=[]
|
395 |
+
rows=2
|
396 |
+
cols=2
|
397 |
+
for i,im in enumerate(inp_ims):
|
398 |
+
urllib.request.urlretrieve(im, f"tmp-{i}.jpg")
|
399 |
+
im_box.append(f"tmp-{i}.png")
|
400 |
+
im_cnt=len(im_box)
|
401 |
+
cnt=1
|
402 |
+
col_start=[im_box[0]]
|
403 |
+
|
404 |
+
for rr in range(rows):
|
405 |
+
for cc in range(cols):
|
406 |
+
col_out=get_concat_h_cut(col_start[0],im_box[cnt])
|
407 |
+
col_start[0]=col_out
|
408 |
+
cnt+=1
|
409 |
+
if cnt>im_cnt:
|
410 |
+
rr=range(rows)
|
411 |
+
cc=range(cols)
|
412 |
+
v_box.append(col_out)
|
413 |
+
print(v_box)
|
414 |
+
v_cnt=0
|
415 |
+
v_box_cnt=len(v_box)
|
416 |
+
v_start=[v_box[0]]
|
417 |
+
for vv in range(v_box_cnt):
|
418 |
+
print(rr)
|
419 |
+
v_out=get_concat_v_cut(v_start[0],v_box[v_cnt])
|
420 |
+
v_start[0]=v_out
|
421 |
+
return v_out
|
422 |
+
|
423 |
with gr.Blocks() as app:
|
424 |
datetimestamp=str(datetime.datetime.now()).split(".")[0]
|
425 |
datestamp=datetimestamp.replace(" ","-").split("-")
|
|
|
463 |
sdo_drop2=gr.Dropdown(label="Size", multiselect=True, choices=["All"]+sdo_size,value=512)
|
464 |
|
465 |
with gr.Tab("Composite"):
|
466 |
+
with gr.Row():
|
467 |
+
comp_num=gr.Number(label="Return",precision=0,value=4)
|
468 |
+
comp_col=gr.Number(label="Columns",precision=0)
|
469 |
+
comp_row=gr.Number(label="Rows",precision=0)
|
470 |
+
with gr.Row():
|
471 |
+
comp_combine_btn=gr.Button("Combine")
|
472 |
+
sdo_comp_btn=gr.Button("Load")
|
473 |
+
img_out=gr.Image()
|
474 |
+
comp_combine_html=gr.HTML()
|
475 |
+
sdo_comp_html=gr.HTML()
|
476 |
+
image_comp_list=gr.Textbox(visible=True)
|
477 |
with gr.Tab("Images"):
|
478 |
sdo_btn=gr.Button("Load")
|
479 |
sdo_html=gr.HTML()
|
|
|
489 |
soho_vid_btn=gr.Button("Load")
|
490 |
html_vid_nasa=gr.HTML()
|
491 |
|
492 |
+
###### Composite Images ##########
|
493 |
+
comp_combine_btn.click(comp_combine,image_comp_list,img_out)
|
494 |
+
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,image_comp_list])
|
495 |
+
|
496 |
###### NASA Images ##########
|
|
|
497 |
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)
|
498 |
soho_btn.click(make_nasa_soho_image_trigger,None,html_nasa)
|
499 |
soho_vid_btn.click(make_nasa_soho_videos,None,html_vid_nasa)
|