ada error Error: Out of range float values are not JSON compliant: nan Json saya berikut…
- User
ada error Error: Out of range float values are not JSON compliant: nan Json saya berikut {"Year":[2020,2021,2022,2023,2024],"Net Receivables":[1000,1200,1500,1800,2100],"Sales":[5000,6000,7000,8000,9000],"Cost of Goods Sold":[3000,3600,4200,4800,5400],"Current Assets":[2000,2400,2800,3200,3600],"PPE":[8000,8500,9000,9500,10000],"Net PPE":[7000,7400,7800,8200,8600],"Securities":[0,0,0,0,0],"Total Assets":[15000,16000,17000,18000,19000],"Depreciation Expense":[500,550,600,650,700],"SG&A Expenses":[400,450,500,550,600],"Total Debt":[5000,5500,6000,6500,7000],"Income from Continuing Operations":[1000,1100,1200,1300,1400],"Cash from Operations":[800,900,1000,1100,1200]} main.py import pandas as pd import fitz from fastapi import FastAPI, File, UploadFile from fastapi.responses import JSONResponse, HTMLResponse from fastapi.middleware.cors import CORSMiddleware
from lib.Chatbot import Chatbot from lib.audit.Beneish import BeneishMScoreCalculator
app = FastAPI()
app.add_middleware( CORSMiddleware, allow_origins=[""], allow_credentials=True, allow_methods=[""], allow_headers=["*"], )
@app.post("/upload") async def upload_file(file: UploadFile = File(...)): try: contents = await file.read() with fitz.open(stream=contents, filetype="pdf") as doc: text = "" for page in doc: text += page.get_text()
codechatbot = Chatbot() financial_data = chatbot.extract_financial_data(text) df = pd.DataFrame(financial_data) # Replace NaN values with None df = df.where(pd.notnull(df), None) calculator = BeneishMScoreCalculator(df) results = calculator.get_results() # Convert DataFrame and Series to dictionaries or lists for JSON serialization if isinstance(results, pd.DataFrame): results = results.to_dict(orient='records') # For DataFrames elif isinstance(results, pd.Series): results = results.to_dict() # For Series elif isinstance(results, dict): # Convert any nested DataFrames/Series within the dictionary for key, value in results.items(): if isinstance(value, (pd.DataFrame, pd.Series)): results[key] = value.to_dict(orient='records' if isinstance(value, pd.DataFrame) else 'dict') return JSONResponse(content={"status": "success", "results": results}) except Exception as e: return JSONResponse(content={"status": "error", "message": str(e)}) - Assistant