Spaces:
Sleeping
Sleeping
import requests | |
import time | |
import threading | |
import gradio as gr | |
# Define the URL of the website you want to keep active | |
url = "https://baseline-btn5.onrender.com/" | |
# Define the interval in seconds (5 minutes to ensure it's active before 6 minutes) | |
interval = 5 * 60 | |
# Variable to keep track of request counts | |
request_count = 0 | |
def keep_site_active(): | |
global request_count | |
while True: | |
try: | |
# Send a GET request to the website | |
response = requests.get(url) | |
# Check if the request was successful (status code 200) | |
if response.status_code == 200: | |
# print(f"Successfully accessed {url} - Status Code: {response.status_code}") | |
request_count += 1 | |
else: | |
print(f"Failed to access {url} - Status Code: {response.status_code}") | |
except requests.RequestException as e: | |
print(f"An error occurred: {e}") | |
# Wait for the specified interval before making the next request | |
time.sleep(interval) | |
def get_request_count(): | |
return request_count | |
def main(): | |
# Start the site-keeping thread | |
threading.Thread(target=keep_site_active, daemon=True).start() | |
# Define the Gradio interface | |
with gr.Blocks() as demo: | |
gr.Markdown("# Website Request Tracker") | |
count_button = gr.Button("Get Request Count") | |
count_display = gr.Textbox(label="Number of Successful Requests") | |
count_button.click(fn=get_request_count, outputs=count_display) | |
demo.launch() | |
if __name__ == "__main__": | |
main() | |