File size: 1,287 Bytes
9bf0a0f
 
 
 
 
 
 
 
 
 
def095c
9bf0a0f
 
 
 
 
 
bbf7997
9bf0a0f
 
3de0849
9bf0a0f
 
3de0849
9bf0a0f
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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": 3}
    )
    answer_list = [a.answer for a in prediction["answers"]]
    print(f"Answer List: {answer_list}")
    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")