How to achieve a function that runs every 10 seconds
Hi,I’m trying to achieve a function that runs every 10 seconds witheveryI highlighted what row of the code that I want to useeverythis is my GUI:##GradioGUI###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!
2023-03-01T18:30:43Z
What’s not working@LittleWing?
2023-03-01T18:49:39Z
Oh,The functionthreat_feed_checkdoesn’t run every 10 seconds
2023-03-01T19:16:26Z
Is it running approximately every 10 seconds or it’s not running repeatedly at all?What version of gradio are you using?
2023-03-01T19:18:45Z
Doesn’t run repeatedly - Only once when I run the script.version: 3.19.1
2023-03-01T19:43:57Z
LittleWing:gr.Textbox(value = threat_feed_check(name), label = name, interactive=False, every=10)The value of the textbox must be callable, so I think rewritingthreat_feed_checkto return a function should be workdef 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 innerThe indentation got a bit messed up but hopefully you get what I mean.
2023-03-01T20:05:17Z
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.
2023-03-01T20:28:02Z
No need to apologize! Glad it’s working now