xls-converter / app.py
hellorahulk's picture
Create app.py
fd90193 verified
raw
history blame
1.06 kB
import io
from numbers_parser import Document
from openpyxl import Workbook
import gradio as gr
import pandas as pd
def numbers_to_xlsx(numbers_file):
"""
Reads a Numbers file and converts it to an xlsx file for download.
Args:
numbers_file: The uploaded Numbers file object.
Returns:
bytes: The contents of the converted xlsx file.
"""
try:
# Read the Numbers file
doc = Document(numbers_file.name)
sheets = doc.sheets
tables = sheets[0].tables
data = tables[0].rows(values_only=True)
df = pd.DataFrame(data[1:], columns=data[0])
xls_path = './new.xlsx'
df.to_excel(xls_path, index=False)
return xls_path
except Exception as e:
return f"Error converting file: {e}"
# Define the Gradio interface
interface = gr.Interface(
fn=numbers_to_xlsx,
inputs="file",
outputs=gr.File(label="XLSX file"),
title="Numbers to XLSX Converter",
description="Convert your Numbers files to Excel format easily and download the result.",
)
# Launch the Gradio app
interface.launch(share=True)