|
60 | 60 | 3. 代码结构必须是: |
61 | 61 | import leafmap |
62 | 62 | # 可选:import geopandas as gpd, pandas as pd, numpy as np, matplotlib... |
63 | | - |
| 63 | +
|
64 | 64 | m = leafmap.Map(center=[纬度, 经度], zoom=缩放级别) |
65 | 65 | # ... 添加图层、数据、标注 ... |
66 | | - |
| 66 | +
|
67 | 67 | # 最后一行导出 HTML(OUTPUT_PATH 变量会自动替换为输出路径) |
68 | 68 | m.to_html(OUTPUT_PATH) |
69 | | - |
| 69 | +
|
70 | 70 | 4. 必须通过变量 OUTPUT_PATH 保存地图,不要硬编码其他输出路径 |
71 | 71 | 5. 如果用户描述中需要真实地理数据(如河流、行政边界等),优先尝试使用内置数据或示例数据: |
72 | 72 | - leafmap 自带示例数据可通过 leafmap.sample_data 或 folium 内置 GeoJSON 获取 |
@@ -100,9 +100,7 @@ def __init__( |
100 | 100 | or os.environ.get("LEAFMAP_LLM_BASE_URL") |
101 | 101 | or "https://api.deepseek.com/v1" |
102 | 102 | ) |
103 | | - self.api_key = ( |
104 | | - api_key or os.environ.get("LEAFMAP_LLM_API_KEY") or "" |
105 | | - ) |
| 103 | + self.api_key = api_key or os.environ.get("LEAFMAP_LLM_API_KEY") or "" |
106 | 104 | self.model = model or os.environ.get("LEAFMAP_LLM_MODEL") or "deepseek-chat" |
107 | 105 | self.temperature = temperature |
108 | 106 | self.max_tokens = max_tokens |
@@ -231,9 +229,7 @@ def _check_ast_safety(code: str) -> None: |
231 | 229 | raise SafetyError(f"检测到危险魔法属性引用: {node.value!r}") |
232 | 230 |
|
233 | 231 |
|
234 | | -def _safe_import( |
235 | | - name, globals=None, locals=None, fromlist=(), level=0 |
236 | | -): |
| 232 | +def _safe_import(name, globals=None, locals=None, fromlist=(), level=0): |
237 | 233 | """受限 __import__:仅允许白名单模块导入(运行时兜底,防动态导入绕过)。""" |
238 | 234 | root = name.split(".")[0] |
239 | 235 | if root not in ALLOWED_IMPORTS and name not in ALLOWED_IMPORTS: |
@@ -650,7 +646,9 @@ def natural_map( |
650 | 646 | while (not result["ok"]) and (attempt < max_repairs): |
651 | 647 | attempt += 1 |
652 | 648 | if verbose: |
653 | | - print(f"[leafmap.ai] 第 {attempt}/{max_repairs} 次修复: {result.get('error')}") |
| 649 | + print( |
| 650 | + f"[leafmap.ai] 第 {attempt}/{max_repairs} 次修复: {result.get('error')}" |
| 651 | + ) |
654 | 652 | try: |
655 | 653 | code = repair_code( |
656 | 654 | code, |
@@ -725,9 +723,7 @@ def demo(): |
725 | 723 | try: |
726 | 724 | import gradio as gr |
727 | 725 | except ImportError as e: |
728 | | - raise ImportError( |
729 | | - "Gradio 未安装,请先执行: pip install gradio" |
730 | | - ) from e |
| 726 | + raise ImportError("Gradio 未安装,请先执行: pip install gradio") from e |
731 | 727 |
|
732 | 728 | def _generate(description: str, max_repairs: int, show_code: bool): |
733 | 729 | if not description.strip(): |
|
0 commit comments