From a6aef62a99e38f64301a752c2628cfe529031633 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Fri, 15 Jul 2022 22:07:39 +0400 Subject: [PATCH] Create Basic Landing Page to Query Semantic Search and Render Results - Allow viewing image results returned by Semantic Search. Until now there wasn't any interface within the app to view image search results. For text results, we at least had the emacs interface - This should help with debugging issues with image search too For text the Swagger interface was good enough --- .gitignore | 4 +- src/interface/web/index.html | 78 ++++++++++++++++++++++++++++++++++++ src/main.py | 10 ++++- 3 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 src/interface/web/index.html diff --git a/.gitignore b/.gitignore index 266478df..4bb1a18e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,6 @@ tests/data/embeddings src/.data .vscode *.gz -*.pt \ No newline at end of file +*.pt +/src/interface/web/*.jpg +/src/interface/web/*.png \ No newline at end of file diff --git a/src/interface/web/index.html b/src/interface/web/index.html new file mode 100644 index 00000000..611c1f55 --- /dev/null +++ b/src/interface/web/index.html @@ -0,0 +1,78 @@ + + + + + + + + + + + + + +
+ + + + + diff --git a/src/main.py b/src/main.py index 68d0c401..34e73c4d 100644 --- a/src/main.py +++ b/src/main.py @@ -1,12 +1,12 @@ # Standard Packages -import sys, json, yaml +import sys, json, yaml, os from typing import Optional # External Packages import uvicorn import torch from fastapi import FastAPI, Request -from fastapi.responses import HTMLResponse +from fastapi.responses import HTMLResponse, FileResponse from fastapi.staticfiles import StaticFiles from fastapi.templating import Jinja2Templates @@ -27,10 +27,16 @@ processor_config = ProcessorConfigModel() config_file = "" verbose = 0 app = FastAPI() +web_directory = f'src/interface/web/' +app.mount("/static", StaticFiles(directory=web_directory), name="static") app.mount("/views", StaticFiles(directory="views"), name="views") templates = Jinja2Templates(directory="views/") +@app.get("/", response_class=FileResponse) +def index(): + return FileResponse(web_directory + "index.html") + @app.get('/ui', response_class=HTMLResponse) def ui(request: Request): return templates.TemplateResponse("config.html", context={'request': request})