-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
81 lines (69 loc) · 3.04 KB
/
main.py
File metadata and controls
81 lines (69 loc) · 3.04 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse
import os
import uvicorn
from api import documents, connections, insights, podcast, search, individual_insights, youtube
from config import settings
# Create necessary directories
os.makedirs('storage/pdfs', exist_ok=True)
os.makedirs('storage/outlines', exist_ok=True)
os.makedirs('storage/audio', exist_ok=True)
# Create FastAPI app
app = FastAPI(
title="Document Insight & Engagement System",
description="Adobe Hackathon 2025 - Grand Finale",
version="1.0.0"
)
# Configure CORS
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Mount static files for serving PDFs and audio
app.mount("/static/pdfs", StaticFiles(directory="storage/pdfs"), name="pdfs")
app.mount("/static/audio", StaticFiles(directory="storage/audio"), name="audio")
# Include API routers
app.include_router(documents.router, prefix="/api/documents", tags=["documents"])
app.include_router(connections.router, prefix="/api/connections", tags=["connections"])
app.include_router(insights.router, prefix="/api/insights", tags=["insights"])
app.include_router(individual_insights.router, prefix="/api/individual-insights", tags=["individual-insights"])
app.include_router(podcast.router, prefix="/api/podcast", tags=["podcast"])
app.include_router(search.router, prefix="/api/search", tags=["search"])
app.include_router(youtube.router, prefix="/api/youtube", tags=["youtube"])
# Serve frontend static files (for production deployment)
if os.path.exists("../frontend/dist"):
app.mount("/assets", StaticFiles(directory="../frontend/dist/assets"), name="assets")
@app.get("/{full_path:path}")
async def serve_frontend(full_path: str):
"""Serve frontend files or index.html for SPA routing"""
if full_path.startswith("api/") or full_path.startswith("docs") or full_path.startswith("static/"):
# Let API and static routes handle themselves
return
file_path = f"../frontend/dist/{full_path}"
if os.path.exists(file_path) and os.path.isfile(file_path):
return FileResponse(file_path)
else:
# Return index.html for SPA routing
return FileResponse("../frontend/dist/index.html")
@app.get("/")
async def root():
"""Serve the frontend index.html or API info"""
if os.path.exists("../frontend/dist/index.html"):
return FileResponse("../frontend/dist/index.html")
else:
return {"message": "Document Insight & Engagement System API", "version": "1.0.0"}
@app.get("/health")
async def health_check():
return {"status": "healthy", "version": "1.0.0", "frontend": os.path.exists("../frontend/dist/index.html")}
if __name__ == "__main__":
uvicorn.run(
"main:app",
host="localhost",
port=8080,
reload=True if os.getenv("ENVIRONMENT", "development") == "development" else False
)