Spaces:
Sleeping
Sleeping
Update app/main.py
Browse files- app/main.py +34 -11
app/main.py
CHANGED
|
@@ -2,43 +2,66 @@ from fastapi import FastAPI, Request
|
|
| 2 |
from fastapi.responses import HTMLResponse
|
| 3 |
from fastapi.staticfiles import StaticFiles
|
| 4 |
from fastapi.templating import Jinja2Templates
|
|
|
|
| 5 |
import os
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
app = FastAPI(title="Ranjith Portfolio")
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
app.mount(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
templates = Jinja2Templates(directory=
|
| 14 |
|
| 15 |
|
| 16 |
@app.get("/", response_class=HTMLResponse)
|
| 17 |
async def home(request: Request):
|
| 18 |
"""Landing page"""
|
| 19 |
-
return templates.TemplateResponse(
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
|
| 22 |
@app.get("/projects", response_class=HTMLResponse)
|
| 23 |
async def projects(request: Request):
|
| 24 |
"""Projects page"""
|
| 25 |
-
return templates.TemplateResponse(
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
|
| 28 |
@app.get("/chatbot", response_class=HTMLResponse)
|
| 29 |
async def chatbot_page(request: Request):
|
| 30 |
"""Chatbot demo page"""
|
| 31 |
-
return templates.TemplateResponse(
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
|
| 34 |
@app.get("/resume", response_class=HTMLResponse)
|
| 35 |
async def resume_page(request: Request):
|
| 36 |
-
"""Resume page (download button
|
| 37 |
-
return templates.TemplateResponse(
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
|
|
|
|
| 40 |
if __name__ == "__main__":
|
| 41 |
import uvicorn
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
| 2 |
from fastapi.responses import HTMLResponse
|
| 3 |
from fastapi.staticfiles import StaticFiles
|
| 4 |
from fastapi.templating import Jinja2Templates
|
| 5 |
+
from pathlib import Path
|
| 6 |
import os
|
| 7 |
|
| 8 |
+
# Base directory of this file (works in Docker and locally)
|
| 9 |
+
BASE_DIR = Path(__file__).resolve().parent
|
| 10 |
+
|
| 11 |
+
# Initialize app
|
| 12 |
app = FastAPI(title="Ranjith Portfolio")
|
| 13 |
|
| 14 |
+
# Mount static directory
|
| 15 |
+
app.mount(
|
| 16 |
+
"/static",
|
| 17 |
+
StaticFiles(directory=BASE_DIR / "static"),
|
| 18 |
+
name="static"
|
| 19 |
+
)
|
| 20 |
|
| 21 |
+
# Load templates directory
|
| 22 |
+
templates = Jinja2Templates(directory=BASE_DIR / "templates")
|
| 23 |
|
| 24 |
|
| 25 |
@app.get("/", response_class=HTMLResponse)
|
| 26 |
async def home(request: Request):
|
| 27 |
"""Landing page"""
|
| 28 |
+
return templates.TemplateResponse(
|
| 29 |
+
"index.html",
|
| 30 |
+
{"request": request, "title": "Home"}
|
| 31 |
+
)
|
| 32 |
|
| 33 |
|
| 34 |
@app.get("/projects", response_class=HTMLResponse)
|
| 35 |
async def projects(request: Request):
|
| 36 |
"""Projects page"""
|
| 37 |
+
return templates.TemplateResponse(
|
| 38 |
+
"projects.html",
|
| 39 |
+
{"request": request, "title": "Projects"}
|
| 40 |
+
)
|
| 41 |
|
| 42 |
|
| 43 |
@app.get("/chatbot", response_class=HTMLResponse)
|
| 44 |
async def chatbot_page(request: Request):
|
| 45 |
"""Chatbot demo page"""
|
| 46 |
+
return templates.TemplateResponse(
|
| 47 |
+
"chatbot.html",
|
| 48 |
+
{"request": request, "title": "Chatbot"}
|
| 49 |
+
)
|
| 50 |
|
| 51 |
|
| 52 |
@app.get("/resume", response_class=HTMLResponse)
|
| 53 |
async def resume_page(request: Request):
|
| 54 |
+
"""Resume page (download button can link to PDF later)"""
|
| 55 |
+
return templates.TemplateResponse(
|
| 56 |
+
"resume.html",
|
| 57 |
+
{"request": request, "title": "Resume"}
|
| 58 |
+
)
|
| 59 |
|
| 60 |
|
| 61 |
+
# --- Entry point ---
|
| 62 |
if __name__ == "__main__":
|
| 63 |
import uvicorn
|
| 64 |
|
| 65 |
+
# Hugging Face Spaces requires port 7860
|
| 66 |
+
port = int(os.environ.get("PORT", 7860))
|
| 67 |
+
uvicorn.run(app, host="0.0.0.0", port=port)
|