Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,8 +5,7 @@ import tempfile
|
|
| 5 |
import os
|
| 6 |
|
| 7 |
def generate_circuit(skidl_code):
|
| 8 |
-
# Reset SKiDL trước mỗi lần
|
| 9 |
-
reset()
|
| 10 |
try:
|
| 11 |
# Lưu code tạm thời
|
| 12 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.py') as tmp:
|
|
@@ -20,12 +19,12 @@ def generate_circuit(skidl_code):
|
|
| 20 |
# Generate netlist
|
| 21 |
netlist_str = generate_netlist()
|
| 22 |
|
| 23 |
-
# Lưu
|
| 24 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.net', mode='w') as out_file:
|
| 25 |
out_file.write(netlist_str)
|
| 26 |
netlist_file_path = out_file.name
|
| 27 |
|
| 28 |
-
return "Netlist
|
| 29 |
|
| 30 |
except Exception as e:
|
| 31 |
return f"Error: {e}", None
|
|
@@ -36,10 +35,10 @@ def generate_circuit(skidl_code):
|
|
| 36 |
|
| 37 |
# Gradio UI
|
| 38 |
with gr.Blocks() as demo:
|
| 39 |
-
gr.Markdown("# SKiDL Circuit Builder")
|
| 40 |
-
skidl_input = gr.Textbox(label="Enter SKiDL
|
| 41 |
output_message = gr.Textbox(label="Status / Error", interactive=False)
|
| 42 |
-
download_btn = gr.File(label="Download Netlist")
|
| 43 |
|
| 44 |
run_button = gr.Button("Build Circuit")
|
| 45 |
|
|
|
|
| 5 |
import os
|
| 6 |
|
| 7 |
def generate_circuit(skidl_code):
|
| 8 |
+
reset() # Reset SKiDL trước mỗi lần chạy
|
|
|
|
| 9 |
try:
|
| 10 |
# Lưu code tạm thời
|
| 11 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.py') as tmp:
|
|
|
|
| 19 |
# Generate netlist
|
| 20 |
netlist_str = generate_netlist()
|
| 21 |
|
| 22 |
+
# Lưu file output để cho download
|
| 23 |
with tempfile.NamedTemporaryFile(delete=False, suffix='.net', mode='w') as out_file:
|
| 24 |
out_file.write(netlist_str)
|
| 25 |
netlist_file_path = out_file.name
|
| 26 |
|
| 27 |
+
return "Netlist generated successfully!", netlist_file_path
|
| 28 |
|
| 29 |
except Exception as e:
|
| 30 |
return f"Error: {e}", None
|
|
|
|
| 35 |
|
| 36 |
# Gradio UI
|
| 37 |
with gr.Blocks() as demo:
|
| 38 |
+
gr.Markdown("# SKiDL Circuit Builder (No KiCad Needed)")
|
| 39 |
+
skidl_input = gr.Textbox(label="Enter SKiDL Code Here", lines=20, placeholder="Type your SKiDL circuit code...")
|
| 40 |
output_message = gr.Textbox(label="Status / Error", interactive=False)
|
| 41 |
+
download_btn = gr.File(label="Download Netlist (.net)")
|
| 42 |
|
| 43 |
run_button = gr.Button("Build Circuit")
|
| 44 |
|