nexus-apis / main.py
suneeln-duke's picture
.
77961ad
raw
history blame contribute delete
No virus
1.54 kB
from fastapi import FastAPI, Request
from Flask import jsonify
from scripts import mongo_utils
from scripts import rag_utils
from dotenv import load_dotenv
import os
load_dotenv()
app = FastAPI
client = mongo_utils.connect_to_mongo()
print("Connected to MongoDB")
def captitalize_name(name):
name_split = name.split("_")
return " ".join([x.capitalize() for x in name_split])
@app.post('/summ')
def summarize(request: Request):
pdf_path = request.body()['pdf_path']
text = request.body()['text']
vs = mongo_utils.get_vs(pdf_path, client)
summary = rag_utils.summ(vs, text)
return {'summary': summary}
@app.post('/clf')
def classify(request: Request):
pdf_path = request.body()['pdf_path']
text = request.body()['text']
vs = mongo_utils.get_vs(pdf_path, client)
decision = rag_utils.clf_seq(vs, text).lower()
return jsonify({'decision': decision})
@app.post('/options')
def options(request: Request):
pdf_path = request.body()['pdf_path']
text = request.body()['text']
vs = mongo_utils.get_vs(pdf_path, client)
options = eval(rag_utils.gen_options(vs, text))
return jsonify({'options': options})
@app.post('/path')
def path(request: Request):
pdf_path = request.body()['pdf_path']
text = request.body()['text']
decision = request.body()['decision']
vs = mongo_utils.get_vs(pdf_path, client)
path = rag_utils.gen_path(vs, text, decision)
return jsonify({'path': path})
if __name__ == '__main__':
app.run()