Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1734,28 +1734,21 @@ if __name__ == "__main__":
|
|
| 1734 |
raise
|
| 1735 |
|
| 1736 |
def import_templates(self, path: str):
|
| 1737 |
-
|
| 1738 |
-
|
| 1739 |
-
|
| 1740 |
-
|
| 1741 |
-
|
| 1742 |
-
|
| 1743 |
-
|
| 1744 |
-
|
| 1745 |
-
|
| 1746 |
-
components=template_data["components"],
|
| 1747 |
-
metadata=template_data["metadata"],
|
| 1748 |
-
example=template_data.get("example")
|
| 1749 |
-
)
|
| 1750 |
-
|
| 1751 |
-
# Rebuild indexes
|
| 1752 |
-
self.component_index = self._build_component_index()
|
| 1753 |
-
self.category_index = self._build_category_index()
|
| 1754 |
|
| 1755 |
-
|
|
|
|
| 1756 |
|
| 1757 |
-
|
| 1758 |
-
|
| 1759 |
raise
|
| 1760 |
|
| 1761 |
|
|
|
|
| 1734 |
raise
|
| 1735 |
|
| 1736 |
def import_templates(self, path: str):
|
| 1737 |
+
"""Import templates from a directory"""
|
| 1738 |
+
try:
|
| 1739 |
+
for template_file in os.listdir(path):
|
| 1740 |
+
if template_file.endswith(".json"):
|
| 1741 |
+
template_path = os.path.join(path, template_file)
|
| 1742 |
+
with open(template_path, "r", encoding="utf-8") as f:
|
| 1743 |
+
template_data = json.load(f)
|
| 1744 |
+
name = template_file.replace(".json", "")
|
| 1745 |
+
self.templates[name] = Template(**template_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1746 |
|
| 1747 |
+
self.component_index = self._build_component_index()
|
| 1748 |
+
self.category_index = self._build_category_index()
|
| 1749 |
|
| 1750 |
+
except Exception as e:
|
| 1751 |
+
logging.error(f"Error importing templates: {str(e)}")
|
| 1752 |
raise
|
| 1753 |
|
| 1754 |
|