Spaces:
Runtime error
Runtime error
Download extract_v2.py from Macbath/indicator-modeling: direct link, hf CLI and curl.
- Browser
- Download file 2.63 kB
-
https://huggingface.co/spaces/Macbath/indicator-modeling/resolve/main/extract_v2.py
- Command line
-
hf download hf://spaces/Macbath/indicator-modeling/extract_v2.py
-
curl -L -o extract_v2.py https://huggingface.co/spaces/Macbath/indicator-modeling/resolve/main/extract_v2.py
2.63 kB
| #!/usr/bin/env python3 | |
| """ | |
| 精确提取聊天记录中的 app.py 原始内容 | |
| 搜索 Read 工具的成功结果(文件内容 > 10KB) | |
| """ | |
| import json | |
| jsonl_file = r"C:\Users\41930\.workbuddy\projects\c-Users-41930-WorkBuddy-2026-05-11-task-4\4134032d-101d-4c31-b4da-53dfc4305be7.jsonl" | |
| print("🔍 正在搜索聊天记录...") | |
| candidates = [] | |
| with open(jsonl_file, 'r', encoding='utf-8') as f: | |
| for line_num, line in enumerate(f, 1): | |
| try: | |
| data = json.loads(line) | |
| # 递归搜索所有字符串值 | |
| def search_values(obj, path=""): | |
| if isinstance(obj, dict): | |
| # 检查是否是 Read 工具的成功结果 | |
| if obj.get('toolName') == 'Read' or 'file_path' in str(obj): | |
| content = json.dumps(obj, ensure_ascii=False) | |
| # 查找包含完整 Python 文件的内容 | |
| if ('import streamlit as st' in content and | |
| 'def main()' in content and | |
| len(content) > 5000): | |
| # 尝试提取文件内容 | |
| # 查找 "file_content" 或类似字段 | |
| if 'stdout' in obj or 'result' in obj or 'content' in obj: | |
| candidates.append({ | |
| 'line': line_num, | |
| 'data': obj | |
| }) | |
| print(f"✅ 第 {line_num} 行:找到可能的完整代码") | |
| # 递归搜索 | |
| for key, value in obj.items(): | |
| search_values(value, f"{path}.{key}") | |
| elif isinstance(obj, list): | |
| for i, item in enumerate(obj): | |
| search_values(item, f"{path}[{i}]") | |
| except json.JSONDecodeError: | |
| continue | |
| except Exception as e: | |
| if line_num % 1000 == 0: | |
| print(f"处理第 {line_num} 行...") | |
| continue | |
| print(f"\n📊 找到 {len(candidates)} 个候选") | |
| print("\n正在分析最大的候选...") | |
| if candidates: | |
| # 保存候选到文件供检查 | |
| with open('candidates.json', 'w', encoding='utf-8') as f: | |
| json.dump(candidates[:3], f, ensure_ascii=False, indent=2) | |
| print("✅ 已保存前 3 个候选到 candidates.json") | |
| else: | |
| print("❌ 未找到候选,尝试搜索 'app.py' 相关内容...") | |