broadfield-dev commited on
Commit
ee716f2
·
verified ·
1 Parent(s): 9b139bb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +115 -152
app.py CHANGED
@@ -73,16 +73,16 @@ sdo_obj = ["HMIB","HMIBC","HMIIC","HMIIF","HMID","HMII","HMI171",
73
  "211193171","211193171n","211193171rg",
74
  "094335193","304211171"]
75
  sdo_size= [256,512,1024,2048,4096]
76
- month_dict={"01":31,"02":28,"03":31,"04":30,"05":31,"06":30,"07":31,"08":31,"09":30,"10":31,"11":30,"12":31}
77
- html = """
78
- <div>
79
- PAGE_LINK
80
- </div>
81
- """
82
  css="""
 
 
 
 
 
 
83
  .img_box{
84
  display: flex;
85
- height: fit-content;
86
  flex-direction: column;
87
  flex-flow: unset;
88
  flex-wrap: wrap;
@@ -108,7 +108,6 @@ css="""
108
  }
109
  .img_box_soho{
110
  display: flex;
111
- height: fit-content;
112
  flex-direction: row;
113
  flex-wrap: wrap;
114
  justify-content: space-between;
@@ -140,8 +139,7 @@ def load_json(url1="",url2="",url3="",url4="",url5="",url6="",url7="",url8=""):
140
  feed1 = requests.get(get_url)
141
  return None, feed1.text
142
  elif get_url.endswith(".png") or get_url.endswith(".gif") or get_url.endswith(".jpg"):
143
- html_out=f"<style>{css}</style><div>"
144
- html_out+=f'<div class="img_class_raw"><a href="{get_url}" target="_blank">{get_url}</a><br><img src={get_url}></div></div>'
145
  return html_out, None
146
  return None,None
147
 
@@ -162,7 +160,7 @@ def make_tree(url1="",url2="",url3="",url4="",url5="",url6="",url7="",url8=""):
162
  return None
163
 
164
  def get_images():
165
- html_out=f"<style>{css}</style><div class='img_box'>"
166
  get_url=f'{main_directory}images/geospace/'
167
  feed1 = requests.get(get_url)
168
  spl = feed1.text.split("href=")
@@ -178,12 +176,11 @@ def get_images():
178
  if spl2.endswith(".png") or spl2.endswith(".gif") or spl2.endswith(".jpg"):
179
  html_out+=f'<div class="img_class"><a href="{get_url2}{spl2}" target="_blank">{spl2}</a><br><img src={get_url2}{spl2}></div>'
180
  html_out+="</div>"
181
- return html_out
182
 
183
  def make_animation_new(gif_box=[], fps=10, loop=True):
184
  if gif_box:
185
  gif_box.sort(reverse=False)
186
- print("Making GIF...")
187
  try:
188
  frames = []
189
  for i,ea in enumerate(gif_box):
@@ -203,30 +200,19 @@ def make_animation_new(gif_box=[], fps=10, loop=True):
203
  gif_base64 = base64.b64encode(gif_bytes).decode('utf-8')
204
  gif_data_url = f"data:image/gif;base64,{gif_base64}"
205
 
206
- html_out=f"<style>{css}</style><div>"
207
- html_out+=f'<div class="img_class"><img src="{gif_data_url}"></div>'
208
- html_out+="</div>"
209
  os.remove(temp_gif_path)
210
  for frame_file in frames:
211
  os.remove(frame_file)
212
- return html_out
213
 
214
  except Exception as e:
215
- print(f"ERROR HAPPENED: {e}")
216
  return f"<div>An error occurred: {e}</div>"
217
  else:
218
  return "<div>No images were provided to create an animation.</div>"
219
 
220
-
221
- def make_html(inp_files):
222
- html_out=f"<style>{css}</style><div class='img_box'>"
223
- for ea in inp_files:
224
- html_out+=f'<div class="img_class"><img src="file={ea}"></div>'
225
- html_out+='</div>'
226
- return html_out
227
-
228
  def make_nasa_soho_videos():
229
- html_out=f"<style>{css}</style><div class='img_box_soho'>"
230
  for ea in nasa_soho_mp4:
231
  file_name=ea['source']
232
  html_out+=f'''
@@ -235,7 +221,7 @@ def make_nasa_soho_videos():
235
  Your browser does not support the video tag.
236
  </video>'''
237
  html_out+='</div>'
238
- return html_out
239
 
240
  def make_nasa_soho_images(inp_src: list):
241
  html_out=""
@@ -245,11 +231,11 @@ def make_nasa_soho_images(inp_src: list):
245
  return html_out
246
 
247
  def make_nasa_soho_image_trigger():
248
- html_in=f"<style>{css}</style><div class='img_box_soho'>"
249
  html_in+= make_nasa_soho_images(nasa_images)
250
  html_in+= make_nasa_soho_images(sdo_aia_latest)
251
  html_in+="</div>"
252
- return html_in
253
 
254
  def generate_sdo_urls(date1_str: str, date2_str: str) -> list[str]:
255
  url_box = []
@@ -272,7 +258,7 @@ def generate_sdo_urls(date1_str: str, date2_str: str) -> list[str]:
272
  return url_box
273
 
274
  def nasa_sdo_images(obj,size,date1,date2):
275
- html_in=f"<style>{css}</style><div class='img_box_soho'>"
276
  sdo_urls = generate_sdo_urls(date1, date2)
277
 
278
  if not sdo_urls:
@@ -293,55 +279,45 @@ def nasa_sdo_images(obj,size,date1,date2):
293
  feed1 = requests.get(link)
294
  feed1.raise_for_status()
295
  except requests.exceptions.RequestException as e:
296
- print(f"Could not fetch {link}: {e}")
297
  continue
298
 
299
- if "All" in size:
300
- size_list = sdo_size
301
- else:
302
- size_list = size
303
- if "All" in obj:
304
- obj_list = sdo_obj
305
- else:
306
- obj_list = obj
307
 
308
  soup = bs4.BeautifulSoup(feed1.content, 'html.parser')
309
- anchor_elements = soup.find_all('a')
310
 
311
- for element in anchor_elements:
312
  href=element.get('href')
313
  if href and href.endswith('.jpg'):
314
  parts = href.split('_')
315
  if len(parts) < 4:
316
  continue
317
 
318
- image_time_str = parts[1]
319
- image_size_str = parts[2]
320
- image_obj_str = parts[3].split('.jpg')[0]
321
 
322
  time_match = False
323
  if is_first_day and is_last_day:
324
- if start_time_str <= image_time_str <= end_time_str:
325
- time_match = True
326
  elif is_first_day:
327
- if image_time_str >= start_time_str:
328
- time_match = True
329
  elif is_last_day:
330
- if image_time_str <= end_time_str:
331
- time_match = True
332
- else: # Middle day
333
  time_match = True
334
 
335
- if time_match:
336
- if image_obj_str in obj_list and int(image_size_str) in size_list:
337
- full_url = f'{link}{href}'
338
- out_box.append(full_url)
339
- html_in+=f'<div class="img_class_sdo"><a href="{full_url}" target="_blank">{href}</a><br><img src={full_url}></div>'
340
  html_in += "</div>"
 
341
  if not out_box:
342
- html_in = "<div>No images found for the specified criteria.</div>"
343
- return html_in, out_box
344
-
 
 
345
 
346
  def get_concat_h_cut(in1, in2):
347
  uid=uuid.uuid4()
@@ -357,10 +333,7 @@ def get_concat_v_cut(in1, in2, theme='dark'):
357
  uid=uuid.uuid4()
358
  im1=Image.open(in1)
359
  im2=Image.open(in2)
360
- if theme=='dark':
361
- color=(31,41,55)
362
- if theme=='light':
363
- color=(255,255,255)
364
  dst = Image.new('RGB', (min(im1.width, im2.width), im1.height + im2.height),color=color)
365
  dst.paste(im1, (0, 0))
366
  dst.paste(im2, (0, im1.height))
@@ -368,46 +341,44 @@ def get_concat_v_cut(in1, in2, theme='dark'):
368
  return f"v_{uid}.jpg"
369
 
370
  def nasa_sdo_composite(obj,size,date1,date2,ret_num):
371
- html_in=f"<style>{css}</style><div class='img_box_soho'>"
372
- in_year=f"{date2[0:4]}"
373
- in_month=f"{date2[4:6]}"
374
- in_day=f"{date2[6:8]}"
375
  sdo_source_format = f"https://sdo.gsfc.nasa.gov/assets/img/browse/{in_year}/{in_month}/{in_day}/"
376
- get_url=sdo_source_format
377
- feed1 = requests.get(get_url)
378
- if "All" in size:
379
- size = sdo_size
380
- if "All" in obj:
381
- obj = sdo_obj
 
 
 
 
382
  link_box=[]
383
  soup = bs4.BeautifulSoup(feed1.content, 'html.parser')
384
- anchor_elements = soup.find_all('a')
385
- cnt=1
386
- max_cnt=ret_num
387
- for element in anchor_elements:
388
  href=element.get('href')
389
- if href.endswith('.jpg'):
390
- for o in obj:
391
- for s in size:
392
- ls=href.split("_")
393
- if ls[1][0:4]>=date1[8:13]:
394
- src_obj=ls[3].split('.jpg')[0]
395
- if src_obj == o:
396
- if int(ls[2]) == int(s):
397
- link_box.append(href)
398
  link_box.sort(reverse=True)
399
  out_box=[]
400
- for ea in link_box:
401
- if cnt<=max_cnt:
402
  out_link=f'{sdo_source_format}{ea}'
403
  out_box.append(out_link)
404
- cnt+=1
405
- 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>'
406
  html_in+="</div>"
407
- return html_in, out_box
408
 
409
  def run():
410
- out=make_tree()
411
  im_html=get_images()
412
  return im_html
413
 
@@ -419,55 +390,48 @@ def get_date(year1,month1,day1,hour1,minute1,year2,month2,day2,hour2,minute2):
419
  date2 = end_dt.strftime('%Y%m%d%H%M')
420
  return date1, date2
421
  except ValueError as e:
422
- print(f"Error creating date: {e}")
423
  return None, None
424
 
425
-
426
  def comp_combine(inp_ims: list,comp_col,comp_row,resize=False):
427
  im_box=[]
428
- v_box=[]
429
- rows=comp_row
430
- cols=comp_col
431
- if not type(inp_ims)==type([]):
432
- try:
433
- inp_ims=eval(inp_ims)
434
- except:
435
- return None
436
- if not inp_ims:
437
- return None
438
 
439
- for i,im in enumerate(inp_ims):
440
- urllib.request.urlretrieve(im, f"tmp-{i}.jpg")
441
- if resize:
442
- pil_im = Image.open(f'tmp-{i}.jpg')
443
- pil_im = pil_im.resize((int(resize[0]),int(resize[1])),resample=Image.Resampling.LANCZOS).convert('RGB')
444
- pil_im.save(f'tmp-{i}.jpg')
445
- im_box.append(f"tmp-{i}.jpg")
446
- im_cnt=len(im_box)
447
- cnt=1
448
- for rr in range(rows):
449
- if cnt > im_cnt: break
450
- col_start=[im_box[cnt-1]]
451
- for cc in range(cols-1):
452
- try:
453
- if cnt >= im_cnt: break
454
- col_out=get_concat_h_cut(col_start[0],im_box[cnt])
455
- col_start[0]=col_out
456
- cnt+=1
457
- except Exception as e:
458
- pass
459
- v_box.append(col_start[0])
460
- if not v_box:
461
- return None
462
-
463
- v_cnt=1
464
- v_box_cnt=len(v_box)
465
- v_start=[v_box[0]]
466
- for vv in range(v_box_cnt-1):
467
- v_out=get_concat_v_cut(v_start[0],v_box[v_cnt])
468
- v_start[0]=v_out
469
- v_cnt+=1
470
- return v_start[0]
 
471
 
472
  def comp_1(comp_list=comp_list,col=3,row=4,resize=[640,450]):
473
  outp=comp_combine(comp_list,col,row,resize)
@@ -480,7 +444,7 @@ def get_time():
480
  return (gr.update(value=html_out), now.year, now.month, now.day, now.hour, now.minute,
481
  now.year, now.month, now.day, now.hour, now.minute)
482
 
483
- with gr.Blocks() as app:
484
  url_list=gr.State([])
485
  now = datetime.datetime.utcnow()
486
 
@@ -509,18 +473,18 @@ with gr.Blocks() as app:
509
  with gr.Tab("NASA"):
510
  with gr.Tab("SDO Images"):
511
  with gr.Row():
512
- gr.Markdown("<h5 style='font-size:xx-large;'>From:")
513
- year1=gr.Number(label="Year",minimum=2010,maximum=now.year,precision=0,value=now.year,min_width=10)
514
- month1=gr.Number(label="Month",minimum=1,maximum=12,precision=0,value=now.month,min_width=10)
515
- day1=gr.Number(label="Day",minimum=1,maximum=31,precision=0,value=now.day,min_width=10)
516
- hour1=gr.Number(label="Hour",minimum=0,maximum=23,precision=0,value=now.hour,min_width=10)
517
- minute1=gr.Number(label="Minute",minimum=0,maximum=59,precision=0,value=now.minute,min_width=10)
518
- gr.Markdown("<h5 style='font-size:xx-large;'>To:")
519
- year2=gr.Number(label="Year",minimum=2010,maximum=now.year,precision=0,value=now.year,min_width=10)
520
- month2=gr.Number(label="Month",minimum=1,maximum=12,precision=0,value=now.month,min_width=10)
521
- day2=gr.Number(label="Day",minimum=1,maximum=31,precision=0,value=now.day,min_width=10)
522
- hour2=gr.Number(label="Hour",minimum=0,maximum=23,precision=0,value=now.hour,min_width=10)
523
- minute2=gr.Number(label="Minute",minimum=0,maximum=59,precision=0,value=now.minute,min_width=10)
524
 
525
  with gr.Row():
526
  sdo_drop1=gr.Dropdown(label="Instrument", multiselect=True, choices=["All"]+sdo_obj, value="0094")
@@ -535,7 +499,6 @@ with gr.Blocks() as app:
535
  comp_combine_btn=gr.Button("Combine")
536
  sdo_comp_btn=gr.Button("Load")
537
  img_out=gr.Image()
538
- comp_combine_html=gr.HTML()
539
  sdo_comp_html=gr.HTML()
540
  image_comp_list=gr.Textbox(visible=True)
541
  with gr.Tab("Images"):
@@ -545,7 +508,6 @@ with gr.Blocks() as app:
545
  loop_checkbox = gr.Checkbox(label="Loop Animation", value=True)
546
  sdo_gif=gr.Button("Make GIF")
547
  sdo_gif_html=gr.HTML()
548
- sdo_gif.click(make_animation_new,[url_list, fps_slider, loop_checkbox],sdo_gif_html)
549
  sdo_html=gr.HTML()
550
 
551
  date1=gr.Textbox(visible=False)
@@ -559,6 +521,7 @@ with gr.Blocks() as app:
559
 
560
  app.load(get_time,None,[time_html,year1,month1,day1,hour1,minute1,year2,month2,day2,hour2,minute2]).then(make_tree,None,drop1)
561
 
 
562
  first_comp_btn.click(comp_1,None,first_comp_img)
563
  comp_combine_btn.click(comp_combine,[image_comp_list,comp_col,comp_row],img_out)
564
  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,comp_num],[sdo_comp_html,image_comp_list])
 
