Spaces:
Runtime error
Runtime error
Commit
·
7098224
1
Parent(s):
9a6e4f2
feat: Add Hugging Face Hub integration for uploading database file
Browse files
main.py
CHANGED
@@ -12,12 +12,15 @@ from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
|
12 |
from apscheduler.triggers.cron import CronTrigger
|
13 |
from cashews import NOT_NONE, cache
|
14 |
from fastapi import FastAPI, HTTPException, Query
|
|
|
15 |
from pandas import Timestamp
|
16 |
from pydantic import BaseModel
|
17 |
from starlette.responses import RedirectResponse
|
18 |
|
19 |
from data_loader import refresh_data
|
20 |
|
|
|
|
|
21 |
UPDATE_SCHEDULE = {"hour": os.getenv("UPDATE_INTERVAL_HOURS", "*/6")}
|
22 |
|
23 |
cache.setup("mem://?check_interval=10&size=10000")
|
@@ -147,6 +150,18 @@ async def update_database():
|
|
147 |
finally:
|
148 |
conn.close()
|
149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
|
151 |
@asynccontextmanager
|
152 |
async def lifespan(app: FastAPI):
|
|
|
12 |
from apscheduler.triggers.cron import CronTrigger
|
13 |
from cashews import NOT_NONE, cache
|
14 |
from fastapi import FastAPI, HTTPException, Query
|
15 |
+
from huggingface_hub import login, upload_file
|
16 |
from pandas import Timestamp
|
17 |
from pydantic import BaseModel
|
18 |
from starlette.responses import RedirectResponse
|
19 |
|
20 |
from data_loader import refresh_data
|
21 |
|
22 |
+
login(token=os.getenv("HF_TOKEN"))
|
23 |
+
|
24 |
UPDATE_SCHEDULE = {"hour": os.getenv("UPDATE_INTERVAL_HOURS", "*/6")}
|
25 |
|
26 |
cache.setup("mem://?check_interval=10&size=10000")
|
|
|
150 |
finally:
|
151 |
conn.close()
|
152 |
|
153 |
+
# Upload the database file to Hugging Face Hub
|
154 |
+
try:
|
155 |
+
upload_file(
|
156 |
+
path_or_fileobj="datasets.db",
|
157 |
+
path_in_repo="datasets.db",
|
158 |
+
repo_id="librarian-bots/column-db",
|
159 |
+
repo_type="dataset",
|
160 |
+
)
|
161 |
+
logger.info("Database file uploaded to Hugging Face Hub successfully")
|
162 |
+
except Exception as e:
|
163 |
+
logger.error(f"Error uploading database file to Hugging Face Hub: {str(e)}")
|
164 |
+
|
165 |
|
166 |
@asynccontextmanager
|
167 |
async def lifespan(app: FastAPI):
|