Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cc/serve UI assets #58

Merged
merged 4 commits into from
Mar 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions backend/server/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"""Entry point into the server."""
import logging
import os
from pathlib import Path

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from langserve import add_routes

from server.api import configurables, examples, extract, extractors, shared, suggest
Expand All @@ -12,6 +15,8 @@
extraction_runnable,
)

logger = logging.getLogger(__name__)

app = FastAPI(
title="Extraction Powered by LangChain",
description="An extraction service powered by LangChain.",
Expand All @@ -24,6 +29,8 @@
],
)

ROOT = Path(__file__).parent.parent

ORIGINS = os.environ.get("CORS_ORIGINS", "").split(",")

if ORIGINS:
Expand Down Expand Up @@ -59,6 +66,15 @@ def ready() -> str:
)


# Serve the frontend
ui_dir = str(ROOT / "ui")

if os.path.exists(ui_dir):
app.mount("/", StaticFiles(directory=ui_dir, html=True), name="ui")
else:
logger.warning("No UI directory found, serving API only.")


if __name__ == "__main__":
import uvicorn

Expand Down
Loading