SalexAI commited on
Commit
58ed042
·
verified ·
1 Parent(s): 5afa13e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -1
app.py CHANGED
@@ -37,6 +37,19 @@ if not ADMIN_TOKEN:
37
  if not GOOGLE_KEY:
38
  print("⚠️ WARNING: GOOGLE_KEY not set")
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  # ==================================================
41
  # HF DATASET COMMIT SCHEDULER
42
  # ==================================================
@@ -83,7 +96,23 @@ def require_admin(token: str):
83
  @app.get("/imageget/{tour}.json")
84
  async def get_images(tour: str):
85
  path = tour_path(tour)
86
- return load_json(path)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
 
88
  # ==================================================
89
  # UPLOAD IMAGE
 
37
  if not GOOGLE_KEY:
38
  print("⚠️ WARNING: GOOGLE_KEY not set")
39
 
40
+ HF_RAW_BASE = "https://huggingface.co/datasets/SalexAI/mztimgs/raw/main/data"
41
+
42
+ async def fetch_from_hf(tour: str) -> dict | None:
43
+ url = f"{HF_RAW_BASE}/{tour}.json"
44
+
45
+ async with httpx.AsyncClient(timeout=15) as client:
46
+ r = await client.get(url)
47
+
48
+ if r.status_code != 200:
49
+ return None
50
+
51
+ return r.json()
52
+
53
  # ==================================================
54
  # HF DATASET COMMIT SCHEDULER
55
  # ==================================================
 
96
  @app.get("/imageget/{tour}.json")
97
  async def get_images(tour: str):
98
  path = tour_path(tour)
99
+
100
+ # 1) If exists locally → return it
101
+ if path.exists():
102
+ return load_json(path)
103
+
104
+ # 2) Otherwise fetch from HuggingFace
105
+ data = await fetch_from_hf(tour)
106
+
107
+ if data is None:
108
+ # Not found anywhere → return empty structure
109
+ return empty_structure()
110
+
111
+ # 3) Cache it locally for next time
112
+ save_json(path, data)
113
+
114
+ return data
115
+
116
 
117
  # ==================================================
118
  # UPLOAD IMAGE