优化UI模块和资源推荐功能
Made-with: Cursor
This commit is contained in:
+65
-139
@@ -3,93 +3,86 @@
|
||||
import streamlit as st
|
||||
|
||||
from modules.resource_recommender import ResourceRecommender
|
||||
from modules.ui.components import render_tab_top_with_clear
|
||||
|
||||
|
||||
def render_tab_resources(storage, brand: str) -> None:
|
||||
"""渲染 Tab8:GEO 资源库。由主入口在 with tab8 内调用。"""
|
||||
st.markdown("### 📚 GEO 资源库")
|
||||
st.caption("发现 GEO 相关工具、代理、论文和社区资源,增强工具生态")
|
||||
render_tab_top_with_clear(
|
||||
title="📚 GEO 资源库",
|
||||
caption="发现 GEO 相关工具、代理、论文和社区资源,增强工具生态",
|
||||
clear_key="resources_clear",
|
||||
on_clear=lambda: None, # 资源库无需清空
|
||||
)
|
||||
|
||||
resource_recommender = ResourceRecommender()
|
||||
|
||||
# 资源统计概览
|
||||
summary = resource_recommender.get_resource_summary()
|
||||
stat_col1, stat_col2, stat_col3, stat_col4, stat_col5 = st.columns(5)
|
||||
with stat_col1:
|
||||
st.metric("总资源数", summary['total'])
|
||||
with stat_col2:
|
||||
st.metric("代理服务", summary['agents'])
|
||||
with stat_col3:
|
||||
st.metric("工具推荐", summary['tools'])
|
||||
with stat_col4:
|
||||
st.metric("论文/指南", summary['papers'])
|
||||
with stat_col5:
|
||||
st.metric("社区资源", summary['communities'])
|
||||
|
||||
st.markdown("---")
|
||||
stat_cols = st.columns(5)
|
||||
stats = [
|
||||
("总资源数", summary['total']),
|
||||
("AI 搜索", summary['agents']),
|
||||
("工具推荐", summary['tools']),
|
||||
("论文指南", summary['papers']),
|
||||
("社区资源", summary['communities']),
|
||||
]
|
||||
for col, (label, value) in zip(stat_cols, stats):
|
||||
with col:
|
||||
st.metric(label, value)
|
||||
|
||||
# 搜索功能
|
||||
search_col1, search_col2 = st.columns([3, 1])
|
||||
search_col1, search_col2 = st.columns([4, 1])
|
||||
with search_col1:
|
||||
search_query = st.text_input(
|
||||
"🔍 搜索资源",
|
||||
"搜索资源",
|
||||
key="resource_search",
|
||||
placeholder="输入关键词搜索代理、工具、论文、社区...",
|
||||
help="支持搜索资源名称、描述、功能特性等"
|
||||
placeholder="🔍 输入关键词搜索资源名称、描述、功能特性...",
|
||||
label_visibility="collapsed"
|
||||
)
|
||||
with search_col2:
|
||||
clear_search = st.button("清除搜索", use_container_width=True, key="clear_resource_search")
|
||||
if clear_search:
|
||||
if st.button("清除", use_container_width=True, key="clear_resource_search"):
|
||||
st.session_state.resource_search = ""
|
||||
st.rerun()
|
||||
|
||||
# 资源分类标签
|
||||
resource_tab1, resource_tab2, resource_tab3, resource_tab4 = st.tabs(["🤖 GEO 代理", "🛠️ 工具推荐", "📄 论文/指南", "👥 社区资源"])
|
||||
resource_tab1, resource_tab2, resource_tab3, resource_tab4 = st.tabs([
|
||||
"🤖 AI 搜索", "🛠️ 工具推荐", "📄 论文指南", "👥 社区资源"
|
||||
])
|
||||
|
||||
# GEO 代理
|
||||
# AI 搜索/代理
|
||||
with resource_tab1:
|
||||
st.markdown("#### 🤖 GEO 代理服务")
|
||||
st.caption("专业的 GEO 代理服务,提供高质量的内容生成和优化")
|
||||
st.caption("AI 搜索引擎和内容生成服务,用于验证和优化 GEO 效果")
|
||||
|
||||
if search_query:
|
||||
agents = resource_recommender.search_resources(search_query, "agents")
|
||||
if agents:
|
||||
st.info(f"🔍 找到 {len(agents)} 个匹配的代理服务")
|
||||
else:
|
||||
agents = resource_recommender.get_agents()
|
||||
|
||||
if agents:
|
||||
for i, agent in enumerate(agents, 1):
|
||||
for agent in agents:
|
||||
with st.container(border=True):
|
||||
col1, col2 = st.columns([3, 1])
|
||||
with col1:
|
||||
st.markdown(f"##### {i}. {agent['name']} {agent.get('rating', '')}")
|
||||
st.markdown(f"**{agent['name']}** {agent.get('rating', '')}")
|
||||
with col2:
|
||||
if agent.get('url'):
|
||||
st.markdown(f"[🔗 访问]({agent['url']})")
|
||||
st.link_button("访问", agent['url'], use_container_width=True)
|
||||
|
||||
st.markdown(f"**{agent['description']}**")
|
||||
st.markdown(f"**分类**:{agent.get('category', 'N/A')}")
|
||||
st.caption(agent['description'])
|
||||
|
||||
if agent.get('features'):
|
||||
st.markdown("**功能特性**:")
|
||||
features_text = " | ".join([f"✓ {f}" for f in agent['features']])
|
||||
st.markdown(features_text)
|
||||
|
||||
if agent.get('url'):
|
||||
st.markdown(f"**链接**:{agent['url']}")
|
||||
features_text = " · ".join([f"✓ {f}" for f in agent['features']])
|
||||
st.markdown(f"<small>{features_text}</small>", unsafe_allow_html=True)
|
||||
else:
|
||||
st.info("💡 暂无匹配的代理资源。尝试使用其他关键词搜索。")
|
||||
st.info("💡 暂无匹配的资源,尝试其他关键词搜索。")
|
||||
|
||||
# 工具推荐
|
||||
with resource_tab2:
|
||||
st.markdown("#### 🛠️ 工具推荐")
|
||||
st.caption("GEO 相关的工具和服务,帮助优化内容效果")
|
||||
|
||||
if search_query:
|
||||
tools = resource_recommender.search_resources(search_query, "tools")
|
||||
if tools:
|
||||
st.info(f"🔍 找到 {len(tools)} 个匹配的工具")
|
||||
else:
|
||||
tools = resource_recommender.get_tools()
|
||||
|
||||
@@ -103,144 +96,77 @@ def render_tab_resources(storage, brand: str) -> None:
|
||||
categories[cat].append(tool)
|
||||
|
||||
for category, category_tools in categories.items():
|
||||
st.markdown(f"##### 📁 {category}")
|
||||
for i, tool in enumerate(category_tools, 1):
|
||||
st.markdown(f"**{category}**")
|
||||
for tool in category_tools:
|
||||
with st.container(border=True):
|
||||
col1, col2 = st.columns([3, 1])
|
||||
with col1:
|
||||
st.markdown(f"**{tool['name']}** {tool.get('rating', '')}")
|
||||
with col2:
|
||||
if tool.get('url'):
|
||||
st.markdown(f"[🔗 访问]({tool['url']})")
|
||||
st.link_button("访问", tool['url'], use_container_width=True)
|
||||
|
||||
st.markdown(f"*{tool['description']}*")
|
||||
st.caption(tool['description'])
|
||||
|
||||
if tool.get('features'):
|
||||
st.markdown("**功能**:")
|
||||
features_text = " | ".join([f"✓ {f}" for f in tool['features']])
|
||||
st.markdown(features_text)
|
||||
|
||||
if tool.get('url'):
|
||||
st.markdown(f"**链接**:{tool['url']}")
|
||||
features_text = " · ".join([f"✓ {f}" for f in tool['features']])
|
||||
st.markdown(f"<small>{features_text}</small>", unsafe_allow_html=True)
|
||||
else:
|
||||
st.info("💡 暂无匹配的工具资源。尝试使用其他关键词搜索。")
|
||||
st.info("💡 暂无匹配的工具,尝试其他关键词搜索。")
|
||||
|
||||
# 论文/指南
|
||||
with resource_tab3:
|
||||
st.markdown("#### 📄 论文/指南")
|
||||
st.caption("GEO 相关的论文、指南、文档,深入学习 GEO 策略")
|
||||
|
||||
if search_query:
|
||||
papers = resource_recommender.search_resources(search_query, "papers")
|
||||
if papers:
|
||||
st.info(f"🔍 找到 {len(papers)} 个匹配的论文/指南")
|
||||
else:
|
||||
papers = resource_recommender.get_papers()
|
||||
|
||||
if papers:
|
||||
# 按重要性排序
|
||||
# 按重要性分组显示
|
||||
importance_order = {"高": 3, "中": 2, "低": 1}
|
||||
papers_sorted = sorted(papers, key=lambda x: importance_order.get(x.get('importance', '低'), 1), reverse=True)
|
||||
|
||||
# 按重要性分组显示
|
||||
high_importance = [p for p in papers_sorted if p.get('importance') == '高']
|
||||
medium_importance = [p for p in papers_sorted if p.get('importance') == '中']
|
||||
low_importance = [p for p in papers_sorted if p.get('importance') == '低']
|
||||
importance_groups = {
|
||||
"🔥 必读": [p for p in papers_sorted if p.get('importance') == '高'],
|
||||
"⭐ 推荐": [p for p in papers_sorted if p.get('importance') == '中'],
|
||||
}
|
||||
|
||||
if high_importance:
|
||||
st.markdown("##### 🔥 高重要性(必读)")
|
||||
for paper in high_importance:
|
||||
with st.container(border=True):
|
||||
st.markdown(f"**🔥 {paper['title']}**")
|
||||
st.markdown(f"*{paper['description']}*")
|
||||
st.markdown(f"**分类**:{paper.get('category', 'N/A')} | **日期**:{paper.get('date', 'N/A')}")
|
||||
if paper.get('url'):
|
||||
st.markdown(f"🔗 [{paper['url']}]({paper['url']})")
|
||||
|
||||
if medium_importance:
|
||||
st.markdown("##### ⭐ 中重要性(推荐阅读)")
|
||||
for paper in medium_importance:
|
||||
with st.container(border=True):
|
||||
st.markdown(f"**⭐ {paper['title']}**")
|
||||
st.markdown(f"*{paper['description']}*")
|
||||
st.markdown(f"**分类**:{paper.get('category', 'N/A')} | **日期**:{paper.get('date', 'N/A')}")
|
||||
if paper.get('url'):
|
||||
st.markdown(f"🔗 [{paper['url']}]({paper['url']})")
|
||||
|
||||
if low_importance:
|
||||
st.markdown("##### 📌 低重要性(参考阅读)")
|
||||
for paper in low_importance:
|
||||
with st.container(border=True):
|
||||
st.markdown(f"**📌 {paper['title']}**")
|
||||
st.markdown(f"*{paper['description']}*")
|
||||
st.markdown(f"**分类**:{paper.get('category', 'N/A')} | **日期**:{paper.get('date', 'N/A')}")
|
||||
if paper.get('url'):
|
||||
st.markdown(f"🔗 [{paper['url']}]({paper['url']})")
|
||||
for group_name, group_papers in importance_groups.items():
|
||||
if group_papers:
|
||||
st.markdown(f"**{group_name}**")
|
||||
for paper in group_papers:
|
||||
with st.container(border=True):
|
||||
st.markdown(f"**{paper['title']}**")
|
||||
st.caption(paper['description'])
|
||||
meta = f"分类:{paper.get('category', 'N/A')} · 日期:{paper.get('date', 'N/A')}"
|
||||
st.markdown(f"<small>{meta}</small>", unsafe_allow_html=True)
|
||||
if paper.get('url'):
|
||||
st.link_button("查看", paper['url'], use_container_width=True)
|
||||
else:
|
||||
st.info("💡 暂无匹配的论文/指南资源。尝试使用其他关键词搜索。")
|
||||
st.info("💡 暂无匹配的论文/指南,尝试其他关键词搜索。")
|
||||
|
||||
# 社区资源
|
||||
with resource_tab4:
|
||||
st.markdown("#### 👥 社区资源")
|
||||
st.caption("GEO 相关的社区和论坛,与其他用户交流经验")
|
||||
|
||||
if search_query:
|
||||
communities = resource_recommender.search_resources(search_query, "communities")
|
||||
if communities:
|
||||
st.info(f"🔍 找到 {len(communities)} 个匹配的社区")
|
||||
else:
|
||||
communities = resource_recommender.get_communities()
|
||||
|
||||
if communities:
|
||||
for i, community in enumerate(communities, 1):
|
||||
for community in communities:
|
||||
with st.container(border=True):
|
||||
col1, col2 = st.columns([3, 1])
|
||||
with col1:
|
||||
st.markdown(f"##### {i}. {community['name']} {community.get('rating', '')}")
|
||||
st.markdown(f"**{community['name']}** {community.get('rating', '')}")
|
||||
with col2:
|
||||
if community.get('url'):
|
||||
st.markdown(f"[🔗 访问]({community['url']})")
|
||||
st.link_button("访问", community['url'], use_container_width=True)
|
||||
|
||||
st.markdown(f"*{community['description']}*")
|
||||
st.markdown(f"**分类**:{community.get('category', 'N/A')}")
|
||||
|
||||
if community.get('url'):
|
||||
st.markdown(f"**链接**:{community['url']}")
|
||||
st.caption(community['description'])
|
||||
st.markdown(f"<small>分类:{community.get('category', 'N/A')}</small>", unsafe_allow_html=True)
|
||||
else:
|
||||
st.info("💡 暂无匹配的社区资源。尝试使用其他关键词搜索。")
|
||||
|
||||
# 搜索结果显示(跨分类)
|
||||
if search_query:
|
||||
all_results = resource_recommender.search_resources(search_query)
|
||||
if all_results:
|
||||
st.markdown("---")
|
||||
st.markdown("#### 🔍 搜索结果汇总")
|
||||
st.info(f"共找到 {len(all_results)} 个匹配资源(跨所有分类)")
|
||||
|
||||
# 按类型分组显示
|
||||
results_by_type = {}
|
||||
for result in all_results:
|
||||
res_type = result.get('type', 'unknown')
|
||||
if res_type not in results_by_type:
|
||||
results_by_type[res_type] = []
|
||||
results_by_type[res_type].append(result)
|
||||
|
||||
type_names = {
|
||||
'agent': '🤖 代理服务',
|
||||
'tool': '🛠️ 工具',
|
||||
'paper': '📄 论文/指南',
|
||||
'community': '👥 社区'
|
||||
}
|
||||
|
||||
for res_type, results in results_by_type.items():
|
||||
if results:
|
||||
st.markdown(f"##### {type_names.get(res_type, res_type)} ({len(results)} 个)")
|
||||
for result in results:
|
||||
with st.container(border=True):
|
||||
name_key = 'name' if 'name' in result else 'title'
|
||||
st.markdown(f"**{result.get(name_key, 'N/A')}**")
|
||||
st.caption(result.get('description', ''))
|
||||
if result.get('url'):
|
||||
st.markdown(f"🔗 [{result['url']}]({result['url']})")
|
||||
|
||||
# =======================
|
||||
st.info("💡 暂无匹配的社区资源,尝试其他关键词搜索。")
|
||||
|
||||
Reference in New Issue
Block a user