Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +11 -4
src/streamlit_app.py
CHANGED
@@ -5,22 +5,29 @@ from PIL import Image
|
|
5 |
import os
|
6 |
import numpy as np
|
7 |
import chromadb
|
|
|
8 |
import tempfile
|
|
|
9 |
|
10 |
-
#
|
11 |
-
|
|
|
|
|
12 |
|
13 |
-
|
|
|
|
|
14 |
for i in tqdm(range(50), desc="Downloading images"):
|
15 |
url = f"https://picsum.photos/seed/{i}/1024/768"
|
16 |
response = requests.get(url)
|
17 |
if response.status_code == 200:
|
18 |
-
with open(f"
|
19 |
f.write(response.content)
|
20 |
else:
|
21 |
print(f"Failed to download image {i+1}")
|
22 |
|
23 |
|
|
|
24 |
# ----- Setup -----
|
25 |
CACHE_DIR = tempfile.gettempdir()
|
26 |
CHROMA_PATH = os.path.join(CACHE_DIR, "chroma_db")
|
|
|
5 |
import os
|
6 |
import numpy as np
|
7 |
import chromadb
|
8 |
+
import requests
|
9 |
import tempfile
|
10 |
+
from tqdm import tqdm
|
11 |
|
12 |
+
# Get a temporary directory (automatically cleaned up after runtime ends)
|
13 |
+
temp_dir = tempfile.gettempdir()
|
14 |
+
demo_dir = os.path.join(temp_dir, "demo_images")
|
15 |
+
os.makedirs(demo_dir, exist_ok=True)
|
16 |
|
17 |
+
print(f"Saving images to: {demo_dir}")
|
18 |
+
|
19 |
+
# Download 50 high-resolution images (1024x768)
|
20 |
for i in tqdm(range(50), desc="Downloading images"):
|
21 |
url = f"https://picsum.photos/seed/{i}/1024/768"
|
22 |
response = requests.get(url)
|
23 |
if response.status_code == 200:
|
24 |
+
with open(os.path.join(demo_dir, f"img_{i+1:02}.jpg"), "wb") as f:
|
25 |
f.write(response.content)
|
26 |
else:
|
27 |
print(f"Failed to download image {i+1}")
|
28 |
|
29 |
|
30 |
+
|
31 |
# ----- Setup -----
|
32 |
CACHE_DIR = tempfile.gettempdir()
|
33 |
CHROMA_PATH = os.path.join(CACHE_DIR, "chroma_db")
|