Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -227,6 +227,50 @@ def make_animation():
|
|
| 227 |
print(e)
|
| 228 |
return files_out
|
| 229 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
def make_html(inp_files):
|
| 231 |
html_out=f"<style>{css}</style><div class='img_box'>"
|
| 232 |
for ea in inp_files:
|
|
@@ -307,7 +351,7 @@ def nasa_sdo_images(obj,size,date1,date2):
|
|
| 307 |
if int(ls[2]) == int(s):
|
| 308 |
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>'
|
| 309 |
html_in+="</div>"
|
| 310 |
-
return html_in
|
| 311 |
|
| 312 |
def get_concat_h_cut(in1, in2):
|
| 313 |
uid=uuid.uuid4()
|
|
@@ -491,7 +535,7 @@ def get_time():
|
|
| 491 |
with gr.Blocks() as app:
|
| 492 |
#datetimestamp=gr.Textbox()
|
| 493 |
#datestamp=gr.Textbox()
|
| 494 |
-
|
| 495 |
datetimestamp=str(datetime.datetime.now()).split(".")[0]
|
| 496 |
datestamp=datetimestamp.replace(" ","-").split("-")
|
| 497 |
timestamp=datestamp[3].split(":")
|
|
@@ -556,6 +600,9 @@ with gr.Blocks() as app:
|
|
| 556 |
image_comp_list=gr.Textbox(visible=True)
|
| 557 |
with gr.Tab("Images"):
|
| 558 |
sdo_btn=gr.Button("Load")
|
|
|
|
|
|
|
|
|
|
| 559 |
sdo_html=gr.HTML()
|
| 560 |
|
| 561 |
|
|
@@ -576,7 +623,7 @@ with gr.Blocks() as app:
|
|
| 576 |
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])
|
| 577 |
|
| 578 |
###### NASA Images ##########
|
| 579 |
-
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)
|
| 580 |
soho_btn.click(make_nasa_soho_image_trigger,None,html_nasa)
|
| 581 |
soho_vid_btn.click(make_nasa_soho_videos,None,html_vid_nasa)
|
| 582 |
###### NOAA Images ##########
|
|
|
|
| 227 |
print(e)
|
| 228 |
return files_out
|
| 229 |
|
| 230 |
+
|
| 231 |
+
def make_animation_new(gif_box=[]):
|
| 232 |
+
|
| 233 |
+
if gif_box:
|
| 234 |
+
print(gif_box)
|
| 235 |
+
gif_box.sort(reverse=False)
|
| 236 |
+
print("Making GIF...")
|
| 237 |
+
try:
|
| 238 |
+
#frames = [Image.open(image) for image in glob.glob(f"{frame_folder}/*.JPG")]
|
| 239 |
+
frames = []
|
| 240 |
+
for i,ea in enumerate(gif_box):
|
| 241 |
+
print("############")
|
| 242 |
+
print(ea)
|
| 243 |
+
urllib.request.urlretrieve(ea,f'tmp{i}.png')
|
| 244 |
+
frames.append(f'tmp{i}.png')
|
| 245 |
+
fps=60
|
| 246 |
+
uid=uuid.uuid4()
|
| 247 |
+
clip = ic.ImageSequenceClip(frames, fps = fps)
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
# Save GIF to a temporary file
|
| 251 |
+
temp_gif_path = f"temp_{uid}.gif"
|
| 252 |
+
clip.write_gif(temp_gif_path, fps=fps)
|
| 253 |
+
|
| 254 |
+
# Read the GIF file into bytes
|
| 255 |
+
with open(temp_gif_path, 'rb') as gif_file:
|
| 256 |
+
gif_bytes = gif_file.read()
|
| 257 |
+
|
| 258 |
+
# Encode GIF bytes as base64 for HTML
|
| 259 |
+
gif_base64 = base64.b64encode(gif_bytes).decode('utf-8')
|
| 260 |
+
gif_data_url = f"data:image/gif;base64,{gif_base64}"
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
html_out=f"<style>{css}</style><div>"
|
| 264 |
+
html_out+=f'<div class="img_class"><img src="{gif_data_url}"></div>'
|
| 265 |
+
html_out+="</div>"
|
| 266 |
+
except Exception as e:
|
| 267 |
+
print("ERROR HAPPENED")
|
| 268 |
+
print(e)
|
| 269 |
+
|
| 270 |
+
else:
|
| 271 |
+
print("passed")
|
| 272 |
+
|
| 273 |
+
return html_out
|
| 274 |
def make_html(inp_files):
|
| 275 |
html_out=f"<style>{css}</style><div class='img_box'>"
|
| 276 |
for ea in inp_files:
|
|
|
|
| 351 |
if int(ls[2]) == int(s):
|
| 352 |
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>'
|
| 353 |
html_in+="</div>"
|
| 354 |
+
return html_in, link_box
|
| 355 |
|
| 356 |
def get_concat_h_cut(in1, in2):
|
| 357 |
uid=uuid.uuid4()
|
|
|
|
| 535 |
with gr.Blocks() as app:
|
| 536 |
#datetimestamp=gr.Textbox()
|
| 537 |
#datestamp=gr.Textbox()
|
| 538 |
+
url_list=gr.State([])
|
| 539 |
datetimestamp=str(datetime.datetime.now()).split(".")[0]
|
| 540 |
datestamp=datetimestamp.replace(" ","-").split("-")
|
| 541 |
timestamp=datestamp[3].split(":")
|
|
|
|
| 600 |
image_comp_list=gr.Textbox(visible=True)
|
| 601 |
with gr.Tab("Images"):
|
| 602 |
sdo_btn=gr.Button("Load")
|
| 603 |
+
sdo_gif=gr.Button("Make GIF")
|
| 604 |
+
sdo_gif_html=gr.HTML()
|
| 605 |
+
sdo_gif.click(make_animation_new,url_list,sdo_gif_html)
|
| 606 |
sdo_html=gr.HTML()
|
| 607 |
|
| 608 |
|
|
|
|
| 623 |
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])
|
| 624 |
|
| 625 |
###### NASA Images ##########
|
| 626 |
+
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,url_list])
|
| 627 |
soho_btn.click(make_nasa_soho_image_trigger,None,html_nasa)
|
| 628 |
soho_vid_btn.click(make_nasa_soho_videos,None,html_vid_nasa)
|
| 629 |
###### NOAA Images ##########
|