Spaces:
Runtime error
Runtime error
| import os | |
| import streamlit as st | |
| import googleapiclient.discovery | |
| from google.oauth2 import service_account | |
| def auth(): | |
| with open("/tmp/token.json", "w") as token_f: | |
| google_key = os.getenv("GOOGLE_KEY") | |
| token_f.write(google_key) | |
| credentials = service_account.Credentials.from_service_account_file('/tmp/token.json') | |
| return credentials | |
| def get_status(credentials): | |
| status = False | |
| client = googleapiclient.discovery.build('compute', 'v1', credentials=credentials) | |
| result = client.instances().list(project='nus-cisco-corp-lab-wp1', zone='asia-southeast1-b').execute() | |
| for item in result['items']: | |
| if item["name"] == "venus": | |
| status = True if item["status"] == "RUNNING" else False | |
| return status | |
| def activate_server(): | |
| return True | |
| st.title("Lucky Reactor") | |
| credentials = auth() | |
| status = get_status(credentials) | |
| st.image("cover.jpg", caption="Reactor is currently " + "running ๐" if status else "sleeping ๐ด" + ".") | |
| if not status: | |
| if st.button("Ignite"): | |
| st.write("Here you go: [LINK]") |