-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
54 lines (36 loc) · 1.8 KB
/
main.py
File metadata and controls
54 lines (36 loc) · 1.8 KB
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
from fastapi import FastAPI
import os
from dotenv import load_dotenv, dotenv_values
from text_db import TextDB
from key_phrase_finder import KeyPhraseFinder
from ranking import Ranking
load_dotenv()
app = FastAPI()
app.text_db = TextDB()
app.ranking = Ranking()
app.key_phrase_finder = KeyPhraseFinder(os.getenv("AWS_ACCESS_KEY_ID"), os.getenv("AWS_SECRET_ACCESS_KEY"), os.getenv("AWS_SESSION_TOKEN"))
@app.get("/highlight/{title}")
def generate_highlights(title: str):
content, full_text, source, searched_term = app.text_db.search_from_text_db(title)
key_phrases = app.key_phrase_finder.get_key_phrases(title, content)
response = app.ranking.get_ranks(title, key_phrases)
return { "nodes": response, "article": full_text, "source": source, "searched_term": searched_term }
@app.get("/get_search_options/{title}/{limit}")
def show_search_options(title: str, limit: int):
results = app.text_db.get_search_options(title, limit)
return { "results": results }
@app.get("/free_highlight/{title}")
def generate_free_highlights(title: str):
content, full_text, source, searched_term = app.text_db.get_content(title)
key_phrases = app.key_phrase_finder.get_key_phrases(content)
response = app.ranking.get_ranks(title, key_phrases)
return { "nodes": response, "article": full_text, "source": source, "searched_term": searched_term }
@app.get("/full_text/{title}")
def show_full_text(title: str):
_content, full_text, source, searched_term = app.text_db.search_from_text_db(title)
return { "article": full_text, "source": source, "searched_term": searched_term }
@app.get("/key_phrases/{title}")
def show_key_phrases(title: str):
content, _full_text, _url, _title = app.text_db.get_content(title)
response = app.key_phrase_finder.get_key_phrases(content)
return response