Spaces:
No application file
No application file
| #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() | |
| 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)} | |