File size: 3,447 Bytes
d714d3d
8fa564a
f894099
60ed47f
49687e4
 
ed88b70
 
49687e4
8d217ca
9265cc1
 
 
 
8d217ca
36b3c9a
62a99f6
 
36b3c9a
c458717
8512e9b
 
62a99f6
 
8e0ab44
62a99f6
8512e9b
f894099
 
3c99043
d714d3d
 
384f0cb
 
3c99043
f894099
60ed47f
7f431fa
c1d30cd
 
4ec3536
f894099
746d0e8
c1e08f5
 
a8a0883
838a98c
813a644
 
1453434
79687a9
eb75b14
746d0e8
eb75b14
 
 
 
746d0e8
eb75b14
746d0e8
eb75b14
746d0e8
 
f6669c0
09974cb
 
 
 
 
 
 
 
 
 
 
 
 
1f375b6
ef02a4a
36b3c9a
ef02a4a
36b3c9a
8512e9b
 
 
36b3c9a
ef02a4a
09974cb
 
 
 
 
746d0e8
ef02a4a
 
9bf98ce
2322049
 
a8a0883
36b3c9a
ef02a4a
09974cb
 
8512e9b
09974cb
 
 
746d0e8
8512e9b
d714d3d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import gradio as gr
import pandas as pd 
import requests
import json
from datasets import load_dataset

#dataset = load_dataset("nlphuji/flickr30k", split="test[10:20]")
#print (dataset)

#headers = {"Authorization": f"Bearer {API_TOKEN}"}
def query1(fetch_url):
    if fetch_url=="":
        fetch_url = "nlphuji/flickr30k"    
    API_URL1 = f"https://datasets-server.huggingface.co/splits?dataset={fetch_url}"
    response = requests.get(API_URL1)
    json_obj=response.json()

    drop_box = []
    for obj in json_obj:
        print (obj)
        out_config = obj[0]
        out_split = obj[1]
        print (out_config)
        print (out_split)
        drop_box.append(obj[0])
    #df = pd.DataFrame.from_dict(json_obj)        
    return json_obj


def query2(fetch_url,config="TEST",split="test",offset=0,length=10):
    if fetch_url=="":
        fetch_url = "nlphuji/flickr30k"
    #offset=0
    #length=10
    API_URL2 = f"https://datasets-server.huggingface.co/rows?dataset={fetch_url}&config={config}&split={split}&offset={offset}&length={length}"
    response = requests.get(API_URL2)
    dictionary=response.json()
    print (len(dictionary))
    for key in dictionary:
        print (key)
    return dictionary

def find_fn(lvl_1,lvl_2,fetch_url,config="TEST",split="test",offset=0,length=10):
    #print(out_json['rows'])
    #print (inp)
    img_list=[]
    out_json=query2(fetch_url,config,split,offset=10,length=20)
    lvl_1=lvl_1.strip("[]")

    lvl_2=lvl_2.strip('""').strip("''")
    #print(inp)
    cnt_lvl = ""
    if lvl_2 != "":
        ea_lvl_len = len(lvl_2)
        print (ea_lvl_len)
        for ea_lvl in lvl_2:
            cnt_lvl = f'{cnt_lvl}[{ea_lvl}]'
        for ea in out_json[f"{lvl_1}"]:
            cnt_lvl=cnt_lvl.strip("[]")
            #img_ea = ea['row']['image']['src']
            img_list.append(ea[f"{cnt_lvl}"])
    if lvl_2 == "":
        img_list.append(out_json[lvl_1])
    return img_list


def upd_drop(inp1,fetch_url,config="TEST",split="test",offset=0,length=10):

    #def upd_drop(inp1,inp2,inp3,inp4,inp5,fetch_url,config="TEST",split="test",offset=0,length=10):
    out_json=query2(fetch_url,config,split,offset=10,length=20)
    
    for ea in out_json[inp1]:
        out = [inp1]
        
        img_list.append(out_json[ea])    
    return gr.update(choices=[c for c in img_list])

with gr.Blocks() as app:
    with gr.Row():
        data_set_url=gr.Textbox(label="Dataset (repo/name)")
        fetch_btn=gr.Button()
    with gr.Row():
        config_set=gr.Textbox(label="Config")
        split_set=gr.Textbox(label="Split")
        #config_drop = gr.Dropdown(label="Config/Split", choices=[])
        view_data=gr.Button(label="View")
    with gr.Row():
        lvl_1=gr.Dropdown("lvl_1")
        lvl_2=gr.Dropdown("lvl_2")
        lvl_3=gr.Dropdown("lvl_3")
        lvl_4=gr.Dropdown("lvl_4")
        lvl_5=gr.Dropdown("lvl_5")
        
        find_btn=gr.Button("Search")
    with gr.Row():
        with gr.Column(scale=1):
            out_json = gr.JSON()
        with gr.Column(scale=3):
            out_find = gr.JSON()
            out_gal = gr.Gallery()


    lvl_1.change(upd_drop,[lvl_1,data_set_url,config_set,split_set],lvl_2)
    view_data.click(query2,[data_set_url,config_set,split_set],[out_find])
    
    
    
    find_btn.click(find_fn,[lvl_1,lvl_2,data_set_url,config_set,split_set],[out_find])
    fetch_btn.click(query1,data_set_url,out_json)
app.launch()