test / app.py
JairoDanielMT's picture
Update app.py
b4fe433 verified
#https://tomoniai-mixtral-chat.hf.space/
from fastapi import FastAPI, UploadFile, File
import pandas as pd
import json
from fastapi.responses import FileResponse
app = FastAPI()
@app.get("/convert/{sheet_name}")
async def convert(sheet_name: str, file: UploadFile = File(...)):
try:
df = pd.read_excel(file.file, engine='openpyxl', sheet_name=sheet_name)
json_file = "output.json"
df.to_json(json_file, orient="records")
return FileResponse(json_file, media_type='application/json', filename=json_file)
except FileNotFoundError:
return {"error": "El archivo no existe"}
except Exception as e:
return {"error": str(e)}