File size: 1,064 Bytes
fd90193
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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)