Upload 7 files
Browse files- README.md +22 -14
- app/app.py +14 -0
- crawler/crawler.py +24 -0
- data/filtered.json +1 -0
- data/raw.json +1 -0
- filter/filter.py +21 -0
- requirements.txt +1 -0
README.md
CHANGED
|
@@ -1,14 +1,22 @@
|
|
| 1 |
-
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Hugging Face Spaces - 个性化标签信息过滤展示 (演出预警)
|
| 2 |
+
|
| 3 |
+
## 功能说明
|
| 4 |
+
- 从本地模拟的大麦演出数据中筛选符合你兴趣标签的内容
|
| 5 |
+
- 展示匹配结果到网页(使用 Streamlit)
|
| 6 |
+
- 可部署到 Hugging Face Spaces
|
| 7 |
+
|
| 8 |
+
## 如何使用
|
| 9 |
+
1. `crawler/crawler.py` - 抓取大麦网(示例数据)
|
| 10 |
+
2. `filter/filter.py` - 过滤出与用户兴趣匹配的演出
|
| 11 |
+
3. `app/app.py` - Streamlit 展示页面
|
| 12 |
+
|
| 13 |
+
## 运行方法
|
| 14 |
+
```bash
|
| 15 |
+
pip install streamlit
|
| 16 |
+
python crawler/crawler.py
|
| 17 |
+
python filter/filter.py
|
| 18 |
+
streamlit run app/app.py
|
| 19 |
+
```
|
| 20 |
+
|
| 21 |
+
## 示例截图
|
| 22 |
+

|
app/app.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import json
|
| 3 |
+
|
| 4 |
+
st.set_page_config(page_title="我的兴趣演出预警", layout="wide")
|
| 5 |
+
st.title("🎵 我的标签匹配演出信息")
|
| 6 |
+
|
| 7 |
+
with open("data/filtered.json", "r", encoding="utf-8") as f:
|
| 8 |
+
events = json.load(f)
|
| 9 |
+
|
| 10 |
+
for event in events:
|
| 11 |
+
st.markdown(f"### {event['title']}")
|
| 12 |
+
st.write(f"📍 地点: {event['location']} | 📅 时间: {event['date']}")
|
| 13 |
+
st.markdown(f"[🔗 查看详情]({event['url']})")
|
| 14 |
+
st.markdown("---")
|
crawler/crawler.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🚧 Placeholder: 此处应使用 playwright/scrapy 抓取大麦网信息
|
| 2 |
+
# 示例结构如下
|
| 3 |
+
|
| 4 |
+
import json
|
| 5 |
+
|
| 6 |
+
example_data = [
|
| 7 |
+
{
|
| 8 |
+
"title": "万能青年旅店2025巡演 - 北京站",
|
| 9 |
+
"date": "2025-07-12",
|
| 10 |
+
"location": "北京 糖果Live",
|
| 11 |
+
"url": "https://detail.damai.cn/example1"
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"title": "另一个艺人 - 上海演唱会",
|
| 15 |
+
"date": "2025-07-22",
|
| 16 |
+
"location": "上海 虹口剧场",
|
| 17 |
+
"url": "https://detail.damai.cn/example2"
|
| 18 |
+
}
|
| 19 |
+
]
|
| 20 |
+
|
| 21 |
+
with open("data/raw.json", "w", encoding="utf-8") as f:
|
| 22 |
+
json.dump(example_data, f, ensure_ascii=False, indent=2)
|
| 23 |
+
|
| 24 |
+
print("✅ 示例数据已写入 data/raw.json")
|
data/filtered.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
[]
|
data/raw.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
[]
|
filter/filter.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
|
| 3 |
+
def is_relevant(event, tags, location="北京"):
|
| 4 |
+
title = event["title"].lower()
|
| 5 |
+
loc = event["location"]
|
| 6 |
+
if location not in loc:
|
| 7 |
+
return False
|
| 8 |
+
return any(tag.lower() in title for tag in tags)
|
| 9 |
+
|
| 10 |
+
def filter_events(input_file, output_file, tags):
|
| 11 |
+
with open(input_file, "r", encoding="utf-8") as f:
|
| 12 |
+
events = json.load(f)
|
| 13 |
+
|
| 14 |
+
filtered = [e for e in events if is_relevant(e, tags)]
|
| 15 |
+
|
| 16 |
+
with open(output_file, "w", encoding="utf-8") as f:
|
| 17 |
+
json.dump(filtered, f, ensure_ascii=False, indent=2)
|
| 18 |
+
|
| 19 |
+
if __name__ == "__main__":
|
| 20 |
+
TAGS = ["万能青年旅店", "演唱会", "后摇"]
|
| 21 |
+
filter_events("data/raw.json", "data/filtered.json", TAGS)
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
streamlit
|