Spaces:
Running
Running
admin
commited on
Commit
•
301e30f
1
Parent(s):
dbbe120
fix restart studio
Browse files
app.py
CHANGED
@@ -125,16 +125,30 @@ def get_spaces(username: str):
|
|
125 |
def activate_space(url: str):
|
126 |
status = "running"
|
127 |
try:
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
if ".hf.space" in url
|
132 |
-
|
133 |
-
)
|
134 |
-
response.raise_for_status()
|
135 |
|
136 |
-
|
137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
|
139 |
except requests.exceptions.Timeout as e:
|
140 |
if ".hf.space" in url:
|
@@ -144,7 +158,13 @@ def activate_space(url: str):
|
|
144 |
return activate_space(url)
|
145 |
|
146 |
except requests.RequestException as e:
|
147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
|
149 |
except Exception as e:
|
150 |
status = f"{e}"
|
|
|
125 |
def activate_space(url: str):
|
126 |
status = "running"
|
127 |
try:
|
128 |
+
if ".hf.space" in url:
|
129 |
+
response = requests.get(url, timeout=TIMEOUT)
|
130 |
+
response.raise_for_status()
|
131 |
+
if "-keep-spaces-active.hf.space" in url:
|
132 |
+
status = start_monitor(url)
|
|
|
|
|
133 |
|
134 |
+
else:
|
135 |
+
response = requests.put(url, timeout=TIMEOUT)
|
136 |
+
response.raise_for_status()
|
137 |
+
print("Expired studio found, restarting...")
|
138 |
+
while (
|
139 |
+
requests.get(
|
140 |
+
url.replace("/start_expired", "/status"),
|
141 |
+
timeout=TIMEOUT,
|
142 |
+
).json()["Data"]["Status"]
|
143 |
+
== "ExpiredCreating"
|
144 |
+
):
|
145 |
+
requests.get(
|
146 |
+
url.replace("/api/v1/studio/", "/studios/").replace(
|
147 |
+
"/start_expired", ""
|
148 |
+
),
|
149 |
+
timeout=TIMEOUT,
|
150 |
+
)
|
151 |
+
time.sleep(5)
|
152 |
|
153 |
except requests.exceptions.Timeout as e:
|
154 |
if ".hf.space" in url:
|
|
|
158 |
return activate_space(url)
|
159 |
|
160 |
except requests.RequestException as e:
|
161 |
+
if (
|
162 |
+
"500 Server Error:" in f"{e}"
|
163 |
+
and response.json()["Message"] == "studio is not expired"
|
164 |
+
):
|
165 |
+
status = "running"
|
166 |
+
else:
|
167 |
+
status = f"{e}"
|
168 |
|
169 |
except Exception as e:
|
170 |
status = f"{e}"
|