Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from gradio.components import File as InputFile
|
3 |
+
from gradio.components import File as OutputFile
|
4 |
+
from urllib.parse import urlparse
|
5 |
+
import ifcopenshell
|
6 |
+
import ifcopenshell.api
|
7 |
+
import pandas as pd
|
8 |
+
|
9 |
+
def getProps(ifc_file_path):
|
10 |
+
|
11 |
+
ifc = ifcopenshell.open(ifc_file_path.name)
|
12 |
+
|
13 |
+
# Get all entity types in the IFC file
|
14 |
+
entity_types = ifc.types()
|
15 |
+
|
16 |
+
ifcAll = []
|
17 |
+
for entity_type in entity_types:
|
18 |
+
# Get all entities of this type
|
19 |
+
entities = ifc.by_type(entity_type)
|
20 |
+
ifcAll.extend(entities)
|
21 |
+
|
22 |
+
psetsColl = ifcopenshell.util.element.get_psets(ifc.by_type("IfcProject")[0])
|
23 |
+
|
24 |
+
for element in ifcAll:
|
25 |
+
psets = ifcopenshell.util.element.get_psets(element)
|
26 |
+
psetsColl = {**psetsColl, **psets}
|
27 |
+
psetsColl['General'] = {
|
28 |
+
'GlobalId': "X",
|
29 |
+
'Name': "X"
|
30 |
+
}
|
31 |
+
|
32 |
+
for key in psetsColl:
|
33 |
+
psetsColl[key] = {k: 'X' for k in psetsColl[key]}
|
34 |
+
|
35 |
+
df = pd.DataFrame(psetsColl).transpose()
|
36 |
+
df_transposed = df.transpose()
|
37 |
+
|
38 |
+
df_transposed.to_excel(ifc_file_path.name.replace(".ifc", ".xlsx"), engine='openpyxl')
|
39 |
+
|
40 |
+
return ifc_file_path.name.replace(".ifc", ".xlsx")
|
41 |
+
|
42 |
+
iface = gr.Interface(
|
43 |
+
fn=getProps,
|
44 |
+
inputs=[
|
45 |
+
InputFile(label="Upload IFC File"),
|
46 |
+
],
|
47 |
+
outputs=[
|
48 |
+
OutputFile(label="Download XLSX")
|
49 |
+
],
|
50 |
+
title="IFC Model Properties Extractor",
|
51 |
+
description="Upload an IFC file to process and download the resulting XLSX file."
|
52 |
+
)
|
53 |
+
|
54 |
+
iface.launch()
|