Spaces:
Sleeping
Sleeping
dauduchieu commited on
Commit ·
1330f15
1
Parent(s): 82cf5fa
add auto update data at 2am
Browse files- app.py +19 -0
- requirements.txt +2 -0
app.py
CHANGED
|
@@ -8,11 +8,30 @@ from llm import llm_request
|
|
| 8 |
from fastapi import FastAPI
|
| 9 |
from fastapi.middleware.cors import CORSMiddleware
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
df = load_data()
|
| 12 |
print("df shape:")
|
| 13 |
print(df.shape)
|
| 14 |
print("-> Done")
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
app = FastAPI()
|
| 17 |
app.add_middleware(
|
| 18 |
CORSMiddleware,
|
|
|
|
| 8 |
from fastapi import FastAPI
|
| 9 |
from fastapi.middleware.cors import CORSMiddleware
|
| 10 |
|
| 11 |
+
from apscheduler.schedulers.background import BackgroundScheduler
|
| 12 |
+
from datetime import datetime
|
| 13 |
+
import pytz
|
| 14 |
+
import time
|
| 15 |
+
|
| 16 |
df = load_data()
|
| 17 |
print("df shape:")
|
| 18 |
print(df.shape)
|
| 19 |
print("-> Done")
|
| 20 |
|
| 21 |
+
def reload_data():
|
| 22 |
+
global df
|
| 23 |
+
print(f"[{datetime.now()}] Reloading data...", end="")
|
| 24 |
+
df = load_data()
|
| 25 |
+
print(f"Update: df_shape = {df.shape}")
|
| 26 |
+
|
| 27 |
+
scheduler = BackgroundScheduler()
|
| 28 |
+
vietnam_tz = pytz.timezone("Asia/Ho_Chi_Minh")
|
| 29 |
+
|
| 30 |
+
scheduler.add_job(reload_data, 'cron', hour=15, minute=50, timezone=vietnam_tz)
|
| 31 |
+
scheduler.add_job(reload_data, 'cron', hour=2, minute=0, timezone=vietnam_tz)
|
| 32 |
+
|
| 33 |
+
scheduler.start()
|
| 34 |
+
|
| 35 |
app = FastAPI()
|
| 36 |
app.add_middleware(
|
| 37 |
CORSMiddleware,
|
requirements.txt
CHANGED
|
@@ -19,3 +19,5 @@ typing_extensions==4.12.2
|
|
| 19 |
tzdata==2025.1
|
| 20 |
uvicorn==0.34.0
|
| 21 |
sentence_transformers
|
|
|
|
|
|
|
|
|
| 19 |
tzdata==2025.1
|
| 20 |
uvicorn==0.34.0
|
| 21 |
sentence_transformers
|
| 22 |
+
APScheduler==3.11.0
|
| 23 |
+
tzlocal==5.3.1
|