File size: 1,540 Bytes
77961ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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()