Spaces:
Sleeping
Sleeping
File size: 1,593 Bytes
d714d3d f894099 60ed47f 49687e4 ed88b70 49687e4 8d217ca f894099 384f0cb 8d217ca f894099 3c99043 d714d3d 384f0cb 3c99043 f894099 60ed47f 4ec3536 f894099 ef02a4a c1e08f5 a8a0883 c1e08f5 a8a0883 1f375b6 ef02a4a a8a0883 ef02a4a a8a0883 3c99043 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 |
import gradio as gr
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():
API_URL1 = "/static-proxy?url=https%3A%2F%2Fdatasets-server.huggingface.co%2Fsplits%3Fdataset%3Dnlphuji%2Fflickr30k%26quot%3B%3C%2Fspan%3E
response = requests.get(API_URL1)
#response = requests.get(API_URL1, headers=headers)
return response.json()
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"/static-proxy?url=https%3A%2F%2Fdatasets-server.huggingface.co%2Frows%3Fdataset%3D%3Cspan class="hljs-subst">{fetch_url}&config={config}&split={split}&offset={offset}&length={length}"
response = requests.get(API_URL2)
dictionary=response.json()
return dictionary
def find_fn(inp,out_json):
#print(out_json['rows'])
#print (inp)
img_list=[]
out_json1=query2("",offset=10,length=20)
for rows in out_json1['rows']:
img_ea = rows['row']['image']['src']
img_list.append(img_ea)
return img_list,img_list
with gr.Blocks() as app:
with gr.Row():
data_set_url=gr.Textbox()
fetch_btn=gr.Button()
with gr.Row():
find_string=gr.Textbox()
find_btn=gr.Button("Search")
with gr.Row():
out_json = gr.JSON()
with gr.Column():
out_gal = gr.Gallery()
out_find = gr.JSON()
find_btn.click(find_fn,[find_string,out_json],[out_find,out_gal])
fetch_btn.click(query1,data_set_url,out_json)
app.launch() |