Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -19,39 +19,26 @@ except ImportError as e:
|
|
19 |
print("Please install requirements: pip install gradio skidl")
|
20 |
sys.exit(1)
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
"""Set a fallback symbol library path if environment variables are missing."""
|
43 |
-
if not check_kicad_env():
|
44 |
-
# Use a generic library or custom path (modify as needed)
|
45 |
-
default_lib_path = os.path.expanduser("~/kicad_symbols") # Example path
|
46 |
-
if os.path.exists(default_lib_path):
|
47 |
-
os.environ['KICAD_SYMBOL_DIR'] = default_lib_path
|
48 |
-
lib_search_paths.append(default_lib_path)
|
49 |
-
logger.info(f"Set default symbol library path: {default_lib_path}")
|
50 |
-
else:
|
51 |
-
logger.warning(
|
52 |
-
f"Default symbol library path {default_lib_path} not found. "
|
53 |
-
"Parts may not be resolved without valid libraries."
|
54 |
-
)
|
55 |
|
56 |
def cleanup_old_files():
|
57 |
"""Clean up temporary files older than 1 hour."""
|
@@ -72,8 +59,12 @@ def generate_circuit(skidl_code):
|
|
72 |
reset() # Reset SKiDL state
|
73 |
tmp_path = None
|
74 |
try:
|
75 |
-
#
|
76 |
-
|
|
|
|
|
|
|
|
|
77 |
|
78 |
# Validate code syntax
|
79 |
try:
|
@@ -119,19 +110,16 @@ with gr.Blocks() as demo:
|
|
119 |
gr.Markdown(
|
120 |
"""
|
121 |
# SKiDL Circuit Builder (No KiCad Needed)
|
122 |
-
**Note**: Ensure
|
123 |
"""
|
124 |
)
|
125 |
|
126 |
-
# Example code
|
127 |
example_code = """
|
128 |
from skidl import *
|
129 |
-
# Use Device library for basic components
|
130 |
-
lib_search_paths.append('.') # Ensure local libraries are searchable
|
131 |
-
set_default_lib('Device') # Use built-in Device library
|
132 |
vcc = Vcc()
|
133 |
gnd = Gnd()
|
134 |
-
r1 = Part('Device', 'R', value='1k') #
|
135 |
c1 = Part('Device', 'C', value='1uF')
|
136 |
r1[1] & c1 & gnd
|
137 |
r1[2] & vcc
|
|
|
19 |
print("Please install requirements: pip install gradio skidl")
|
20 |
sys.exit(1)
|
21 |
|
22 |
+
def check_device_lib():
|
23 |
+
"""Check if device.lib exists in the current directory."""
|
24 |
+
current_dir = os.getcwd()
|
25 |
+
device_lib_path = os.path.join(current_dir, 'device.lib')
|
26 |
+
if os.path.exists(device_lib_path):
|
27 |
+
logger.info(f"Found device.lib in current directory: {device_lib_path}")
|
28 |
+
return True
|
29 |
+
logger.warning(f"device.lib not found in current directory: {current_dir}")
|
30 |
+
return False
|
31 |
+
|
32 |
+
def configure_skidl_libs():
|
33 |
+
"""Configure SKiDL to use device.lib from the current directory."""
|
34 |
+
current_dir = os.getcwd()
|
35 |
+
# Clear existing library search paths to prioritize current directory
|
36 |
+
lib_search_paths.clear()
|
37 |
+
# Add current directory to search paths
|
38 |
+
lib_search_paths.append(current_dir)
|
39 |
+
# Set default library to Device
|
40 |
+
set_default_lib('Device')
|
41 |
+
logger.info(f"Configured SKiDL to use Device library from {current_dir}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
def cleanup_old_files():
|
44 |
"""Clean up temporary files older than 1 hour."""
|
|
|
59 |
reset() # Reset SKiDL state
|
60 |
tmp_path = None
|
61 |
try:
|
62 |
+
# Configure SKiDL to use device.lib from current directory
|
63 |
+
configure_skidl_libs()
|
64 |
+
|
65 |
+
# Check for device.lib
|
66 |
+
if not check_device_lib():
|
67 |
+
return "Error: device.lib not found in the current directory. Please ensure it exists.", None
|
68 |
|
69 |
# Validate code syntax
|
70 |
try:
|
|
|
110 |
gr.Markdown(
|
111 |
"""
|
112 |
# SKiDL Circuit Builder (No KiCad Needed)
|
113 |
+
**Note**: Ensure `device.lib` is in the same directory as this script to resolve components like resistors and capacitors.
|
114 |
"""
|
115 |
)
|
116 |
|
117 |
+
# Example code using Device library from device.lib
|
118 |
example_code = """
|
119 |
from skidl import *
|
|
|
|
|
|
|
120 |
vcc = Vcc()
|
121 |
gnd = Gnd()
|
122 |
+
r1 = Part('Device', 'R', value='1k') # Uses device.lib in current directory
|
123 |
c1 = Part('Device', 'C', value='1uF')
|
124 |
r1[1] & c1 & gnd
|
125 |
r1[2] & vcc
|