Omnibus commited on
Commit
7748011
·
verified ·
1 Parent(s): 4507214

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -6
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  import requests
3
  import json
 
4
  main_directory = "https://services.swpc.noaa.gov/"
5
 
6
  html = """
@@ -72,8 +73,7 @@ def make_tree(url1="",url2="",url3="",url4=""):
72
 
73
  def get_images():
74
  html_out=f"<style>{css}</style><div class='img_box'>"
75
- get_url=f'{main_directory}images/'
76
-
77
  feed1 = requests.get(get_url)
78
  spl = feed1.text.split("href=")
79
  for line in spl:
@@ -83,19 +83,52 @@ def get_images():
83
  html_out+=f'<div class="img_class"><a href="{get_url}{spl2}" target="_blank">{get_url}{spl2}</a><br><img src={get_url}{spl2}></div>'
84
  else:
85
  print(spl2)
 
 
 
 
 
 
 
 
 
 
86
  html_out+="</div>"
87
  return html_out
88
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  def run():
90
  out=make_tree()
91
  im_html=get_images()
92
  return out, im_html
93
 
94
-
95
-
96
  with gr.Blocks() as app:
97
  with gr.Tab("Images"):
98
  html_im=gr.HTML()
 
 
 
99
  with gr.Tab("Raw"):
100
  with gr.Row():
101
  drop1=gr.Dropdown()
@@ -108,9 +141,10 @@ with gr.Blocks() as app:
108
 
109
  ###### Images ##########
110
 
 
 
111
 
112
  ####### Raw ############
113
- load_btn.click(load_json,[drop1,drop2,drop3,drop4],[html_raw,links])
114
  drop1.change(make_tree,drop1,[drop2])
115
  drop2.change(make_tree,[drop1,drop2],[drop3])
116
  drop3.change(make_tree,[drop1,drop2,drop3],[drop4])
 
1
  import gradio as gr
2
  import requests
3
  import json
4
+ from PIL import Image
5
  main_directory = "https://services.swpc.noaa.gov/"
6
 
7
  html = """
 
73
 
74
  def get_images():
75
  html_out=f"<style>{css}</style><div class='img_box'>"
76
+ get_url=f'{main_directory}images/geospace/'
 
77
  feed1 = requests.get(get_url)
78
  spl = feed1.text.split("href=")
79
  for line in spl:
 
83
  html_out+=f'<div class="img_class"><a href="{get_url}{spl2}" target="_blank">{get_url}{spl2}</a><br><img src={get_url}{spl2}></div>'
84
  else:
85
  print(spl2)
86
+ get_url2=f'{main_directory}images/'
87
+ feed2 = requests.get(get_url2)
88
+ spl = feed2.text.split("href=")
89
+ for line2 in spl:
90
+ spl2 = line2.split(">")[0].strip('""')
91
+ if spl2.endswith(".png") or spl2.endswith(".gif") or spl2.endswith(".jpg"):
92
+ print(spl2)
93
+ html_out+=f'<div class="img_class"><a href="{get_url2}{spl2}" target="_blank">{get_url2}{spl2}</a><br><img src={get_url2}{spl2}></div>'
94
+ else:
95
+ print(spl2)
96
  html_out+="</div>"
97
  return html_out
98
+
99
+ def make_animation():
100
+ html_out=f"<style>{css}</style><div class='img_box'>"
101
+ get_url=f'{main_directory}images/animations/'
102
+ feed1 = requests.get(get_url)
103
+ spl = feed1.text.split("href=")
104
+ for line in spl:
105
+ spl2 = line.split(">")[0].strip('""')
106
+ if spl2.endswith("/"):
107
+ feed2 = requests.get(get_url)
108
+ spl3 = feed2.text.split("href=")
109
+ for line2 in spl3:
110
+ spl3 = line2.split(">")[0].strip('""')
111
+ if spl3.endswith(".png") or spl2.endswith(".gif") or spl2.endswith(".jpg"):
112
+ gif_box.append(f'{get_url}{spl2}{spl3}')
113
+ '''
114
+ frames = [Image.open(image) for image in glob.glob(f"{frame_folder}/*.JPG")]
115
+ frame_one = frames[0]
116
+ frame_one.save("my_awesome.gif", format="GIF", append_images=frames,
117
+ save_all=True, duration=100, loop=0)
118
+ '''
119
+ return gif_box
120
+
121
  def run():
122
  out=make_tree()
123
  im_html=get_images()
124
  return out, im_html
125
 
 
 
126
  with gr.Blocks() as app:
127
  with gr.Tab("Images"):
128
  html_im=gr.HTML()
129
+ with gr.Tab("Animations"):
130
+ anim_btn=gr.Button()
131
+ anim_out=gr.JSON()
132
  with gr.Tab("Raw"):
133
  with gr.Row():
134
  drop1=gr.Dropdown()
 
141
 
142
  ###### Images ##########
143
 
144
+ load_btn.click(load_json,[drop1,drop2,drop3,drop4],[html_raw,links])
145
+ anim_btn.click(make_animatin,None,[anim_out])
146
 
147
  ####### Raw ############
 
148
  drop1.change(make_tree,drop1,[drop2])
149
  drop2.change(make_tree,[drop1,drop2],[drop3])
150
  drop3.change(make_tree,[drop1,drop2,drop3],[drop4])