Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,6 +19,11 @@ if not REPO_ID:
|
|
| 19 |
if not HF_TOKEN:
|
| 20 |
raise RuntimeError("HF_TOKEN environment variable is not set")
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
# =========================================================
|
| 24 |
# HELPERS
|
|
@@ -100,7 +105,6 @@ def collect_stories():
|
|
| 100 |
elif "/images/" in lower and lower.endswith((".png", ".jpg", ".jpeg", ".webp")):
|
| 101 |
stories[folder]["image_paths"].append(path)
|
| 102 |
|
| 103 |
-
# sort images naturally
|
| 104 |
for _, story in stories.items():
|
| 105 |
story["image_paths"] = sorted(
|
| 106 |
story["image_paths"],
|
|
@@ -110,7 +114,6 @@ def collect_stories():
|
|
| 110 |
]
|
| 111 |
)
|
| 112 |
|
| 113 |
-
# newest first
|
| 114 |
sorted_stories = sorted(
|
| 115 |
stories.values(),
|
| 116 |
key=lambda x: x["timestamp"],
|
|
@@ -135,6 +138,7 @@ def download_markdown(path: str) -> str:
|
|
| 135 |
filename=path,
|
| 136 |
repo_type=REPO_TYPE,
|
| 137 |
token=HF_TOKEN,
|
|
|
|
| 138 |
)
|
| 139 |
with open(local_path, "r", encoding="utf-8") as f:
|
| 140 |
return f.read()
|
|
@@ -151,6 +155,7 @@ def download_repo_file(path: str):
|
|
| 151 |
filename=path,
|
| 152 |
repo_type=REPO_TYPE,
|
| 153 |
token=HF_TOKEN,
|
|
|
|
| 154 |
)
|
| 155 |
except Exception as e:
|
| 156 |
print(f"[DOWNLOAD ERROR] {path}: {e}")
|
|
@@ -180,13 +185,8 @@ def load_story(folder_name: str):
|
|
| 180 |
)
|
| 181 |
|
| 182 |
story_md = download_markdown(story["markdown_path"])
|
| 183 |
-
|
| 184 |
-
# IMPORTANT:
|
| 185 |
-
# pass LOCAL FILE PATHS to Gradio, not HF resolve URLs
|
| 186 |
video_value = download_repo_file(story["video_path"]) if story["video_path"] else None
|
| 187 |
gallery_value = download_repo_images(story["image_paths"])
|
| 188 |
-
|
| 189 |
-
# only text changed from dataset.csv -> Theme
|
| 190 |
theme_text = "Theme" if story["csv_path"] else "No Theme"
|
| 191 |
|
| 192 |
return (
|
|
|
|
| 19 |
if not HF_TOKEN:
|
| 20 |
raise RuntimeError("HF_TOKEN environment variable is not set")
|
| 21 |
|
| 22 |
+
# IMPORTANT:
|
| 23 |
+
# Gradio accepts files from /tmp, so force HF downloads there
|
| 24 |
+
LOCAL_CACHE_DIR = "/tmp/story_showcase"
|
| 25 |
+
os.makedirs(LOCAL_CACHE_DIR, exist_ok=True)
|
| 26 |
+
|
| 27 |
|
| 28 |
# =========================================================
|
| 29 |
# HELPERS
|
|
|
|
| 105 |
elif "/images/" in lower and lower.endswith((".png", ".jpg", ".jpeg", ".webp")):
|
| 106 |
stories[folder]["image_paths"].append(path)
|
| 107 |
|
|
|
|
| 108 |
for _, story in stories.items():
|
| 109 |
story["image_paths"] = sorted(
|
| 110 |
story["image_paths"],
|
|
|
|
| 114 |
]
|
| 115 |
)
|
| 116 |
|
|
|
|
| 117 |
sorted_stories = sorted(
|
| 118 |
stories.values(),
|
| 119 |
key=lambda x: x["timestamp"],
|
|
|
|
| 138 |
filename=path,
|
| 139 |
repo_type=REPO_TYPE,
|
| 140 |
token=HF_TOKEN,
|
| 141 |
+
local_dir=LOCAL_CACHE_DIR,
|
| 142 |
)
|
| 143 |
with open(local_path, "r", encoding="utf-8") as f:
|
| 144 |
return f.read()
|
|
|
|
| 155 |
filename=path,
|
| 156 |
repo_type=REPO_TYPE,
|
| 157 |
token=HF_TOKEN,
|
| 158 |
+
local_dir=LOCAL_CACHE_DIR,
|
| 159 |
)
|
| 160 |
except Exception as e:
|
| 161 |
print(f"[DOWNLOAD ERROR] {path}: {e}")
|
|
|
|
| 185 |
)
|
| 186 |
|
| 187 |
story_md = download_markdown(story["markdown_path"])
|
|
|
|
|
|
|
|
|
|
| 188 |
video_value = download_repo_file(story["video_path"]) if story["video_path"] else None
|
| 189 |
gallery_value = download_repo_images(story["image_paths"])
|
|
|
|
|
|
|
| 190 |
theme_text = "Theme" if story["csv_path"] else "No Theme"
|
| 191 |
|
| 192 |
return (
|