Spaces:
Running
Running
import gradio as gr | |
import requests | |
from datasets import load_dataset | |
#dataset = load_dataset("nlphuji/flickr30k", split="test[10:20]") | |
#print (dataset) | |
#headers = {"Authorization": f"Bearer {API_TOKEN}"} | |
API_URL1 = "/static-proxy?url=https%3A%2F%2Fdatasets-server.huggingface.co%2Fsplits%3Fdataset%3Dnlphuji%2Fflickr30k%26quot%3B%3C%2Fspan%3E%3C!-- HTML_TAG_END --> | |
def query1(): | |
response = requests.get(API_URL1) | |
#response = requests.get(API_URL1, headers=headers) | |
return response.json() | |
data = query1() | |
print (data) | |
def query2(fetch_url): | |
if fetch_url=="": | |
fetch_url = "nlphuji/flickr30k" | |
API_URL2 = f"/static-proxy?url=https%3A%2F%2Fdatasets-server.huggingface.co%2Frows%3Fdataset%3D%3Cspan class="hljs-subst">{fetch_url}&config=TEST&split=test&offset=150&length=10" | |
response = requests.get(API_URL2) | |
return response.json() | |
def find_fn(inp,out_json): | |
print (inp) | |
return(f'{out_json}{inp}') | |
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() | |
out_find = gr.Textbox() | |
find_btn.click(find_fn,[find_string,out_json],out_find) | |
fetch_btn.click(query2,data_set_url,out_json) | |
app.launch() |