EzekielMW commited on
Commit
71128e8
·
verified ·
1 Parent(s): 0d036ba

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import time
4
+
5
+ st.title("Heartbeat Script to Keep Spaces Awake")
6
+
7
+ # URLs of the target Space and itself
8
+ target_space_url = "https://EzekielMW-test3.hf.space/"
9
+ self_space_url = "https://EzekielMW-activateTest3.hf.space/"
10
+
11
+ # Define the interval (in seconds) - 3 hours
12
+ interval = 3 * 60 * 60
13
+
14
+ st.write(f"Sending requests every 3 hours to: {target_space_url} and {self_space_url}")
15
+
16
+ while True:
17
+ try:
18
+ # Send a GET request to the root of the target Space
19
+ target_response = requests.get(target_space_url)
20
+ st.write(f"Request sent to target! Status code: {target_response.status_code}")
21
+
22
+ # Send a GET request to itself
23
+ self_response = requests.get(self_space_url)
24
+ st.write(f"Request sent to self! Status code: {self_response.status_code}")
25
+
26
+ except Exception as e:
27
+ st.write(f"An error occurred: {e}")
28
+
29
+ # Sleep for the interval (3 hours)
30
+ time.sleep(interval)