Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import io
|
2 |
+
from numbers_parser import Document
|
3 |
+
from openpyxl import Workbook
|
4 |
+
import gradio as gr
|
5 |
+
import pandas as pd
|
6 |
+
|
7 |
+
def numbers_to_xlsx(numbers_file):
|
8 |
+
"""
|
9 |
+
Reads a Numbers file and converts it to an xlsx file for download.
|
10 |
+
|
11 |
+
Args:
|
12 |
+
numbers_file: The uploaded Numbers file object.
|
13 |
+
|
14 |
+
Returns:
|
15 |
+
bytes: The contents of the converted xlsx file.
|
16 |
+
"""
|
17 |
+
try:
|
18 |
+
# Read the Numbers file
|
19 |
+
doc = Document(numbers_file.name)
|
20 |
+
sheets = doc.sheets
|
21 |
+
tables = sheets[0].tables
|
22 |
+
data = tables[0].rows(values_only=True)
|
23 |
+
df = pd.DataFrame(data[1:], columns=data[0])
|
24 |
+
xls_path = './new.xlsx'
|
25 |
+
df.to_excel(xls_path, index=False)
|
26 |
+
|
27 |
+
return xls_path
|
28 |
+
except Exception as e:
|
29 |
+
return f"Error converting file: {e}"
|
30 |
+
|
31 |
+
# Define the Gradio interface
|
32 |
+
interface = gr.Interface(
|
33 |
+
fn=numbers_to_xlsx,
|
34 |
+
inputs="file",
|
35 |
+
outputs=gr.File(label="XLSX file"),
|
36 |
+
title="Numbers to XLSX Converter",
|
37 |
+
description="Convert your Numbers files to Excel format easily and download the result.",
|
38 |
+
)
|
39 |
+
|
40 |
+
# Launch the Gradio app
|
41 |
+
interface.launch(share=True)
|