Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -42,9 +42,9 @@ def get_server(credentials, instance_name):
|
|
42 |
response = request.execute()
|
43 |
return response
|
44 |
|
45 |
-
def schedule_server(credentials, instance_name):
|
46 |
service = googleapiclient.discovery.build('compute', 'v1', credentials=credentials)
|
47 |
-
request = service.instances().setScheduling(project='nus-cisco-corp-lab-wp1', zone='asia-southeast1-c', instance=instance_name, body={"automaticRestart": False,"maxRunDuration": {"seconds":
|
48 |
response = request.execute()
|
49 |
return response
|
50 |
|
@@ -79,11 +79,12 @@ st.image("cover.jpg", caption="Lucky Reactor is currently " + ("running 🚀" if
|
|
79 |
if status == 'TERMINATED':
|
80 |
with st.form("activate_form"):
|
81 |
token = st.text_input("Token (FYI: The reactor costs USD $10 per hour to operate)")
|
|
|
82 |
submitted = st.form_submit_button("Ignite 🚀")
|
83 |
|
84 |
if submitted and token == os.getenv("EASY_TOKEN"):
|
85 |
st.write("Lucky Reactor has been ignited. Please wait a few minutes (3~5) to preceed...")
|
86 |
-
response = schedule_server(credentials, instance_name)
|
87 |
response = activate_server(credentials, instance_name)
|
88 |
elif status == 'RUNNING':
|
89 |
st.write(f"You can access Lucky Reactor via http://{ip_address}:7860")
|
|
|
42 |
response = request.execute()
|
43 |
return response
|
44 |
|
45 |
+
def schedule_server(credentials, instance_name, running_time):
|
46 |
service = googleapiclient.discovery.build('compute', 'v1', credentials=credentials)
|
47 |
+
request = service.instances().setScheduling(project='nus-cisco-corp-lab-wp1', zone='asia-southeast1-c', instance=instance_name, body={"automaticRestart": False,"maxRunDuration": {"seconds": running_time*3600}})
|
48 |
response = request.execute()
|
49 |
return response
|
50 |
|
|
|
79 |
if status == 'TERMINATED':
|
80 |
with st.form("activate_form"):
|
81 |
token = st.text_input("Token (FYI: The reactor costs USD $10 per hour to operate)")
|
82 |
+
running_time = st.select_slider("Running Hours", options=[1,2,3,4,5,6])
|
83 |
submitted = st.form_submit_button("Ignite 🚀")
|
84 |
|
85 |
if submitted and token == os.getenv("EASY_TOKEN"):
|
86 |
st.write("Lucky Reactor has been ignited. Please wait a few minutes (3~5) to preceed...")
|
87 |
+
response = schedule_server(credentials, instance_name, running_time)
|
88 |
response = activate_server(credentials, instance_name)
|
89 |
elif status == 'RUNNING':
|
90 |
st.write(f"You can access Lucky Reactor via http://{ip_address}:7860")
|