Spaces:
Running
Running
fix(data): merge seed database — search now returns results
Browse files- api/main.py +2 -1
- api/routes/admin.py +31 -0
- graph/seed.py +104 -0
api/main.py
CHANGED
|
@@ -8,7 +8,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
| 8 |
from loguru import logger
|
| 9 |
|
| 10 |
from api.dependencies import get_driver, close_driver
|
| 11 |
-
from api.routes import search, profile, graph, risk, multilingual, export
|
| 12 |
from api.models import HealthResponse, StatsResponse
|
| 13 |
|
| 14 |
|
|
@@ -48,6 +48,7 @@ app.include_router(graph.router, tags=["Graph"])
|
|
| 48 |
app.include_router(risk.router, tags=["Risk"])
|
| 49 |
app.include_router(multilingual.router,tags=["Multilingual"])
|
| 50 |
app.include_router(export.router, tags=["Export"])
|
|
|
|
| 51 |
|
| 52 |
|
| 53 |
@app.get("/health", response_model=HealthResponse)
|
|
|
|
| 8 |
from loguru import logger
|
| 9 |
|
| 10 |
from api.dependencies import get_driver, close_driver
|
| 11 |
+
from api.routes import search, profile, graph, risk, multilingual, export, admin
|
| 12 |
from api.models import HealthResponse, StatsResponse
|
| 13 |
|
| 14 |
|
|
|
|
| 48 |
app.include_router(risk.router, tags=["Risk"])
|
| 49 |
app.include_router(multilingual.router,tags=["Multilingual"])
|
| 50 |
app.include_router(export.router, tags=["Export"])
|
| 51 |
+
app.include_router(admin.router, tags=["Admin"])
|
| 52 |
|
| 53 |
|
| 54 |
@app.get("/health", response_model=HealthResponse)
|
api/routes/admin.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os, sys
|
| 2 |
+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
| 3 |
+
|
| 4 |
+
from fastapi import APIRouter, Depends
|
| 5 |
+
from api.dependencies import get_db
|
| 6 |
+
|
| 7 |
+
router = APIRouter()
|
| 8 |
+
|
| 9 |
+
@router.post("/admin/seed")
|
| 10 |
+
def seed_database(driver=Depends(get_db)):
|
| 11 |
+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
|
| 12 |
+
from graph.seed import (
|
| 13 |
+
SAMPLE_POLITICIANS, SAMPLE_COMPANIES,
|
| 14 |
+
SAMPLE_CONTRACTS, SAMPLE_AUDIT_REPORTS
|
| 15 |
+
)
|
| 16 |
+
from graph.loader import GraphLoader
|
| 17 |
+
|
| 18 |
+
loader = GraphLoader()
|
| 19 |
+
p = loader.load_politicians(SAMPLE_POLITICIANS)
|
| 20 |
+
c = loader.load_companies(SAMPLE_COMPANIES)
|
| 21 |
+
k = loader.load_contracts(SAMPLE_CONTRACTS)
|
| 22 |
+
a = loader.load_audit_reports(SAMPLE_AUDIT_REPORTS)
|
| 23 |
+
|
| 24 |
+
return {
|
| 25 |
+
"status": "seeded",
|
| 26 |
+
"politicians": p,
|
| 27 |
+
"companies": c,
|
| 28 |
+
"contracts": k,
|
| 29 |
+
"audit_reports": a,
|
| 30 |
+
"try_searching": ["Modi", "Gandhi", "Adani", "Tata", "Infosys"],
|
| 31 |
+
}
|
graph/seed.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os, sys
|
| 2 |
+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 3 |
+
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
from loguru import logger
|
| 6 |
+
from graph.loader import GraphLoader
|
| 7 |
+
|
| 8 |
+
load_dotenv()
|
| 9 |
+
|
| 10 |
+
SAMPLE_POLITICIANS = [
|
| 11 |
+
{"id":"pol_001","name":"Narendra Modi","state":"Gujarat","party":"BJP",
|
| 12 |
+
"constituency":"Varanasi","criminal_cases":0,"total_assets_crore":2.85,
|
| 13 |
+
"education":"BA Political Science","year":2024},
|
| 14 |
+
{"id":"pol_002","name":"Rahul Gandhi","state":"Kerala","party":"INC",
|
| 15 |
+
"constituency":"Wayanad","criminal_cases":0,"total_assets_crore":15.89,
|
| 16 |
+
"education":"MPhil Development Studies","year":2024},
|
| 17 |
+
{"id":"pol_003","name":"Amit Shah","state":"Gujarat","party":"BJP",
|
| 18 |
+
"constituency":"Gandhinagar","criminal_cases":0,"total_assets_crore":42.33,
|
| 19 |
+
"education":"BSc Biochemistry","year":2024},
|
| 20 |
+
{"id":"pol_004","name":"Smriti Irani","state":"Uttar Pradesh","party":"BJP",
|
| 21 |
+
"constituency":"Amethi","criminal_cases":0,"total_assets_crore":9.12,
|
| 22 |
+
"education":"BA (Incomplete)","year":2024},
|
| 23 |
+
{"id":"pol_005","name":"Arvind Kejriwal","state":"Delhi","party":"AAP",
|
| 24 |
+
"constituency":"New Delhi","criminal_cases":3,"total_assets_crore":3.40,
|
| 25 |
+
"education":"BTech IIT Kharagpur","year":2024},
|
| 26 |
+
{"id":"pol_006","name":"Mamata Banerjee","state":"West Bengal","party":"AITC",
|
| 27 |
+
"constituency":"Bhowanipore","criminal_cases":0,"total_assets_crore":1.25,
|
| 28 |
+
"education":"BA History","year":2024},
|
| 29 |
+
{"id":"pol_007","name":"Nitish Kumar","state":"Bihar","party":"JDU",
|
| 30 |
+
"constituency":"Nalanda","criminal_cases":0,"total_assets_crore":1.65,
|
| 31 |
+
"education":"BE Electrical","year":2024},
|
| 32 |
+
{"id":"pol_008","name":"Yogi Adityanath","state":"Uttar Pradesh","party":"BJP",
|
| 33 |
+
"constituency":"Gorakhpur","criminal_cases":0,"total_assets_crore":1.08,
|
| 34 |
+
"education":"BSc Mathematics","year":2024},
|
| 35 |
+
{"id":"pol_009","name":"Shashi Tharoor","state":"Kerala","party":"INC",
|
| 36 |
+
"constituency":"Thiruvananthapuram","criminal_cases":1,"total_assets_crore":27.44,
|
| 37 |
+
"education":"PhD Tufts University","year":2024},
|
| 38 |
+
{"id":"pol_010","name":"Anurag Thakur","state":"Himachal Pradesh","party":"BJP",
|
| 39 |
+
"constituency":"Hamirpur","criminal_cases":0,"total_assets_crore":33.87,
|
| 40 |
+
"education":"BA History","year":2024},
|
| 41 |
+
]
|
| 42 |
+
|
| 43 |
+
SAMPLE_COMPANIES = [
|
| 44 |
+
{"id":"co_001","name":"Adani Enterprises Limited","state":"Gujarat",
|
| 45 |
+
"cin":"L51100GJ1993PLC019067","status":"Active","paid_up_capital_crore":112.0},
|
| 46 |
+
{"id":"co_002","name":"Reliance Industries Limited","state":"Maharashtra",
|
| 47 |
+
"cin":"L17110MH1973PLC019786","status":"Active","paid_up_capital_crore":673.0},
|
| 48 |
+
{"id":"co_003","name":"Tata Consultancy Services","state":"Maharashtra",
|
| 49 |
+
"cin":"L22210MH1995PLC084781","status":"Active","paid_up_capital_crore":366.0},
|
| 50 |
+
{"id":"co_004","name":"Infosys Limited","state":"Karnataka",
|
| 51 |
+
"cin":"L85110KA1981PLC013115","status":"Active","paid_up_capital_crore":207.0},
|
| 52 |
+
{"id":"co_005","name":"Bharti Airtel Limited","state":"Delhi",
|
| 53 |
+
"cin":"L74899DL1995PLC070609","status":"Active","paid_up_capital_crore":282.0},
|
| 54 |
+
]
|
| 55 |
+
|
| 56 |
+
SAMPLE_CONTRACTS = [
|
| 57 |
+
{"id":"ct_001","order_id":"GEM/2024/B/001","item_desc":"Road Construction Supplies",
|
| 58 |
+
"amount_crore":45.5,"buyer_org":"Ministry of Road Transport",
|
| 59 |
+
"order_date":"2024-03-15","company_id":"co_001"},
|
| 60 |
+
{"id":"ct_002","order_id":"GEM/2024/B/002","item_desc":"IT Infrastructure Services",
|
| 61 |
+
"amount_crore":128.0,"buyer_org":"Ministry of Electronics and IT",
|
| 62 |
+
"order_date":"2024-02-10","company_id":"co_003"},
|
| 63 |
+
{"id":"ct_003","order_id":"GEM/2024/B/003","item_desc":"Telecom Equipment",
|
| 64 |
+
"amount_crore":67.3,"buyer_org":"Ministry of Communications",
|
| 65 |
+
"order_date":"2024-01-20","company_id":"co_005"},
|
| 66 |
+
]
|
| 67 |
+
|
| 68 |
+
SAMPLE_AUDIT_REPORTS = [
|
| 69 |
+
{"id":"ar_001","title":"Performance Audit of Pradhan Mantri Gram Sadak Yojana 2023",
|
| 70 |
+
"year":2023,"ministry":"Ministry of Rural Development","state":"National",
|
| 71 |
+
"irregularity_amount_crore":234.5,"url":"https://cag.gov.in/reports/2023"},
|
| 72 |
+
{"id":"ar_002","title":"Compliance Audit of Smart Cities Mission 2022",
|
| 73 |
+
"year":2022,"ministry":"Ministry of Housing and Urban Affairs","state":"National",
|
| 74 |
+
"irregularity_amount_crore":189.2,"url":"https://cag.gov.in/reports/2022"},
|
| 75 |
+
{"id":"ar_003","title":"Revenue Audit of GST Collections Maharashtra 2023",
|
| 76 |
+
"year":2023,"ministry":"Ministry of Finance","state":"Maharashtra",
|
| 77 |
+
"irregularity_amount_crore":456.8,"url":"https://cag.gov.in/reports/2023"},
|
| 78 |
+
]
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def seed():
|
| 82 |
+
loader = GraphLoader()
|
| 83 |
+
|
| 84 |
+
logger.info("[Seed] Loading sample politicians...")
|
| 85 |
+
n = loader.load_politicians(SAMPLE_POLITICIANS)
|
| 86 |
+
logger.success(f"[Seed] Politicians loaded: {n}")
|
| 87 |
+
|
| 88 |
+
logger.info("[Seed] Loading sample companies...")
|
| 89 |
+
n = loader.load_companies(SAMPLE_COMPANIES)
|
| 90 |
+
logger.success(f"[Seed] Companies loaded: {n}")
|
| 91 |
+
|
| 92 |
+
logger.info("[Seed] Loading sample contracts...")
|
| 93 |
+
n = loader.load_contracts(SAMPLE_CONTRACTS)
|
| 94 |
+
logger.success(f"[Seed] Contracts loaded: {n}")
|
| 95 |
+
|
| 96 |
+
logger.info("[Seed] Loading sample audit reports...")
|
| 97 |
+
n = loader.load_audit_reports(SAMPLE_AUDIT_REPORTS)
|
| 98 |
+
logger.success(f"[Seed] Audit reports loaded: {n}")
|
| 99 |
+
|
| 100 |
+
logger.success("[Seed] Database seeded. Search 'Modi', 'Gandhi', 'Adani' to test.")
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
if __name__ == "__main__":
|
| 104 |
+
seed()
|