Omnibus commited on
Commit
bd24d05
·
verified ·
1 Parent(s): 6e5e3c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -20
app.py CHANGED
@@ -8,14 +8,37 @@ html = """
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
  print(f'{get_url}')
14
- get_url=get_url.split(".json")[0]+".json"
 
15
  if get_url.endswith('.json'):
16
  feed1 = requests.get(get_url)
17
- return feed1.text
18
- return None
 
 
 
 
 
 
19
  def make_tree(url1="",url2="",url3="",url4=""):
20
  link_box=[]
21
  html_out=""
@@ -34,22 +57,7 @@ def make_tree(url1="",url2="",url3="",url4=""):
34
  return gr.update(choices=[l for l in link_box],interactive=True)
35
  else:
36
  return None
37
- css="""
38
- .img_box{
39
- display: flex;
40
- flex-direction: column;
41
- flex-wrap: wrap;
42
- height: 20000px;
43
- }
44
- .img_class{
45
- background: #ffffff;
46
- max-width: 48%;
47
- font-family: monospace;
48
- border-top: #9300ff;
49
- border-style: inset;
50
- margin-top: 5px;
51
- }
52
- """
53
  def get_images():
54
  html_out=f"<style>{css}</style><div class='img_box'>"
55
  get_url=f'{main_directory}images/'
@@ -89,7 +97,7 @@ with gr.Blocks() as app:
89
 
90
 
91
  ####### Raw ############
92
- load_btn.click(load_json,[drop1,drop2,drop3,drop4],links)
93
  drop1.change(make_tree,drop1,[drop2])
94
  drop2.change(make_tree,[drop1,drop2],[drop3])
95
  drop3.change(make_tree,[drop1,drop2,drop3],[drop4])
 
8
  PAGE_LINK
9
  </div>
10
  """
11
+ css="""
12
+ .img_box{
13
+ display: flex;
14
+ flex-direction: column;
15
+ flex-wrap: wrap;
16
+ height: 20000px;
17
+ }
18
+ .img_class{
19
+ background: #ffffff;
20
+ max-width: 48%;
21
+ font-family: monospace;
22
+ border-top: #9300ff;
23
+ border-style: inset;
24
+ margin-top: 5px;
25
+ }
26
+ """
27
  def load_json(url1="",url2="",url3="",url4=""):
28
  get_url=f'{main_directory}{url1}{url2}{url3}{url4}'
29
  print(f'{get_url}')
30
+ get_url=get_url.split("None")[0]
31
+
32
  if get_url.endswith('.json'):
33
  feed1 = requests.get(get_url)
34
+ return None, feed1.text
35
+ elif get_url.endswith(".png") or get_url.endswith(".gif") or get_url.endswith(".jpg"):
36
+ html_out=f"<style>{css}</style><div>"
37
+ html_out+=f'<div class="img_class"><a href="{get_url}" target="_blank">{get_url}</a><br><img src={get_url}></div></div>'
38
+
39
+ return html_out, None
40
+ return None,None
41
+
42
  def make_tree(url1="",url2="",url3="",url4=""):
43
  link_box=[]
44
  html_out=""
 
57
  return gr.update(choices=[l for l in link_box],interactive=True)
58
  else:
59
  return None
60
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  def get_images():
62
  html_out=f"<style>{css}</style><div class='img_box'>"
63
  get_url=f'{main_directory}images/'
 
97
 
98
 
99
  ####### Raw ############
100
+ load_btn.click(load_json,[drop1,drop2,drop3,drop4],[html_im,links])
101
  drop1.change(make_tree,drop1,[drop2])
102
  drop2.change(make_tree,[drop1,drop2],[drop3])
103
  drop3.change(make_tree,[drop1,drop2,drop3],[drop4])