2025-08-29 18:42:55 +01:00
|
|
|
import io
|
2025-09-02 12:22:50 +01:00
|
|
|
from api import investors
|
2025-08-29 18:42:55 +01:00
|
|
|
import pandas as pd
|
2025-09-02 12:22:50 +01:00
|
|
|
from db.db import db_dependency
|
2025-08-29 18:42:55 +01:00
|
|
|
from fastapi import FastAPI, File, UploadFile
|
2025-09-02 12:22:50 +01:00
|
|
|
from services.openrouter import InvestorProcessor
|
|
|
|
|
from services.querying import QueryProcessor
|
2025-08-28 22:51:58 +01:00
|
|
|
|
|
|
|
|
app = FastAPI()
|
2025-09-02 12:22:50 +01:00
|
|
|
app.include_router(investors.router)
|
|
|
|
|
# init_database()
|
2025-08-29 18:42:55 +01:00
|
|
|
|
|
|
|
|
|
2025-08-28 22:51:58 +01:00
|
|
|
@app.get("/")
|
|
|
|
|
def read_root():
|
2025-08-29 18:42:55 +01:00
|
|
|
return {"Hello": "World"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.post("/parse-csv")
|
|
|
|
|
async def parse_csv(db: db_dependency, file: UploadFile = File(...)):
|
|
|
|
|
# Read uploaded CSV with pandas
|
|
|
|
|
content = await file.read()
|
|
|
|
|
df = pd.read_csv(io.StringIO(content.decode("utf-8")))
|
|
|
|
|
|
|
|
|
|
# Process the dataframe
|
|
|
|
|
processor = InvestorProcessor(sql_session=db)
|
|
|
|
|
results = await processor.process_csv(df)
|
|
|
|
|
|
|
|
|
|
# Convert Pydantic objects to dictionaries
|
|
|
|
|
return {"results": [r.dict() for r in results]}
|
|
|
|
|
|
|
|
|
|
|
2025-09-02 12:22:50 +01:00
|
|
|
@app.post("/query")
|
|
|
|
|
async def query_investors(db: db_dependency, question: str):
|
|
|
|
|
processor = QueryProcessor(sql_session=db)
|
|
|
|
|
results = processor.process_query(question)
|
|
|
|
|
return {"results": results}
|
2025-08-29 18:42:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
import uvicorn
|
|
|
|
|
|
|
|
|
|
uvicorn.run(app="main:app", host="localhost", port=8000, reload=True)
|