Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -31,6 +31,12 @@ def activate_server(credentials, instance_name):
|
|
31 |
response = request.execute()
|
32 |
return response
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
st.title("Lucky Reactor Panel")
|
35 |
|
36 |
instance_name = "lucky-reactor"
|
@@ -40,7 +46,7 @@ status, ip_address = get_status(credentials, instance_name)
|
|
40 |
st.image("cover.jpg", caption="Lucky Reactor is currently " + ("running ๐" if status else "sleeping ๐ด") + ".")
|
41 |
|
42 |
if not status:
|
43 |
-
with st.form("
|
44 |
token = st.text_input("Token (FYI: The reactor costs USD $10 per hour to operate)")
|
45 |
submitted = st.form_submit_button("Ignite ๐")
|
46 |
|
@@ -48,4 +54,11 @@ if not status:
|
|
48 |
st.write("Lucky Reactor has been ignited. Please wait a few minutes (3~5) to preceed...")
|
49 |
response = activate_server(credentials, instance_name)
|
50 |
else:
|
51 |
-
st.write(f"You can access Lucky Reactor via http://{ip_address}:7860")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
response = request.execute()
|
32 |
return response
|
33 |
|
34 |
+
def deactivate_server(credentials, instance_name):
|
35 |
+
service = googleapiclient.discovery.build('compute', 'v1', credentials=credentials)
|
36 |
+
request = service.instances().stop(project='nus-cisco-corp-lab-wp1',zone='asia-southeast1-c',instance=instance_name, discardLocalSsd=False)
|
37 |
+
response = request.execute()
|
38 |
+
return response
|
39 |
+
|
40 |
st.title("Lucky Reactor Panel")
|
41 |
|
42 |
instance_name = "lucky-reactor"
|
|
|
46 |
st.image("cover.jpg", caption="Lucky Reactor is currently " + ("running ๐" if status else "sleeping ๐ด") + ".")
|
47 |
|
48 |
if not status:
|
49 |
+
with st.form("activate_form"):
|
50 |
token = st.text_input("Token (FYI: The reactor costs USD $10 per hour to operate)")
|
51 |
submitted = st.form_submit_button("Ignite ๐")
|
52 |
|
|
|
54 |
st.write("Lucky Reactor has been ignited. Please wait a few minutes (3~5) to preceed...")
|
55 |
response = activate_server(credentials, instance_name)
|
56 |
else:
|
57 |
+
st.write(f"You can access Lucky Reactor via http://{ip_address}:7860")
|
58 |
+
with st.form("deactivate_form"):
|
59 |
+
token = st.text_input("Token")
|
60 |
+
submitted = st.form_submit_button("Terminate ๐๏ธ")
|
61 |
+
|
62 |
+
if submitted and token == os.getenv("EASY_TOKEN"):
|
63 |
+
st.write("Lucky Reactor has been terminated.")
|
64 |
+
response = deactivate_server(credentials, instance_name)
|