-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackend.py
More file actions
44 lines (32 loc) · 1.39 KB
/
backend.py
File metadata and controls
44 lines (32 loc) · 1.39 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
from fastapi import FastAPI
from pydantic import BaseModel
from WebScraper.scraper import Scraper
from Preprocessor.preprocessing_pipeline import Preprocessing_Pipeline
from Database.data_entities import Claim, Answer
from Database.sqldb import Database
from GraphRAG.rag_pipeline import RAG_Pipeline
backend_app = FastAPI()
db = Database()
class InputText(BaseModel):
text: str
@backend_app.post("/run_pipeline")
def process_text(input_text: InputText):
text = input_text.text
preprocessor = Preprocessing_Pipeline()
claim_title, claim_summary = preprocessor.run_claim_pipe(text)
claim = Claim(text, claim_title, claim_summary)
scraper = Scraper()
sources = scraper.search_and_extract(claim_title, num_results=10)
preprocessed_sources = preprocessor.run_sources_pipe(sources)
claim.add_sources(preprocessed_sources)
rag = RAG_Pipeline()
query_result, graphs_folder = rag.run_pipeline(preprocessed_sources, claim.summary, claim.id)
answer = Answer(claim.id, query_result, graphs_folder)
return {"claim_title": claim_title, "claim_summary": claim_summary, "sources": preprocessed_sources, "query_result": query_result, "graphs_folder": graphs_folder}
@backend_app.post("/delete_db")
def delete_database():
db.delete_all_conversations()
@backend_app.get("/get_history")
def delete_database():
history = db.get_history()
return history