Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import threading
|
3 |
+
import requests
|
4 |
+
import time
|
5 |
+
|
6 |
+
def send_dummy_request(space_url):
|
7 |
+
try:
|
8 |
+
response = requests.get(space_url)
|
9 |
+
# Print the response status code (optional)
|
10 |
+
print(f"Response Status Code Of Wait: {response.status_code}")
|
11 |
+
except Exception as e:
|
12 |
+
print(f"Error: {e}")
|
13 |
+
|
14 |
+
def background_request(space_urls, interval_seconds):
|
15 |
+
try:
|
16 |
+
while True:
|
17 |
+
for space_url in space_urls:
|
18 |
+
send_dummy_request(space_url)
|
19 |
+
time.sleep(interval_seconds)
|
20 |
+
except KeyboardInterrupt:
|
21 |
+
print("Background script terminated by user.")
|
22 |
+
|
23 |
+
|
24 |
+
space_urls = [
|
25 |
+
# For Spaces
|
26 |
+
'https://huggingface.co/spaces/clone3/Wait',
|
27 |
+
'https://huggingface.co/spaces/clone3/NewSpace',
|
28 |
+
# For Self
|
29 |
+
]
|
30 |
+
|
31 |
+
# Set the interval for sending requests (in seconds)
|
32 |
+
interval_seconds = 7200 # 2 hours
|
33 |
+
|
34 |
+
# Start the background thread
|
35 |
+
background_thread = threading.Thread(target=background_request, args=(space_urls, interval_seconds))
|
36 |
+
background_thread.start()
|
37 |
+
|
38 |
+
# Gradio interface
|
39 |
+
def echo_text(text):
|
40 |
+
return f"You said: {text}"
|
41 |
+
|
42 |
+
iface = gr.Interface(fn=echo_text, inputs="text", outputs="text")
|
43 |
+
iface.launch()
|