Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
-
import requests
|
3 |
import threading
|
|
|
4 |
import time
|
5 |
|
6 |
def send_dummy_request(space_url):
|
@@ -11,33 +11,27 @@ def send_dummy_request(space_url):
|
|
11 |
except Exception as e:
|
12 |
print(f"Error: {e}")
|
13 |
|
14 |
-
def
|
15 |
-
|
16 |
-
space_url = 'YOUR_SPACE_URL'
|
17 |
-
|
18 |
-
# Set the interval for sending requests (in seconds)
|
19 |
-
interval_seconds = 1800 # 30 minutes
|
20 |
-
|
21 |
-
# Define the Gradio interface components
|
22 |
-
iface = gr.Interface(
|
23 |
-
fn=send_dummy_request,
|
24 |
-
args=["space_url"],
|
25 |
-
inputs=gr.Textbox(text=space_url, label="Space URL"),
|
26 |
-
outputs=None,
|
27 |
-
live=True,
|
28 |
-
)
|
29 |
-
|
30 |
-
# Start a thread for periodic dummy requests
|
31 |
-
def periodic_requests():
|
32 |
while True:
|
33 |
send_dummy_request(space_url)
|
34 |
time.sleep(interval_seconds)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
-
|
37 |
-
|
|
|
38 |
|
39 |
-
|
40 |
-
|
|
|
41 |
|
42 |
-
|
43 |
-
|
|
|
1 |
import gradio as gr
|
|
|
2 |
import threading
|
3 |
+
import requests
|
4 |
import time
|
5 |
|
6 |
def send_dummy_request(space_url):
|
|
|
11 |
except Exception as e:
|
12 |
print(f"Error: {e}")
|
13 |
|
14 |
+
def background_request(space_url, interval_seconds):
|
15 |
+
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
while True:
|
17 |
send_dummy_request(space_url)
|
18 |
time.sleep(interval_seconds)
|
19 |
+
except KeyboardInterrupt:
|
20 |
+
print("Background script terminated by user.")
|
21 |
+
|
22 |
+
# Replace 'YOUR_SPACE_URL' with the actual URL of your deployed Hugging Face Space
|
23 |
+
space_url = 'YOUR_SPACE_URL'
|
24 |
+
|
25 |
+
# Set the interval for sending requests (in seconds)
|
26 |
+
interval_seconds = 1800 # 30 minutes
|
27 |
|
28 |
+
# Start the background thread
|
29 |
+
background_thread = threading.Thread(target=background_request, args=(space_url, interval_seconds))
|
30 |
+
background_thread.start()
|
31 |
|
32 |
+
# Gradio interface
|
33 |
+
def echo_text(text):
|
34 |
+
return f"You said: {text}"
|
35 |
|
36 |
+
iface = gr.Interface(fn=echo_text, inputs="text", outputs="text")
|
37 |
+
iface.launch()
|