Spaces:
Running
on
Zero
Running
on
Zero
Upload template_manager.py
Browse files- template_manager.py +8 -15
template_manager.py
CHANGED
|
@@ -41,6 +41,8 @@ class TemplateManager:
|
|
| 41 |
# 載入模板數據庫
|
| 42 |
self.templates = self._load_templates()
|
| 43 |
|
|
|
|
|
|
|
| 44 |
# 如果提供了自定義模板,則進行合併
|
| 45 |
if custom_templates_db:
|
| 46 |
self._merge_custom_templates(custom_templates_db)
|
|
@@ -1045,14 +1047,14 @@ class TemplateManager:
|
|
| 1045 |
# 處理座位(椅子)相關
|
| 1046 |
if "chair" in object_statistics:
|
| 1047 |
count = object_statistics["chair"]["count"]
|
| 1048 |
-
|
| 1049 |
# 使用統一的數字轉換邏輯
|
| 1050 |
number_words = {
|
| 1051 |
-
1: "one", 2: "two", 3: "three", 4: "four",
|
| 1052 |
-
5: "five", 6: "six", 7: "seven", 8: "eight",
|
| 1053 |
9: "nine", 10: "ten", 11: "eleven", 12: "twelve"
|
| 1054 |
}
|
| 1055 |
-
|
| 1056 |
if count == 1:
|
| 1057 |
replacements["seating"] = "a chair"
|
| 1058 |
replacements["furniture"] = "a chair"
|
|
@@ -1067,6 +1069,7 @@ class TemplateManager:
|
|
| 1067 |
replacements["seating"] = f"numerous chairs ({count} total)"
|
| 1068 |
replacements["furniture"] = f"numerous chairs"
|
| 1069 |
|
|
|
|
| 1070 |
# 處理混合家具情況(當存在多種家具類型時)
|
| 1071 |
furniture_items = []
|
| 1072 |
furniture_counts = []
|
|
@@ -1084,7 +1087,7 @@ class TemplateManager:
|
|
| 1084 |
if len(furniture_items) > 1 and "furniture" not in replacements:
|
| 1085 |
main_furniture = furniture_items[0] # 數量最多的家具類型
|
| 1086 |
main_count = furniture_counts[0]
|
| 1087 |
-
|
| 1088 |
if main_furniture == "chair":
|
| 1089 |
number_words = ["", "one", "two", "three", "four", "five", "six"]
|
| 1090 |
if main_count <= 6:
|
|
@@ -1841,16 +1844,6 @@ class TemplateManager:
|
|
| 1841 |
self.logger.warning(f"Error getting scene detail templates for '{scene_type}': {str(e)}")
|
| 1842 |
return ["A scene with various elements and objects."]
|
| 1843 |
|
| 1844 |
-
def reload_templates(self):
|
| 1845 |
-
"""
|
| 1846 |
-
重新載入所有模板
|
| 1847 |
-
"""
|
| 1848 |
-
try:
|
| 1849 |
-
self.template_manager.reload_templates()
|
| 1850 |
-
self.logger.info("Templates reloaded successfully")
|
| 1851 |
-
except Exception as e:
|
| 1852 |
-
self.logger.error(f"Error reloading templates: {str(e)}")
|
| 1853 |
-
|
| 1854 |
def get_template_categories(self) -> List[str]:
|
| 1855 |
"""
|
| 1856 |
獲取所有可用的模板類別名稱
|
|
|
|
| 41 |
# 載入模板數據庫
|
| 42 |
self.templates = self._load_templates()
|
| 43 |
|
| 44 |
+
self.template_registry = self._initialize_template_registry()
|
| 45 |
+
|
| 46 |
# 如果提供了自定義模板,則進行合併
|
| 47 |
if custom_templates_db:
|
| 48 |
self._merge_custom_templates(custom_templates_db)
|
|
|
|
| 1047 |
# 處理座位(椅子)相關
|
| 1048 |
if "chair" in object_statistics:
|
| 1049 |
count = object_statistics["chair"]["count"]
|
| 1050 |
+
|
| 1051 |
# 使用統一的數字轉換邏輯
|
| 1052 |
number_words = {
|
| 1053 |
+
1: "one", 2: "two", 3: "three", 4: "four",
|
| 1054 |
+
5: "five", 6: "six", 7: "seven", 8: "eight",
|
| 1055 |
9: "nine", 10: "ten", 11: "eleven", 12: "twelve"
|
| 1056 |
}
|
| 1057 |
+
|
| 1058 |
if count == 1:
|
| 1059 |
replacements["seating"] = "a chair"
|
| 1060 |
replacements["furniture"] = "a chair"
|
|
|
|
| 1069 |
replacements["seating"] = f"numerous chairs ({count} total)"
|
| 1070 |
replacements["furniture"] = f"numerous chairs"
|
| 1071 |
|
| 1072 |
+
|
| 1073 |
# 處理混合家具情況(當存在多種家具類型時)
|
| 1074 |
furniture_items = []
|
| 1075 |
furniture_counts = []
|
|
|
|
| 1087 |
if len(furniture_items) > 1 and "furniture" not in replacements:
|
| 1088 |
main_furniture = furniture_items[0] # 數量最多的家具類型
|
| 1089 |
main_count = furniture_counts[0]
|
| 1090 |
+
|
| 1091 |
if main_furniture == "chair":
|
| 1092 |
number_words = ["", "one", "two", "three", "four", "five", "six"]
|
| 1093 |
if main_count <= 6:
|
|
|
|
| 1844 |
self.logger.warning(f"Error getting scene detail templates for '{scene_type}': {str(e)}")
|
| 1845 |
return ["A scene with various elements and objects."]
|
| 1846 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1847 |
def get_template_categories(self) -> List[str]:
|
| 1848 |
"""
|
| 1849 |
獲取所有可用的模板類別名稱
|