Omnibus commited on
Commit
288aecc
·
verified ·
1 Parent(s): 5191a45

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -16
app.py CHANGED
@@ -8,25 +8,26 @@ html = """
8
  PAGE_LINK
9
  </div>
10
  """
11
-
 
 
 
 
12
 
13
  def make_tree(url1="",url2="",url3="",url4=""):
14
  link_box=[]
15
  html_out=""
16
  get_url=f'{main_directory}{url1}{url2}{url3}{url4}'
17
  feed1 = requests.get(get_url)
18
- if get_url.endswith(".json"):
19
- return feed1.text, None
20
- else:
21
- spl = feed1.text.split("href=")
22
- for line in spl:
23
- spl2 = line.split(">")[0]
24
- print(spl2)
25
- if spl2.endswith('/"') or spl2.endswith('.json"'):
26
- fin=line.split(">")[0].strip('""')
27
- link_box.append(fin)
28
- #html_out=html_out+html.replace("PAGE_LINK",fin)
29
- return None, gr.update(choices=[l for l in link_box],interactive=True)
30
 
31
  def run():
32
  _,out=make_tree()
@@ -38,10 +39,12 @@ with gr.Blocks() as app:
38
  drop2=gr.Dropdown()
39
  drop3=gr.Dropdown()
40
  drop4=gr.Dropdown()
 
41
  links=gr.JSON()
42
  html_=gr.HTML()
43
- drop1.change(make_tree,drop1,[links,drop2])
44
- drop2.change(make_tree,[drop1,drop2],[links,drop3])
45
- drop3.change(make_tree,[drop1,drop2,drop3],[links,drop4])
 
46
  app.load(run,None,[drop1])
47
  app.launch()
 
8
  PAGE_LINK
9
  </div>
10
  """
11
+ def load_json(url1="",url2="",url3="",url4=""):
12
+ get_url=f'{main_directory}{url1}{url2}{url3}{url4}'
13
+ feed1 = requests.get(get_url)
14
+ if get_url.endswith(".json"):
15
+ return feed1.text
16
 
17
  def make_tree(url1="",url2="",url3="",url4=""):
18
  link_box=[]
19
  html_out=""
20
  get_url=f'{main_directory}{url1}{url2}{url3}{url4}'
21
  feed1 = requests.get(get_url)
22
+ spl = feed1.text.split("href=")
23
+ for line in spl:
24
+ spl2 = line.split(">")[0]
25
+ print(spl2)
26
+ if spl2.endswith('/"') or spl2.endswith('.json"'):
27
+ fin=line.split(">")[0].strip('""')
28
+ link_box.append(fin)
29
+ #html_out=html_out+html.replace("PAGE_LINK",fin)
30
+ return gr.update(choices=[l for l in link_box],interactive=True)
 
 
 
31
 
32
  def run():
33
  _,out=make_tree()
 
39
  drop2=gr.Dropdown()
40
  drop3=gr.Dropdown()
41
  drop4=gr.Dropdown()
42
+ load_btn=gr.Button("Load JSON")
43
  links=gr.JSON()
44
  html_=gr.HTML()
45
+ load_btn.click(load_json,[drop1,drop2,drop3,drop4],links)
46
+ drop1.change(make_tree,drop1,[drop2])
47
+ drop2.change(make_tree,[drop1,drop2],[drop3])
48
+ drop3.change(make_tree,[drop1,drop2,drop3],[drop4])
49
  app.load(run,None,[drop1])
50
  app.launch()