|
from fastapi import FastAPI |
|
from fastapi.staticfiles import StaticFiles |
|
from fastapi.responses import FileResponse |
|
|
|
from setup_database import get_in_memory_document_store, add_data |
|
from setup_modules import create_retriever, create_readers_and_pipeline, text_reader_types, table_reader_types |
|
app = FastAPI() |
|
document_index = "document" |
|
document_store = get_in_memory_document_store(document_index) |
|
filenames = ["processed_website_tables","processed_website_text","processed_schedule_tables"] |
|
document_store, data = add_data(filenames, document_store, document_index) |
|
document_store, retriever = create_retriever(document_store) |
|
text_reader_type = text_reader_types['deberta-large'] |
|
table_reader_type = table_reader_types['tapas'] |
|
pipeline = create_readers_and_pipeline(retriever, text_reader_type, table_reader_type, True, True) |
|
|
|
|
|
@app.get("/answer") |
|
def t5(input): |
|
prediction = pipeline.run( |
|
query=input, params={"top_k": 10} |
|
) |
|
answer_list = [a.answer for a in prediction["answers"]] |
|
|
|
return {"output": ("\n").join(answer_list)} |
|
|
|
app.mount("/", StaticFiles(directory="static", html=True), name="static") |
|
|
|
@app.get("/") |
|
def index() -> FileResponse: |
|
return FileResponse(path="/app/static/index.html", media_type="text/html") |