Spaces:
Paused
Paused
separation template
Browse files
app.py
CHANGED
|
@@ -30,6 +30,43 @@ def cleanup_workspace(workspace_dir: Path) -> None:
|
|
| 30 |
except Exception as e:
|
| 31 |
_logger.error(f"Error cleaning up workspace: {e}")
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
|
| 35 |
def load_yaml_template(template_path: Path) -> Dict:
|
|
@@ -111,12 +148,18 @@ def main():
|
|
| 111 |
|
| 112 |
template_mode = st.radio("Template Mode", ["Use Existing", "Create New"])
|
| 113 |
|
|
|
|
|
|
|
| 114 |
if template_mode == "Use Existing":
|
| 115 |
template_name = st.selectbox("Select Template", existing_templates)
|
|
|
|
| 116 |
else:
|
| 117 |
template_name = st.text_input("New Template Name")
|
| 118 |
-
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
# LLM Settings
|
| 122 |
st.subheader("LLM Settings")
|
|
@@ -148,7 +191,7 @@ def main():
|
|
| 148 |
st.header("Template Configuration")
|
| 149 |
|
| 150 |
if template_name:
|
| 151 |
-
template_path =
|
| 152 |
template_data = load_yaml_template(template_path)
|
| 153 |
|
| 154 |
if "current_template" not in st.session_state or st.session_state.current_template != template_name:
|
|
|
|
| 30 |
except Exception as e:
|
| 31 |
_logger.error(f"Error cleaning up workspace: {e}")
|
| 32 |
|
| 33 |
+
def get_template_path(template_name: str, is_new_template: bool = False) -> Path:
|
| 34 |
+
"""
|
| 35 |
+
Get template file path
|
| 36 |
+
:param template_name: Name of the template
|
| 37 |
+
:param is_new_template: Whether it's a new template created by user
|
| 38 |
+
:return: Path object for the template file
|
| 39 |
+
"""
|
| 40 |
+
settings_path = Path("metagpt/ext/spo/settings")
|
| 41 |
+
|
| 42 |
+
if is_new_template:
|
| 43 |
+
# Create user-specific subdirectory in settings folder
|
| 44 |
+
if "user_id" not in st.session_state:
|
| 45 |
+
st.session_state.user_id = str(uuid.uuid4())
|
| 46 |
+
user_settings_path = settings_path / st.session_state.user_id
|
| 47 |
+
return user_settings_path / f"{template_name}.yaml"
|
| 48 |
+
else:
|
| 49 |
+
# Use root settings path for existing templates
|
| 50 |
+
return settings_path / f"{template_name}.yaml"
|
| 51 |
+
|
| 52 |
+
def get_all_templates() -> List[str]:
|
| 53 |
+
"""
|
| 54 |
+
Get list of all available templates (both default and user-specific)
|
| 55 |
+
:return: List of template names
|
| 56 |
+
"""
|
| 57 |
+
settings_path = Path("metagpt/ext/spo/settings")
|
| 58 |
+
|
| 59 |
+
# Get default templates
|
| 60 |
+
templates = [f.stem for f in settings_path.glob("*.yaml")]
|
| 61 |
+
|
| 62 |
+
# Get user-specific templates if user_id exists
|
| 63 |
+
if "user_id" in st.session_state:
|
| 64 |
+
user_path = settings_path / st.session_state.user_id
|
| 65 |
+
if user_path.exists():
|
| 66 |
+
user_templates = [f.stem for f in user_path.glob("*.yaml")]
|
| 67 |
+
templates.extend(user_templates)
|
| 68 |
+
|
| 69 |
+
return sorted(list(set(templates)))
|
| 70 |
|
| 71 |
|
| 72 |
def load_yaml_template(template_path: Path) -> Dict:
|
|
|
|
| 148 |
|
| 149 |
template_mode = st.radio("Template Mode", ["Use Existing", "Create New"])
|
| 150 |
|
| 151 |
+
existing_templates = get_all_templates()
|
| 152 |
+
|
| 153 |
if template_mode == "Use Existing":
|
| 154 |
template_name = st.selectbox("Select Template", existing_templates)
|
| 155 |
+
is_new_template = False
|
| 156 |
else:
|
| 157 |
template_name = st.text_input("New Template Name")
|
| 158 |
+
is_new_template = True
|
| 159 |
+
if template_name:
|
| 160 |
+
if template_name in existing_templates:
|
| 161 |
+
st.error("Template name already exists. Please choose a different name.")
|
| 162 |
+
template_name = ""
|
| 163 |
|
| 164 |
# LLM Settings
|
| 165 |
st.subheader("LLM Settings")
|
|
|
|
| 191 |
st.header("Template Configuration")
|
| 192 |
|
| 193 |
if template_name:
|
| 194 |
+
template_path = get_template_path(template_name, is_new_template)
|
| 195 |
template_data = load_yaml_template(template_path)
|
| 196 |
|
| 197 |
if "current_template" not in st.session_state or st.session_state.current_template != template_name:
|