|
|
import os |
|
|
import subprocess |
|
|
import gradio as gr |
|
|
import shutil |
|
|
|
|
|
def gerar_binario_iso(html_content): |
|
|
build_dir = "iso_data" |
|
|
iso_file = "sistema_bootavel.iso" |
|
|
|
|
|
|
|
|
if os.path.exists(build_dir): shutil.rmtree(build_dir) |
|
|
os.makedirs(os.path.join(build_dir, "boot/isolinux"), exist_ok=True) |
|
|
|
|
|
|
|
|
with open(os.path.join(build_dir, "index.html"), "w", encoding="utf-8") as f: |
|
|
f.write(html_content) |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
shutil.copy("/usr/lib/ISOLINUX/isolinux.bin", f"{build_dir}/boot/isolinux/") |
|
|
shutil.copy("/usr/lib/syslinux/modules/bios/ldlinux.c32", f"{build_dir}/boot/isolinux/") |
|
|
except: |
|
|
pass |
|
|
|
|
|
|
|
|
cfg = "default webos\nlabel webos\n kernel /vmlinuz\n append initrd=/initrd.img quiet" |
|
|
with open(os.path.join(build_dir, "boot/isolinux/isolinux.cfg"), "w") as f: |
|
|
f.write(cfg) |
|
|
|
|
|
|
|
|
comando = [ |
|
|
"xorriso", "-as", "mkisofs", |
|
|
"-o", iso_file, |
|
|
"-b", "boot/isolinux/isolinux.bin", |
|
|
"-c", "boot/isolinux/boot.cat", |
|
|
"-no-emul-boot", "-boot-load-size", "4", |
|
|
"-boot-info-table", "-R", "-J", |
|
|
build_dir |
|
|
] |
|
|
|
|
|
try: |
|
|
subprocess.run(comando, check=True) |
|
|
return iso_file |
|
|
except Exception as e: |
|
|
return f"Erro: {str(e)}" |
|
|
|
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
gr.Markdown("# 💾 HTML to Binary (ISO) Converter") |
|
|
html_input = gr.Code(label="Seu código HTML", language="html", lines=15, value="<h1>Sistema Pronto</h1>") |
|
|
btn = gr.Button("GERAR ISO BOOTÁVEL") |
|
|
output = gr.File(label="Arquivo Binário") |
|
|
|
|
|
btn.click(gerar_binario_iso, inputs=html_input, outputs=output) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo.launch(server_name="0.0.0.0", server_port=7860) |