File size: 680 Bytes
b4fe433
65ab50e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#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)}