Spaces:
Running on CPU Upgrade

osv5m commited on
Commit
bba9868
Β·
1 Parent(s): e46ce47
Files changed (2) hide show
  1. app.py +8 -60
  2. requirements.txt +1 -3
app.py CHANGED
@@ -14,17 +14,7 @@ import cartopy.feature as cfeature
14
  import matplotlib.pyplot as plt
15
  from math import radians, sin, cos, sqrt, asin, exp
16
  from collections import defaultdict
17
-
18
- import base64
19
- import os
20
- import pickle
21
- import time
22
- import json
23
-
24
- from googleapiclient.discovery import build
25
- from google_auth_oauthlib.flow import InstalledAppFlow
26
- from google.auth.transport.requests import Request
27
- from email.mime.text import MIMEText
28
 
29
  IMAGE_FOLDER = './select'
30
  CSV_FILE = './select.csv'
@@ -38,52 +28,6 @@ RULES = """# Plonk 🌍 🌎 🌏
38
  ### Click "start" to begin...
39
  """
40
 
41
- class GmailAPI(object):
42
- def __init__(self):
43
- self.scopes = ['https://www.googleapis.com/auth/gmail.compose']
44
- self.service = self.build_service()
45
-
46
- def build_service(self, ):
47
- creds = None
48
- if os.path.exists("token.json"):
49
- creds = Credentials.from_authorized_user_file("token.json", self.scopes)
50
-
51
- if not creds or not creds.valid:
52
- if creds and creds.expired and creds.refresh_token:
53
- creds.refresh(Request())
54
- else:
55
- json_file = json.loads(os.environ['json'])
56
- # save json
57
- with open('credentials.json', 'w') as f:
58
- json.dump(json_file, f)
59
- flow = InstalledAppFlow.from_client_secrets_file("credentials.json", self.scopes)
60
- creds = flow.run_local_server(port=0)
61
- os.remove('credentials.json')
62
-
63
- with open("token.json", "w") as token:
64
- token.write(creds.to_json())
65
-
66
- return build("gmail", "v1", credentials=creds)
67
-
68
- def __call__(self, text, subject=''):
69
- self.send_message(self.create_message(text, subject))
70
-
71
- def send_message(self, message, num_trials=10):
72
- for _ in range(num_trials):
73
- try:
74
- self.service.users().messages().send(userId="me", body=message).execute()
75
- except Exception as e:
76
- print('An error occurred at send_message: %s' % e)
77
- time.sleep(60)
78
-
79
- def create_message(self, message_text, subject):
80
- message = MIMEText(message_text)
81
- message['to'] = "[email protected]"
82
- message['from'] = "[email protected]"
83
- message['subject'] = subject
84
- raw_message = base64.urlsafe_b64encode(message.as_string().encode("utf-8"))
85
- return {'raw': raw_message.decode("utf-8")}
86
-
87
  def haversine(lat1, lon1, lat2, lon2):
88
  if (lat1 is None) or (lon1 is None) or (lat2 is None) or (lon2 is None):
89
  return 0
@@ -250,12 +194,16 @@ class Engine(object):
250
  with open(join(self.cache_path, 'full.txt'), 'w') as f:
251
  print(f"{final_results}" + '\n Times: ' + times, file=f)
252
 
253
- text = f"{final_results}" + '\n Times: ' + times
254
- cache_uuid = os.path.split(self.cache_path)[1]
255
- self.gmail(text, subject=f'Plonk Results [{cache_uuid}]')
 
 
256
 
257
 
258
  if __name__ == "__main__":
 
 
259
  import gradio as gr
260
  def click(state, evt: gr.SelectData):
261
  if state['clicked']:
 
14
  import matplotlib.pyplot as plt
15
  from math import radians, sin, cos, sqrt, asin, exp
16
  from collections import defaultdict
17
+ import wandb
 
 
 
 
 
 
 
 
 
 
18
 
19
  IMAGE_FOLDER = './select'
20
  CSV_FILE = './select.csv'
 
28
  ### Click "start" to begin...
29
  """
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  def haversine(lat1, lon1, lat2, lon2):
32
  if (lat1 is None) or (lon1 is None) or (lat2 is None) or (lon2 is None):
33
  return 0
 
194
  with open(join(self.cache_path, 'full.txt'), 'w') as f:
195
  print(f"{final_results}" + '\n Times: ' + times, file=f)
196
 
197
+ wandb.init(project="plonk")
198
+ artifact = wandb.Artifact('results', type='results')
199
+ artifact.add_file(fname)
200
+ wandb.log_artifact(artifact)
201
+ wandb.finish()
202
 
203
 
204
  if __name__ == "__main__":
205
+ # login with the key from secret
206
+ wandb.login()
207
  import gradio as gr
208
  def click(state, evt: gr.SelectData):
209
  if state['clicked']:
requirements.txt CHANGED
@@ -2,6 +2,4 @@ matplotlib==3.7.1
2
  pandas==2.0.1
3
  reverse_geocoder==1.5.1
4
  cartopy==0.22.0
5
- google-api-python-client
6
- google-auth-httplib2
7
- google-auth-oauthlib
 
2
  pandas==2.0.1
3
  reverse_geocoder==1.5.1
4
  cartopy==0.22.0
5
+ wandb==0.15.4