radames commited on
Commit
1b35184
1 Parent(s): 6adeb37

enable sync every 24h

Browse files
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -20,9 +20,9 @@ import boto3
20
 
21
  from db import Database
22
 
23
- AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID')
24
- AWS_SECRET_KEY = os.getenv('AWS_SECRET_KEY')
25
- AWS_S3_BUCKET_NAME = os.getenv('AWS_S3_BUCKET_NAME')
26
 
27
 
28
  HF_TOKEN = os.environ.get("HF_TOKEN")
@@ -176,11 +176,13 @@ async def sync_data():
176
  "class": classifier
177
  })])
178
  db.commit()
179
-
180
- # print("Updating repository")
181
- # subprocess.Popen(
182
- # "git add . && git commit --amend -m 'update' && git push --force", cwd=DB_FOLDER, shell=True)
183
-
 
 
184
 
185
  app = FastAPI()
186
  app.add_middleware(
@@ -228,8 +230,8 @@ def read_root():
228
  return "Just a bot to sync data from diffusers gallery"
229
 
230
 
231
- # @app.on_event("startup")
232
- # @repeat_every(seconds=60 * 60 * 24, wait_first=True)
233
- # async def repeat_sync():
234
- # await sync_data()
235
- # return "Synced data to huggingface datasets"
 
20
 
21
  from db import Database
22
 
23
+ AWS_ACCESS_KEY_ID = os.getenv('MY_AWS_ACCESS_KEY_ID')
24
+ AWS_SECRET_KEY = os.getenv('MY_AWS_SECRET_KEY')
25
+ AWS_S3_BUCKET_NAME = os.getenv('MY_AWS_S3_BUCKET_NAME')
26
 
27
 
28
  HF_TOKEN = os.environ.get("HF_TOKEN")
 
176
  "class": classifier
177
  })])
178
  db.commit()
179
+
180
+ if(len(models) > 0):
181
+ print("Updating repository")
182
+ subprocess.Popen(
183
+ "git add . && git commit --amend -m 'update' && git push --force", cwd=DB_FOLDER, shell=True)
184
+ else:
185
+ print("No new models found")
186
 
187
  app = FastAPI()
188
  app.add_middleware(
 
230
  return "Just a bot to sync data from diffusers gallery"
231
 
232
 
233
+ @app.on_event("startup")
234
+ @repeat_every(seconds=60 * 60 * 24, wait_first=False)
235
+ async def repeat_sync():
236
+ await sync_data()
237
+ return "Synced data to huggingface datasets"