Spaces:
Runtime error
Runtime error
elfsong
commited on
Commit
ยท
36e8169
1
Parent(s):
f123d7c
Add link
Browse files
app.py
CHANGED
@@ -19,9 +19,12 @@ def get_status(credentials, instance_name):
|
|
19 |
result = client.instances().list(project='nus-cisco-corp-lab-wp1', zone='asia-southeast1-c').execute()
|
20 |
for item in result['items']:
|
21 |
if item["name"] == instance_name:
|
22 |
-
|
|
|
|
|
|
|
23 |
status = True if item["status"] == "RUNNING" else False
|
24 |
-
return status
|
25 |
|
26 |
def activate_server(credentials, instance_name):
|
27 |
service = googleapiclient.discovery.build('compute', 'v1', credentials=credentials)
|
@@ -33,7 +36,7 @@ st.title("Lucky Reactor")
|
|
33 |
|
34 |
instance_name = "lucky-reactor"
|
35 |
credentials = auth()
|
36 |
-
status = get_status(credentials, instance_name)
|
37 |
|
38 |
st.image("cover.jpg", caption="Lucky Reactor is currently " + ("running ๐" if status else "sleeping ๐ด") + ".")
|
39 |
|
@@ -43,9 +46,7 @@ if not status:
|
|
43 |
submitted = st.form_submit_button("Ignite ๐")
|
44 |
|
45 |
if submitted and token == os.getenv("EASY_TOKEN"):
|
46 |
-
st.write("Lucky Reactor has been ignited. Please wait a few minutes (3~5) to preceed...")
|
47 |
-
status = get_status(credentials, instance_name)
|
48 |
-
st.write(status)
|
49 |
-
st.write("You can aceess Lucky Reactor from *[LINK]*.")
|
50 |
response = activate_server(credentials, instance_name)
|
51 |
-
|
|
|
|
19 |
result = client.instances().list(project='nus-cisco-corp-lab-wp1', zone='asia-southeast1-c').execute()
|
20 |
for item in result['items']:
|
21 |
if item["name"] == instance_name:
|
22 |
+
try:
|
23 |
+
ip_address = item['networkInterfaces'][0]['networkIP']
|
24 |
+
except Exception as e:
|
25 |
+
ip_address = None
|
26 |
status = True if item["status"] == "RUNNING" else False
|
27 |
+
return status, ip_address
|
28 |
|
29 |
def activate_server(credentials, instance_name):
|
30 |
service = googleapiclient.discovery.build('compute', 'v1', credentials=credentials)
|
|
|
36 |
|
37 |
instance_name = "lucky-reactor"
|
38 |
credentials = auth()
|
39 |
+
status, ip_address = get_status(credentials, instance_name)
|
40 |
|
41 |
st.image("cover.jpg", caption="Lucky Reactor is currently " + ("running ๐" if status else "sleeping ๐ด") + ".")
|
42 |
|
|
|
46 |
submitted = st.form_submit_button("Ignite ๐")
|
47 |
|
48 |
if submitted and token == os.getenv("EASY_TOKEN"):
|
49 |
+
st.write("Lucky Reactor has been ignited. Please wait a few minutes (3~5) to preceed...")
|
|
|
|
|
|
|
50 |
response = activate_server(credentials, instance_name)
|
51 |
+
else:
|
52 |
+
st.write(f"You can access Lucky Reactor via https://{ip_address}:7860")
|