Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Commit
·
1ef69ae
1
Parent(s):
0b973e8
add dotenv support for environment variables and Hugging Face login
Browse files
main.py
CHANGED
|
@@ -17,7 +17,12 @@ from fastapi import FastAPI, HTTPException, Query
|
|
| 17 |
from fastapi.middleware.cors import CORSMiddleware
|
| 18 |
from pydantic import BaseModel
|
| 19 |
from transformers import AutoTokenizer
|
|
|
|
|
|
|
| 20 |
|
|
|
|
|
|
|
|
|
|
| 21 |
# Configuration constants
|
| 22 |
MODEL_NAME = "davanstrien/SmolLM2-360M-tldr-sft-2025-02-12_15-13"
|
| 23 |
EMBEDDING_MODEL = "nomic-ai/modernbert-embed-base"
|
|
@@ -73,7 +78,7 @@ app.add_middleware(
|
|
| 73 |
allow_origins=[
|
| 74 |
"https://*.hf.space", # Allow all Hugging Face Spaces
|
| 75 |
"https://*.huggingface.co", # Allow all Hugging Face domains
|
| 76 |
-
#
|
| 77 |
],
|
| 78 |
allow_credentials=True,
|
| 79 |
allow_methods=["*"],
|
|
@@ -142,6 +147,8 @@ def setup_database():
|
|
| 142 |
|
| 143 |
if latest_update:
|
| 144 |
logger.info(f"Filtering records newer than {latest_update}")
|
|
|
|
|
|
|
| 145 |
df = df.filter(pl.col("last_modified") > latest_update)
|
| 146 |
filtered_count = df.select(pl.len()).collect().item()
|
| 147 |
logger.info(f"Found {filtered_count} records to update after filtering")
|
|
|
|
| 17 |
from fastapi.middleware.cors import CORSMiddleware
|
| 18 |
from pydantic import BaseModel
|
| 19 |
from transformers import AutoTokenizer
|
| 20 |
+
from dotenv import load_dotenv
|
| 21 |
+
from huggingface_hub import login
|
| 22 |
|
| 23 |
+
load_dotenv(override=True)
|
| 24 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 25 |
+
login(token=HF_TOKEN)
|
| 26 |
# Configuration constants
|
| 27 |
MODEL_NAME = "davanstrien/SmolLM2-360M-tldr-sft-2025-02-12_15-13"
|
| 28 |
EMBEDDING_MODEL = "nomic-ai/modernbert-embed-base"
|
|
|
|
| 78 |
allow_origins=[
|
| 79 |
"https://*.hf.space", # Allow all Hugging Face Spaces
|
| 80 |
"https://*.huggingface.co", # Allow all Hugging Face domains
|
| 81 |
+
# "http://localhost:5500", # Allow localhost:5500 # TODO remove before prod
|
| 82 |
],
|
| 83 |
allow_credentials=True,
|
| 84 |
allow_methods=["*"],
|
|
|
|
| 147 |
|
| 148 |
if latest_update:
|
| 149 |
logger.info(f"Filtering records newer than {latest_update}")
|
| 150 |
+
# Ensure last_modified is datetime before comparison
|
| 151 |
+
df = df.with_columns(pl.col("last_modified").str.to_datetime())
|
| 152 |
df = df.filter(pl.col("last_modified") > latest_update)
|
| 153 |
filtered_count = df.select(pl.len()).collect().item()
|
| 154 |
logger.info(f"Found {filtered_count} records to update after filtering")
|