Spaces:
Running
Running
Commit ·
faf5e01
1
Parent(s): 522ed11
Fix: Remove thumbnail logic, robust sync script, and add QR generator
Browse files- app.py +5 -3
- scripts/gen_qr.py +11 -0
- scripts/sync_data.py +27 -10
app.py
CHANGED
|
@@ -13,7 +13,7 @@ import mimetypes
|
|
| 13 |
import requests
|
| 14 |
try:
|
| 15 |
from dotenv import load_dotenv
|
| 16 |
-
load_dotenv(
|
| 17 |
except ImportError:
|
| 18 |
pass
|
| 19 |
|
|
@@ -98,12 +98,14 @@ class SyncManager:
|
|
| 98 |
|
| 99 |
# Initialize Sync Manager
|
| 100 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
|
|
|
|
|
|
| 101 |
HF_DB_REPO = os.getenv("HF_DB_REPO", "duqing2026/project-show-data")
|
| 102 |
sync_manager = SyncManager(HF_DB_REPO, HF_TOKEN, DATA_DIR)
|
| 103 |
|
| 104 |
PROJECT_TYPES = [
|
| 105 |
-
{"key": "rag", "label": "RAG 系统", "gradient": "linear-gradient(135deg, #2563eb, #06b6d4)"},
|
| 106 |
{"key": "prjprt", "label": "项目实战", "gradient": "linear-gradient(135deg, #7c3aed, #c026d3)"},
|
|
|
|
| 107 |
{"key": "commerce", "label": "电商", "gradient": "linear-gradient(135deg, #ea580c, #f59e0b)"},
|
| 108 |
{"key": "game", "label": "游戏", "gradient": "linear-gradient(135deg, #059669, #34d399)"},
|
| 109 |
{"key": "static", "label": "静态网页", "gradient": "linear-gradient(135deg, #475569, #94a3b8)"},
|
|
@@ -992,7 +994,7 @@ class ShowcaseHandler(BaseHTTPRequestHandler):
|
|
| 992 |
await deleteProjectById(state.editingId);
|
| 993 |
}
|
| 994 |
|
| 995 |
-
const p = { name: name, ptypes: state.newProjectTypes, hf_space_url: document.getElementById("p-hf").value.trim(),
|
| 996 |
await fetch("/api/projects/add", { method:"POST", headers:{ "Content-Type":"application/json" }, body: JSON.stringify(p) });
|
| 997 |
load();
|
| 998 |
state.editingId = null;
|
|
|
|
| 13 |
import requests
|
| 14 |
try:
|
| 15 |
from dotenv import load_dotenv
|
| 16 |
+
load_dotenv()
|
| 17 |
except ImportError:
|
| 18 |
pass
|
| 19 |
|
|
|
|
| 98 |
|
| 99 |
# Initialize Sync Manager
|
| 100 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 101 |
+
if not HF_TOKEN:
|
| 102 |
+
print("WARNING: HF_TOKEN not found in environment!")
|
| 103 |
HF_DB_REPO = os.getenv("HF_DB_REPO", "duqing2026/project-show-data")
|
| 104 |
sync_manager = SyncManager(HF_DB_REPO, HF_TOKEN, DATA_DIR)
|
| 105 |
|
| 106 |
PROJECT_TYPES = [
|
|
|
|
| 107 |
{"key": "prjprt", "label": "项目实战", "gradient": "linear-gradient(135deg, #7c3aed, #c026d3)"},
|
| 108 |
+
{"key": "rag", "label": "RAG 系统", "gradient": "linear-gradient(135deg, #2563eb, #06b6d4)"},
|
| 109 |
{"key": "commerce", "label": "电商", "gradient": "linear-gradient(135deg, #ea580c, #f59e0b)"},
|
| 110 |
{"key": "game", "label": "游戏", "gradient": "linear-gradient(135deg, #059669, #34d399)"},
|
| 111 |
{"key": "static", "label": "静态网页", "gradient": "linear-gradient(135deg, #475569, #94a3b8)"},
|
|
|
|
| 994 |
await deleteProjectById(state.editingId);
|
| 995 |
}
|
| 996 |
|
| 997 |
+
const p = { name: name, ptypes: state.newProjectTypes, hf_space_url: document.getElementById("p-hf").value.trim(), keywords: document.getElementById("p-keywords").value, description: document.getElementById("p-desc").value };
|
| 998 |
await fetch("/api/projects/add", { method:"POST", headers:{ "Content-Type":"application/json" }, body: JSON.stringify(p) });
|
| 999 |
load();
|
| 1000 |
state.editingId = null;
|
scripts/gen_qr.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from PIL import Image, ImageDraw, ImageFont
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
# Create a simple image
|
| 5 |
+
img = Image.new('RGB', (200, 200), color = (255, 255, 255))
|
| 6 |
+
d = ImageDraw.Draw(img)
|
| 7 |
+
d.text((10,90), "QR Code Missing", fill=(0,0,0))
|
| 8 |
+
|
| 9 |
+
os.makedirs("hf_project_showcase_data/images", exist_ok=True)
|
| 10 |
+
img.save('hf_project_showcase_data/images/pay-qr.png')
|
| 11 |
+
print("Generated placeholder pay-qr.png")
|
scripts/sync_data.py
CHANGED
|
@@ -1,18 +1,35 @@
|
|
| 1 |
import sys
|
| 2 |
import os
|
|
|
|
|
|
|
| 3 |
|
| 4 |
# Add project root to sys.path
|
| 5 |
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
if __name__ == "__main__":
|
| 10 |
-
print("Starting manual sync
|
| 11 |
-
if not
|
| 12 |
-
print("
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import sys
|
| 2 |
import os
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
|
| 6 |
# Add project root to sys.path
|
| 7 |
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 8 |
|
| 9 |
+
# Load env explicitly
|
| 10 |
+
load_dotenv(override=True)
|
| 11 |
+
|
| 12 |
+
from app import SyncManager
|
| 13 |
+
|
| 14 |
+
DATA_DIR = Path("hf_project_showcase_data")
|
| 15 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 16 |
+
HF_DB_REPO = os.getenv("HF_DB_REPO", "duqing2026/project-show-data")
|
| 17 |
|
| 18 |
if __name__ == "__main__":
|
| 19 |
+
print("Starting manual sync...")
|
| 20 |
+
if not HF_TOKEN:
|
| 21 |
+
print("Error: HF_TOKEN not found.")
|
| 22 |
+
sys.exit(1)
|
| 23 |
+
|
| 24 |
+
manager = SyncManager(HF_DB_REPO, HF_TOKEN, DATA_DIR)
|
| 25 |
+
|
| 26 |
+
# 1. Pull first (to merge or avoid conflict, though here we prioritize local push for the image)
|
| 27 |
+
# Actually, if we want to fix the QR code, we should just push the file.
|
| 28 |
+
# But to be safe, let's just push.
|
| 29 |
+
|
| 30 |
+
print(f"Token: {HF_TOKEN[:4]}...")
|
| 31 |
+
try:
|
| 32 |
+
manager.push()
|
| 33 |
+
print("Sync completed successfully.")
|
| 34 |
+
except Exception as e:
|
| 35 |
+
print(f"Sync failed: {e}")
|