Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from gradio.components import File as InputFile | |
| from gradio.components import File as OutputFile | |
| from gradio.components import Dataframe as OutputDataframe | |
| from urllib.parse import urlparse | |
| import ifcopenshell | |
| import ifcopenshell.api | |
| import pandas as pd | |
| def getProps(ifc_file_path): | |
| ifc = ifcopenshell.open(ifc_file_path.name) | |
| # Get all entity types in the IFC file | |
| entity_types = ifc.types() | |
| ifcAll = [] | |
| for entity_type in entity_types: | |
| # Get all entities of this type | |
| entities = ifc.by_type(entity_type) | |
| ifcAll.extend(entities) | |
| psetsColl = ifcopenshell.util.element.get_psets(ifc.by_type("IfcProject")[0]) | |
| for element in ifcAll: | |
| psets = ifcopenshell.util.element.get_psets(element) | |
| psetsColl = {**psetsColl, **psets} | |
| psetsColl['General'] = { | |
| 'GlobalId': "X", | |
| 'Name': "X" | |
| } | |
| for key in psetsColl: | |
| psetsColl[key] = {k: 'X' for k in psetsColl[key]} | |
| df = pd.DataFrame(psetsColl).transpose() | |
| df_transposed = df.transpose() | |
| df_transposed.to_excel(ifc_file_path.name.replace(".ifc", ".xlsx"), engine='openpyxl') | |
| df_transposed_reset = df_transposed.reset_index() | |
| return ifc_file_path.name.replace(".ifc", ".xlsx"), df_transposed_reset | |
| iface = gr.Interface( | |
| fn=getProps, | |
| inputs=[ | |
| InputFile(label="Upload IFC File", file_count='single', file_types=[".ifc"]), | |
| ], | |
| outputs=[ | |
| OutputFile(label="Download XLSX"), | |
| OutputDataframe(label="IFC Property Sets") | |
| ], | |
| title="IFC Model Property Sets Extractor", | |
| description="Upload an IFC file to process and download the resulting XLSX file." | |
| ) | |
| iface.launch() | |