import requests import gradio as gr import json #132942 def get_api(inp,call,val,tot): if not tot: r = requests.get(f'{inp}?{call}={val}') new_data=r.text print (new_data) #new_dict = json.loads(new_data) return (new_data) else: out_box=[] data="" for i in range(int(val)): try: r = requests.get(f'{inp}?{call}={int(val)-i}') new_data=r.text new_dict = json.loads(new_data) #print (new_dict) if "2024" in new_dict["data"]["member_since"]: #print(new_dict) out_box.append(new_dict) except Exception as e: print (f"{i} - {e}") pass yield (out_box) with gr.Blocks() as app: with gr.Group(): with gr.Row(): with gr.Column(scale=3): api_url=gr.Textbox(label="API URL") with gr.Column(scale=2): with gr.Row(): api_call=gr.Textbox(label="API CALL") api_val=gr.Textbox(label="VALUE") with gr.Column(scale=1): val_tot=gr.Checkbox(label="Count", value=False) with gr.Row(): btn=gr.Button("Search") stop_btn=gr.Button("Stop") outp=gr.JSON() go_btn = btn.click(get_api,[api_url,api_call,api_val,val_tot],outp) stop_btn.click(None,None,None,cancels=[go_btn]) app.launch()