shamim237's picture
Upload 11 files
baf9496 verified
import gradio as gr
import subprocess
import os
import time
def run_script(script_name, *args):
command = ['python', script_name] + list(args)
start_time = time.time()
result = subprocess.run(command, capture_output=True, text=True)
end_time = time.time()
elapsed_time = end_time - start_time
if result.returncode != 0:
return f"Error running {script_name}: {result.stderr}"
else:
pass
def process_files(xml_file, output_path):
# Define file paths
bez_dict_file = "bez_dict.json"
flurstueck_shapefile = os.path.join(output_path, "flurstueck.shp")
nutzung_shapefile = os.path.join(output_path, "nutzung.shp")
nutzung_flurstueck_shapefile = os.path.join(output_path, "nutzungFlurstueck.shp")
gebauede_bauwerk_shapefile = os.path.join(output_path, "gebauedeBauwerk.shp")
verwaltungs_einheit_shapefile = os.path.join(output_path, "verwaltungsEinheit.shp")
kataster_bezirk_shapefile = os.path.join(output_path, "katasterBezirk.shp")
# Ensure the output directory exists
os.makedirs(output_path, exist_ok=True)
# Run scripts in the correct order
results = []
results.append(run_script('flurstueck.py', xml_file, flurstueck_shapefile))
results.append(f"Generated: {flurstueck_shapefile}")
results.append(run_script('nutzung.py', xml_file, bez_dict_file, nutzung_shapefile))
results.append(f"Generated: {nutzung_shapefile}")
results.append(run_script('nutflu.py', flurstueck_shapefile, nutzung_shapefile, nutzung_flurstueck_shapefile))
results.append(f"Generated: {nutzung_flurstueck_shapefile}")
results.append(run_script('guby.py', xml_file, gebauede_bauwerk_shapefile))
results.append(f"Generated: {gebauede_bauwerk_shapefile}")
results.append(run_script('ver.py', flurstueck_shapefile, xml_file, verwaltungs_einheit_shapefile))
results.append(f"Generated: {verwaltungs_einheit_shapefile}")
results.append(run_script('kat.py', flurstueck_shapefile, kataster_bezirk_shapefile))
results.append(f"Generated: {kataster_bezirk_shapefile}")
results.append("CONVERSION COMPLETED")
return "\n".join(results)
# Create Gradio interface
iface = gr.Interface(
fn=process_files,
inputs=[
gr.File(label="Input XML File"),
gr.Textbox(label="Output Path", placeholder="Enter the output directory path")
],
outputs="text",
title="NAS-ALKIS Conversion",
description="Upload an XML file and specify the output path to generate conversion."
)
# Launch the app
if __name__ == "__main__":
iface.launch(share=True)