How to achieve a function that runs every 10 seconds

Hi,

Iā€™m trying to achieve a function that runs every 10 seconds with every
I highlighted what row of the code that I want to use every

this is my GUI:

##Gradio GUI###
with gr.Blocks(title = ā€˜IPBlockerā€™) as switches_ver:
gr.Markdown(ā€˜Welcome to IPBlockerā€™)
with gr.Row():
fg_names = [ā€˜DCDR Statusā€™,ā€˜TLV Statusā€™,ā€˜HFA Statusā€™, ā€˜KRML Statusā€™]
for name in fg_names:
gr.Textbox(value = threat_feed_check(name), label = name, interactive=False, every=10)
with gr.Tab(label = ā€˜IPBlockerā€™):
with gr.Row():
with gr.Column():
ips_to_block = gr.Textbox(label = ā€œIPsā€, lines = 10, placeholder=(ā€˜Please fill Ips to blockā€™))
block_btn = gr.Button(ā€˜Blockā€™)
with gr.Row():
ip_look_up_btn = gr.Button('Look for IP or URL: ')
look_up = gr.Textbox(show_label=False)
with gr.Row():
ip_removal_btn = gr.Button(ā€˜Remove IP:ā€™)
remove = gr.Textbox(show_label=False)

        with gr.Column():
            output_textbox = gr.Textbox(label = "Results", lines=10)
            with gr.Row():
                current_commit_stats = gr.Textbox(label = 'Current IP\s or URLs added to block:')
                forti_ips_stats = gr.Textbox(label = 'Total blocked IP\s on Fortigate: ')
                forti_urls_stats = gr.Textbox(label = 'Total URLs blocked on Fortigate')
            forti_total_stats = gr.Textbox(label = 'Total blocked IP\s and URLs on Fortigate')
            block_btn.click(fn=block_ip, inputs = ips_to_block, outputs = [output_textbox, current_commit_stats, forti_ips_stats, forti_urls_stats, forti_total_stats])
            ip_look_up_btn.click(fn=ip_look_up, inputs = look_up, outputs = look_up)
            ip_removal_btn.click(fn=ip_removal, inputs = remove, outputs = remove)

switches_ver.queue().launch()

My function:


def threat_feed_check(threat_feed):

    if threat_feed == 'DCDR Status':
        response = requests.get('https://192.168.1.1/api/v2/monitor/system/external-resource/entry-list?mkey=Domain_Blocker&vdom=root', headers=headers, verify=False)
        print('Trying')

        return response.json()['results']
        
    if threat_feed == 'TLV Status':
        response = requests.get('https://192.168.1.2/api/v2/monitor/system/external-resource/entry-list?mkey=Domain_Blocker&vdom=root', headers=headers, verify=False)
        
        return response.json()['results']
    if threat_feed == 'HFA Status':
        response = requests.get('https://192.168.1.3/api/v2/monitor/system/external-resource/entry-list?mkey=Domain_Blocker&vdom=root', headers=headers, verify=False)

        return response.json()['results']
        
    if threat_feed == 'KRML Status':
        response = requests.get('https://192.168.1.4/api/v2/monitor/system/external-resource/entry-list?mkey=Domain_Blocker&vdom=root', headers=headers, verify=False)
        
        return response.json()['results']

Any Idea why It doesnā€™t work?

Thank you!

Whatā€™s not working @LittleWing ?

Oh,
The function threat_feed_check doesnā€™t run every 10 seconds

Is it running approximately every 10 seconds or itā€™s not running repeatedly at all?

What version of gradio are you using?

Doesnā€™t run repeatedly - Only once when I run the script.
version: 3.19.1

The value of the textbox must be callable, so I think rewriting threat_feed_check to return a function should be work

def threat_feed_check(threat_feed):
    def inner():
      if threat_feed == 'DCDR Status':
          response = requests.get('https://192.168.1.1/api/v2/monitor/system/external-resource/entry-list?mkey=Domain_Blocker&vdom=root', headers=headers, verify=False)
          print('Trying')
  
          return response.json()['results']
          
      if threat_feed == 'TLV Status':
          response = requests.get('https://192.168.1.2/api/v2/monitor/system/external-resource/entry-list?mkey=Domain_Blocker&vdom=root', headers=headers, verify=False)
          
          return response.json()['results']
      if threat_feed == 'HFA Status':
          response = requests.get('https://192.168.1.3/api/v2/monitor/system/external-resource/entry-list?mkey=Domain_Blocker&vdom=root', headers=headers, verify=False)
  
          return response.json()['results']
          
      if threat_feed == 'KRML Status':
          response = requests.get('https://192.168.1.4/api/v2/monitor/system/external-resource/entry-list?mkey=Domain_Blocker&vdom=root', headers=headers, verify=False)
          
          return response.json()['results']
     return inner

The indentation got a bit messed up but hopefully you get what I mean.

Thank you.

I apologize for misunderstanding the docs, I know it says value must be callable, I was thinking that callable must mean just a function that the component will run every 10 seconds.

Its working as it should now.

I really appreciate your time helping me.

No need to apologize! Glad itā€™s working now