Spaces:
Sleeping
Sleeping
Commit ·
805175a
1
Parent(s): d491cd7
Setup the Hugging face deployment
Browse files
.env
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
DATABASE_URL='postgresql://neondb_owner:npg_0ZThyfD5xJGw@ep-polished-base-ab35nufp.eu-west-2.aws.neon.tech/neondb?sslmode=require&channel_binding=require'
|
main.py
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
-
from
|
|
|
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
-
import os
|
| 5 |
|
| 6 |
-
#
|
| 7 |
load_dotenv()
|
| 8 |
|
| 9 |
-
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
)
|
| 17 |
|
| 18 |
-
@app.get("/")
|
| 19 |
-
def
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
from fastapi import FastAPI
|
| 3 |
+
from sqlalchemy import create_engine
|
| 4 |
+
from sqlalchemy.orm import sessionmaker
|
| 5 |
from dotenv import load_dotenv
|
|
|
|
| 6 |
|
| 7 |
+
# This will pick up the secret you saved in Hugging Face
|
| 8 |
load_dotenv()
|
| 9 |
|
| 10 |
+
DATABASE_URL = os.getenv("DATABASE_URL")
|
| 11 |
|
| 12 |
+
# Create the SQLAlchemy engine using the modern psycopg driver
|
| 13 |
+
engine = create_engine(DATABASE_URL)
|
| 14 |
+
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
| 15 |
+
|
| 16 |
+
app = FastAPI()
|
|
|
|
| 17 |
|
| 18 |
+
@app.get("/health")
|
| 19 |
+
def health_check():
|
| 20 |
+
# This checks if the URL was loaded correctly from the secrets
|
| 21 |
+
if DATABASE_URL:
|
| 22 |
+
return {"status": "Database URL is loaded"}
|
| 23 |
+
return {"status": "Error: DATABASE_URL not found"}
|