Spaces:
Sleeping
Sleeping
# main.py | |
from fastapi import FastAPI | |
from fastapi.middleware.cors import CORSMiddleware | |
from dotenv import load_dotenv | |
from routers.llm_chat import router as llm_chat_router | |
from routers.scraping_router import router as scraping_router | |
from routers.electronics_router import router as electronics_router | |
from fastapi.staticfiles import StaticFiles | |
from fastapi.responses import FileResponse | |
app = FastAPI( | |
title="LLM Chat API", | |
description="A FastAPI application to interact with an external LLM API.", | |
version="1.0.0", | |
) | |
# Enable CORS for all origins | |
app.add_middleware( | |
CORSMiddleware, | |
allow_origins=["*"], # Allows all origins | |
allow_credentials=True, | |
allow_methods=["*"], # Allows all methods | |
allow_headers=["*"], # Allows all headers | |
) | |
# Add Additional UI pages # Add index.html at static/ui/page2 | |
# app.mount("/page2", StaticFiles(directory="static/ui/page2", html=True), name="index") | |
# Include the routers | |
app.include_router(llm_chat_router) | |
app.include_router(scraping_router) | |
app.include_router(electronics_router) | |
# Serve index.html at root | |
async def read_root(): | |
return FileResponse("static/ui/index.html") | |
# Add to main.py | |
async def get_routes(): | |
return {"routes": [{"path": route.path, "name": route.name} for route in app.routes]} | |
if __name__ == "__main__": | |
import uvicorn | |
uvicorn.run(app, host="0.0.0.0", port=8000) |