Spaces:
Sleeping
Sleeping
Upload run.py with huggingface_hub
Browse files
run.py
CHANGED
|
@@ -436,7 +436,11 @@ def run(arxiv_url: str, top_n: int = 5, progress=None) -> dict:
|
|
| 436 |
|
| 437 |
broad_queries = _extract_broad_queries(title, abstract)
|
| 438 |
# 合并对比算法搜索词,去重
|
| 439 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 440 |
print(f" LLM: {len(broad_queries)} + S2引用: {len(comparison_queries)} + S2论文: {len(s2_extra_queries)} = {len(all_queries)} 个总搜索词:")
|
| 441 |
for q in all_queries:
|
| 442 |
print(f" - {q}")
|
|
@@ -495,10 +499,8 @@ def run(arxiv_url: str, top_n: int = 5, progress=None) -> dict:
|
|
| 495 |
try:
|
| 496 |
direction = analyze_direction(title, abstract, filtered_results, domain_context)
|
| 497 |
except Exception as e:
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
"error": f"研究方向解析失败: {e}",
|
| 501 |
-
}
|
| 502 |
|
| 503 |
subfield = direction.get("subfield", "未知")
|
| 504 |
families = direction.get("method_families", [])
|
|
@@ -845,6 +847,31 @@ def _sanity_check_direction(title: str, subfield: str) -> None:
|
|
| 845 |
print(f" 这可能是 LLM 混淆了论文,请人工核实分析结果。")
|
| 846 |
|
| 847 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 848 |
def _make_error_evaluation(error_msg: str) -> dict:
|
| 849 |
"""构造一个表示评估失败的 evaluation dict"""
|
| 850 |
return {
|
|
|
|
| 436 |
|
| 437 |
broad_queries = _extract_broad_queries(title, abstract)
|
| 438 |
# 合并对比算法搜索词,去重
|
| 439 |
+
has_github_token = bool(os.getenv("GITHUB_TOKEN", ""))
|
| 440 |
+
max_queries = 15 if has_github_token else 8
|
| 441 |
+
all_queries = list(dict.fromkeys(s2_extra_queries + comparison_queries + broad_queries))[:max_queries]
|
| 442 |
+
if not has_github_token:
|
| 443 |
+
print(f" ⚠️ 未设置 GITHUB_TOKEN,搜索词限制为 {max_queries} 个以避免限速")
|
| 444 |
print(f" LLM: {len(broad_queries)} + S2引用: {len(comparison_queries)} + S2论文: {len(s2_extra_queries)} = {len(all_queries)} 个总搜索词:")
|
| 445 |
for q in all_queries:
|
| 446 |
print(f" - {q}")
|
|
|
|
| 499 |
try:
|
| 500 |
direction = analyze_direction(title, abstract, filtered_results, domain_context)
|
| 501 |
except Exception as e:
|
| 502 |
+
print(f" [WARN] Agent 1 方向解析失败,降级为基本分析: {e}")
|
| 503 |
+
direction = _make_fallback_direction(title, abstract, filtered_results)
|
|
|
|
|
|
|
| 504 |
|
| 505 |
subfield = direction.get("subfield", "未知")
|
| 506 |
families = direction.get("method_families", [])
|
|
|
|
| 847 |
print(f" 这可能是 LLM 混淆了论文,请人工核实分析结果。")
|
| 848 |
|
| 849 |
|
| 850 |
+
def _make_fallback_direction(title: str, abstract: str, repos: list[dict]) -> dict:
|
| 851 |
+
"""Agent 1 失败时的降级方向分析:基于搜索到的仓库名称推断子领域。"""
|
| 852 |
+
# 从仓库 topic/description 提取高频词作为子领域
|
| 853 |
+
all_words = []
|
| 854 |
+
for r in repos[:10]:
|
| 855 |
+
desc = (r.get("description") or "")
|
| 856 |
+
topics = " ".join(r.get("topics", []))
|
| 857 |
+
all_words.extend((desc + " " + topics).lower().split())
|
| 858 |
+
|
| 859 |
+
stops = {'a', 'an', 'the', 'of', 'for', 'in', 'on', 'to', 'and', 'or', 'is', 'are',
|
| 860 |
+
'we', 'our', 'that', 'this', 'with', 'from', 'by', 'as', 'at', 'be', 'it'}
|
| 861 |
+
meaningful = [w for w in all_words if w not in stops and len(w) >= 4]
|
| 862 |
+
word_freq = {}
|
| 863 |
+
for w in meaningful:
|
| 864 |
+
word_freq[w] = word_freq.get(w, 0) + 1
|
| 865 |
+
top_words = sorted(word_freq, key=word_freq.get, reverse=True)[:6]
|
| 866 |
+
|
| 867 |
+
return {
|
| 868 |
+
"subfield": f"基于仓库数据推断: {', '.join(top_words[:3])}" if top_words else "未知领域",
|
| 869 |
+
"subfield_trend": "(Agent 1 暂不可用,趋势分析跳过。后续版本将自动恢复。)",
|
| 870 |
+
"method_families": [],
|
| 871 |
+
"broad_queries": [],
|
| 872 |
+
}
|
| 873 |
+
|
| 874 |
+
|
| 875 |
def _make_error_evaluation(error_msg: str) -> dict:
|
| 876 |
"""构造一个表示评估失败的 evaluation dict"""
|
| 877 |
return {
|