Spaces:
Sleeping
Sleeping
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 = "https://datasets-server.huggingface.co/splits?dataset=nlphuji/flickr30k" | |
response = requests.get(API_URL1) | |
#response = requests.get(API_URL1, headers=headers) | |
return response.json() | |
data = query1() | |
print (data) | |
def query2(fetch_url,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=TEST&split=test&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_json=(query2("",offset=10,lenght=20) | |
for rows in out_json['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(query2,data_set_url,out_json) | |
app.launch() |