Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,26 @@ import random
|
|
5 |
from PIL import Image
|
6 |
import os
|
7 |
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
# API Configuration
|
10 |
API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev"
|
@@ -68,4 +88,4 @@ if prompt_from_url:
|
|
68 |
mime="image/png"
|
69 |
)
|
70 |
else:
|
71 |
-
st.info("Add a 'text' parameter to the URL to generate an image. Example: ?text=astronaut
|
|
|
5 |
from PIL import Image
|
6 |
import os
|
7 |
import json
|
8 |
+
import time
|
9 |
+
|
10 |
+
# Restart mechanism: Check if the application has been running for more than 48 hours.
|
11 |
+
start_time_file = "start_time.txt"
|
12 |
+
if not os.path.exists(start_time_file):
|
13 |
+
# Create the file and write the current time (in seconds since epoch)
|
14 |
+
with open(start_time_file, "w") as f:
|
15 |
+
f.write(str(time.time()))
|
16 |
+
else:
|
17 |
+
try:
|
18 |
+
with open(start_time_file, "r") as f:
|
19 |
+
start_time = float(f.read())
|
20 |
+
# Check if more than 48 hours have passed
|
21 |
+
if time.time() - start_time > 48 * 3600:
|
22 |
+
st.write("Restarting the space after 48 hours of uptime...")
|
23 |
+
os._exit(0) # Force a restart of the space
|
24 |
+
except Exception as e:
|
25 |
+
# If there's an issue reading the file, reset the start time.
|
26 |
+
with open(start_time_file, "w") as f:
|
27 |
+
f.write(str(time.time()))
|
28 |
|
29 |
# API Configuration
|
30 |
API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev"
|
|
|
88 |
mime="image/png"
|
89 |
)
|
90 |
else:
|
91 |
+
st.info("Add a 'text' parameter to the URL to generate an image. Example: ?text=astronaut riding a horse")
|