Spaces:
Sleeping
Sleeping
import gradio as gr | |
import subprocess | |
import threading | |
import time | |
# Define the URL and interval | |
url = 'https://baseline-btn5.onrender.com/' | |
interval = 13 * 60 # 13 minutes in seconds | |
subprocess_duration = 60 # Duration to run the subprocess in seconds (e.g., 60 seconds) | |
# Variables for subprocess and count | |
count = 0 | |
subprocess_process = None | |
def open_website(): | |
global subprocess_process, count | |
count += 1 | |
if subprocess_process: | |
subprocess_process.terminate() # Terminate the previous subprocess if it exists | |
# Start a new subprocess to open the website | |
subprocess_process = subprocess.Popen(["python", "-c", f"import webbrowser; webbrowser.open('{url}')"]) | |
# print(f"Website {url} opened. Count: {count}") | |
# Wait for the subprocess duration and then terminate it | |
time.sleep(subprocess_duration) | |
if subprocess_process: | |
subprocess_process.terminate() # Ensure subprocess is terminated after its run time | |
subprocess_process = None | |
def get_count(): | |
return count | |
def background_task(): | |
while True: | |
open_website() | |
time.sleep(interval) # Wait for the specified interval before opening the website again | |
# Start the background thread to manage website opening and subprocess termination | |
threading.Thread(target=background_task, daemon=True).start() | |
# Define the Gradio interface | |
def interface_function(): | |
return f"Website opened count: {get_count()}" | |
iface = gr.Interface(fn=interface_function, inputs=[], outputs="text") | |
if __name__ == "__main__": | |
iface.launch(debug=True) | |