73
  "211193171","211193171n","211193171rg",
74
  "094335193","304211171"]
75
  sdo_size= [256,512,1024,2048,4096]
76
+
 
 
 
 
 
77
  css="""
78
+ .gallery-container {
79
+ max-height: 80vh;
80
+ overflow-y: auto;
81
+ border: 1px solid #e0e0e0;
82
+ padding: 10px;
83
+ }
84
  .img_box{
85
  display: flex;
 
86
  flex-direction: column;
87
  flex-flow: unset;
88
  flex-wrap: wrap;
 
108
  }
109
  .img_box_soho{
110
  display: flex;
 
111
  flex-direction: row;
112
  flex-wrap: wrap;
113
  justify-content: space-between;
 
139
  feed1 = requests.get(get_url)
140
  return None, feed1.text
141
  elif get_url.endswith(".png") or get_url.endswith(".gif") or get_url.endswith(".jpg"):
142
+ html_out=f'<div><div class="img_class_raw"><a href="{get_url}" target="_blank">{get_url}</a><br><img src={get_url}></div></div>'
 
143
  return html_out, None
144
  return None,None
145
 
 
160
  return None
161
 
162
  def get_images():
163
+ html_out="<div class='img_box'>"
164
  get_url=f'{main_directory}images/geospace/'
165
  feed1 = requests.get(get_url)
166
  spl = feed1.text.split("href=")
 
176
  if spl2.endswith(".png") or spl2.endswith(".gif") or spl2.endswith(".jpg"):
177
  html_out+=f'<div class="img_class"><a href="{get_url2}{spl2}" target="_blank">{spl2}</a><br><img src={get_url2}{spl2}></div>'
178
  html_out+="</div>"
179
+ return f"<div class='gallery-container'>{html_out}</div>"
180
 
181
  def make_animation_new(gif_box=[], fps=10, loop=True):
182
  if gif_box:
183
  gif_box.sort(reverse=False)
 
184
  try:
185
  frames = []
186
  for i,ea in enumerate(gif_box):
 
200
  gif_base64 = base64.b64encode(gif_bytes).decode('utf-8')
201
  gif_data_url = f"data:image/gif;base64,{gif_base64}"
202
 
203
+ html_out=f'<div><div class="img_class"><img src="{gif_data_url}"></div></div>'
 
 
204
  os.remove(temp_gif_path)
205
  for frame_file in frames:
206
  os.remove(frame_file)
207
+ return f"<div class='gallery-container'>{html_out}</div>"
208
 
209
  except Exception as e:
 
210
  return f"<div>An error occurred: {e}</div>"
211
  else:
212
  return "<div>No images were provided to create an animation.</div>"
213
 
 
 
 
 
 
 
 
 
214
  def make_nasa_soho_videos():
215
+ html_out="<div class='img_box_soho'>"
216
  for ea in nasa_soho_mp4:
217
  file_name=ea['source']
218
  html_out+=f'''
 
221
  Your browser does not support the video tag.
222
  </video>'''
223
  html_out+='</div>'
224
+ return f"<div class='gallery-container'>{html_out}</div>"
225
 
226
  def make_nasa_soho_images(inp_src: list):
227
  html_out=""
 
231
  return html_out
232
 
233
  def make_nasa_soho_image_trigger():
234
+ html_in="<div class='img_box_soho'>"
235
  html_in+= make_nasa_soho_images(nasa_images)
236
  html_in+= make_nasa_soho_images(sdo_aia_latest)
237
  html_in+="</div>"
238
+ return f"<div class='gallery-container'>{html_in}</div>"
239
 
240
  def generate_sdo_urls(date1_str: str, date2_str: str) -> list[str]:
241
  url_box = []
 
258
  return url_box
259
 
260
  def nasa_sdo_images(obj,size,date1,date2):
261
+ html_in="<div class='img_box_soho'>"
262
  sdo_urls = generate_sdo_urls(date1, date2)
263
 
264
  if not sdo_urls:
 
279
  feed1 = requests.get(link)
280
  feed1.raise_for_status()
281
  except requests.exceptions.RequestException as e:
 
282
  continue
283
 
284
+ size_list = sdo_size if "All" in size else size
285
+ obj_list = sdo_obj if "All" in obj else obj
 
 
 
 
 
 
286
 
287
  soup = bs4.BeautifulSoup(feed1.content, 'html.parser')
 
288
 
289
+ for element in soup.find_all('a'):
290
  href=element.get('href')
291
  if href and href.endswith('.jpg'):
292
  parts = href.split('_')
293
  if len(parts) < 4:
294
  continue
295
 
296
+ image_time_str, image_size_str, image_obj_str = parts[1], parts[2], parts[3].split('.jpg')[0]
 
 
297
 
298
  time_match = False
299
  if is_first_day and is_last_day:
300
+ if start_time_str <= image_time_str <= end_time_str: time_match = True
 
301
  elif is_first_day:
302
+ if image_time_str >= start_time_str: time_match = True
 
303
  elif is_last_day:
304
+ if image_time_str <= end_time_str: time_match = True
305
+ else:
 
306
  time_match = True
307
 
308
+ if time_match and image_obj_str in obj_list and int(image_size_str) in size_list:
309
+ full_url = f'{link}{href}'
310
+ out_box.append(full_url)
311
+ html_in+=f'<div class="img_class_sdo"><a href="{full_url}" target="_blank">{href}</a><br><img src={full_url}></div>'
312
+
313
  html_in += "</div>"
314
+
315
  if not out_box:
316
+ final_html = "<div>No images found for the specified criteria.</div>"
317
+ else:
318
+ final_html = f"<div class='gallery-container'>{html_in}</div>"
319
+
320
+ return final_html, out_box
321
 
322
  def get_concat_h_cut(in1, in2):
323
  uid=uuid.uuid4()
 
333
  uid=uuid.uuid4()
334
  im1=Image.open(in1)
335
  im2=Image.open(in2)
336
+ color = (31,41,55) if theme=='dark' else (255,255,255)
 
 
 
337
  dst = Image.new('RGB', (min(im1.width, im2.width), im1.height + im2.height),color=color)
338
  dst.paste(im1, (0, 0))
339
  dst.paste(im2, (0, im1.height))
 
341
  return f"v_{uid}.jpg"
342
 
343
  def nasa_sdo_composite(obj,size,date1,date2,ret_num):
344
+ html_in="<div class='img_box_soho'>"
345
+ in_year, in_month, in_day = date2[0:4], date2[4:6], date2[6:8]
 
 
346
  sdo_source_format = f"https://sdo.gsfc.nasa.gov/assets/img/browse/{in_year}/{in_month}/{in_day}/"
347
+
348
+ try:
349
+ feed1 = requests.get(sdo_source_format)
350
+ feed1.raise_for_status()
351
+ except requests.exceptions.RequestException:
352
+ return "<div>Could not fetch SDO composite images.</div>", []
353
+
354
+ size_list = sdo_size if "All" in size else size
355
+ obj_list = sdo_obj if "All" in obj else obj
356
+
357
  link_box=[]
358
  soup = bs4.BeautifulSoup(feed1.content, 'html.parser')
359
+
360
+ for element in soup.find_all('a'):
 
 
361
  href=element.get('href')
362
+ if href and href.endswith('.jpg'):
363
+ parts=href.split("_")
364
+ if len(parts) < 4: continue
365
+ if parts[1][0:4]>=date1[8:12]:
366
+ src_obj=parts[3].split('.jpg')[0]
367
+ if src_obj in obj_list and int(parts[2]) in size_list:
368
+ link_box.append(href)
369
+
 
370
  link_box.sort(reverse=True)
371
  out_box=[]
372
+ for i, ea in enumerate(link_box):
373
+ if i < ret_num:
374
  out_link=f'{sdo_source_format}{ea}'
375
  out_box.append(out_link)
376
+ html_in+=f'<div class="img_class_sdo"><a href="{out_link}" target="_blank">{ea}</a><br><img src={out_link}></div>'
377
+
378
  html_in+="</div>"
379
+ return f"<div class='gallery-container'>{html_in}</div>", out_box
380
 
381
  def run():
 
382
  im_html=get_images()
383
  return im_html
384
 
 
390
  date2 = end_dt.strftime('%Y%m%d%H%M')
391
  return date1, date2
392
  except ValueError as e:
 
393
  return None, None
394
 
 
395
  def comp_combine(inp_ims: list,comp_col,comp_row,resize=False):
396
  im_box=[]
397
+ if not isinstance(inp_ims, list):
398
+ try: inp_ims=eval(inp_ims)
399
+ except: return None
400
+ if not inp_ims: return None
 
 
 
 
 
 
401
 
402
+ for i,im_url in enumerate(inp_ims):
403
+ try:
404
+ tmp_file = f"tmp-{i}.jpg"
405
+ urllib.request.urlretrieve(im_url, tmp_file)
406
+ if resize:
407
+ with Image.open(tmp_file) as pil_im:
408
+ resized_im = pil_im.resize((int(resize[0]),int(resize[1])),resample=Image.Resampling.LANCZOS).convert('RGB')
409
+ resized_im.save(tmp_file)
410
+ im_box.append(tmp_file)
411
+ except Exception:
412
+ continue
413
+
414
+ if not im_box: return None
415
+
416
+ rows, cols = int(comp_row), int(comp_col)
417
+ v_box, im_idx = [], 0
418
+ for _ in range(rows):
419
+ if im_idx >= len(im_box): break
420
+ h_strip = im_box[im_idx]
421
+ im_idx += 1
422
+ for _ in range(cols - 1):
423
+ if im_idx >= len(im_box): break
424
+ h_strip = get_concat_h_cut(h_strip, im_box[im_idx])
425
+ im_idx += 1
426
+ v_box.append(h_strip)
427
+
428
+ if not v_box: return None
429
+
430
+ final_image = v_box[0]
431
+ for i in range(1, len(v_box)):
432
+ final_image = get_concat_v_cut(final_image, v_box[i])
433
+
434
+ return final_image
435
 
436
  def comp_1(comp_list=comp_list,col=3,row=4,resize=[640,450]):
437
  outp=comp_combine(comp_list,col,row,resize)
 
444
  return (gr.update(value=html_out), now.year, now.month, now.day, now.hour, now.minute,
445
  now.year, now.month, now.day, now.hour, now.minute)
446
 
447
+ with gr.Blocks(css=css) as app:
448
  url_list=gr.State([])
449
  now = datetime.datetime.utcnow()
450
 
 
473
  with gr.Tab("NASA"):
474
  with gr.Tab("SDO Images"):
475
  with gr.Row():
476
+ gr.Markdown("<h5>From:")
477
+ year1=gr.Number(label="Year",minimum=2010,maximum=now.year,precision=0,value=now.year)
478
+ month1=gr.Number(label="Month",minimum=1,maximum=12,precision=0,value=now.month)
479
+ day1=gr.Number(label="Day",minimum=1,maximum=31,precision=0,value=now.day)
480
+ hour1=gr.Number(label="Hour",minimum=0,maximum=23,precision=0,value=now.hour)
481
+ minute1=gr.Number(label="Minute",minimum=0,maximum=59,precision=0,value=now.minute)
482
+ gr.Markdown("<h5>To:")
483
+ year2=gr.Number(label="Year",minimum=2010,maximum=now.year,precision=0,value=now.year)
484
+ month2=gr.Number(label="Month",minimum=1,maximum=12,precision=0,value=now.month)
485
+ day2=gr.Number(label="Day",minimum=1,maximum=31,precision=0,value=now.day)
486
+ hour2=gr.Number(label="Hour",minimum=0,maximum=23,precision=0,value=now.hour)
487
+ minute2=gr.Number(label="Minute",minimum=0,maximum=59,precision=0,value=now.minute)
488
 
489
  with gr.Row():
490
  sdo_drop1=gr.Dropdown(label="Instrument", multiselect=True, choices=["All"]+sdo_obj, value="0094")
 
499
  comp_combine_btn=gr.Button("Combine")
500
  sdo_comp_btn=gr.Button("Load")
501
  img_out=gr.Image()
 
502
  sdo_comp_html=gr.HTML()
503
  image_comp_list=gr.Textbox(visible=True)
504
  with gr.Tab("Images"):
 
508
  loop_checkbox = gr.Checkbox(label="Loop Animation", value=True)
509
  sdo_gif=gr.Button("Make GIF")
510
  sdo_gif_html=gr.HTML()
 
511
  sdo_html=gr.HTML()
512
 
513
  date1=gr.Textbox(visible=False)
 
521
 
522
  app.load(get_time,None,[time_html,year1,month1,day1,hour1,minute1,year2,month2,day2,hour2,minute2]).then(make_tree,None,drop1)
523
 
524
+ sdo_gif.click(make_animation_new,[url_list, fps_slider, loop_checkbox],sdo_gif_html)
525
  first_comp_btn.click(comp_1,None,first_comp_img)
526
  comp_combine_btn.click(comp_combine,[image_comp_list,comp_col,comp_row],img_out)
527
  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,comp_num],[sdo_comp_html,image_comp_list])