Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import requests | |
| import time | |
| st.title("Heartbeat Script to Keep Spaces Awake") | |
| # URLs of the target Space and itself | |
| target_space_url = "https://EzekielMW-test3.hf.space/" | |
| self_space_url = "https://EzekielMW-activateTest3.hf.space/" | |
| # Define the interval (in seconds) - 3 hours | |
| interval = 3 * 60 * 60 | |
| st.write(f"Sending requests every 3 hours to: {target_space_url} and {self_space_url}") | |
| while True: | |
| try: | |
| # Send a GET request to the root of the target Space | |
| target_response = requests.get(target_space_url) | |
| st.write(f"Request sent to target! Status code: {target_response.status_code}") | |
| # Send a GET request to itself | |
| self_response = requests.get(self_space_url) | |
| st.write(f"Request sent to self! Status code: {self_response.status_code}") | |
| except Exception as e: | |
| st.write(f"An error occurred: {e}") | |
| # Sleep for the interval (3 hours) | |
| time.sleep(interval) | |