forked from karpathy/reader3
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.py
More file actions
54 lines (41 loc) · 1.63 KB
/
Copy pathserver.py
File metadata and controls
54 lines (41 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""FastAPI server for the EPUB reader and AI-assisted annotation features."""
import os
from pathlib import Path
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
BASE_DIR = Path(__file__).resolve().parent
def load_env():
"""Load environment variables from .env file."""
env_path = BASE_DIR / ".env"
if env_path.exists():
print("Loading .env file...")
with open(env_path, encoding="utf-8") as f:
for line in f:
line = line.strip()
if line and not line.startswith("#") and "=" in line:
key, value = line.split("=", 1)
os.environ[key.strip()] = value.strip()
print(f"✓ Loaded Ollama endpoint: {os.getenv('OLLAMA_BASE_URL', 'Not set')}")
else:
print("⚠ Warning: .env file not found. AI features will not work.")
load_env()
app = FastAPI()
app.mount("/static", StaticFiles(directory=str(BASE_DIR / "static")), name="static")
# Register routers
from routers.library import router as library_router
from routers.highlights import router as highlights_router
from routers.ai import router as ai_router
from routers.settings import router as settings_router
app.include_router(library_router)
app.include_router(highlights_router)
app.include_router(ai_router)
app.include_router(settings_router)
if __name__ == "__main__":
import uvicorn
host = os.getenv("READER_HOST", "0.0.0.0")
port = int(os.getenv("READER_PORT", "8123"))
print(
f"Starting server at http://{host}:{port} "
"(accessible externally if firewall/NAT allow)"
)
uvicorn.run(app, host=host, port=port)