acecalisto3 commited on
Commit
ec86d09
·
verified ·
1 Parent(s): abd078d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -20
app.py CHANGED
@@ -1734,28 +1734,21 @@ if __name__ == "__main__":
1734
  raise
1735
 
1736
  def import_templates(self, path: str):
1737
- """Import templates from JSON file"""
1738
- try:
1739
- with open(path, 'r') as f:
1740
- data = json.load(f)
1741
-
1742
- for name, template_data in data.items():
1743
- self.templates[name] = Template(
1744
- code="", # Code should be loaded separately
1745
- description=template_data["description"],
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
- logger.info(f"Templates imported from {path}")
 
1756
 
1757
- except Exception as e:
1758
- logger.error(f"Error importing templates: {str(e)}")
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