Spaces:
Sleeping
Sleeping
Commit ·
3ef914c
1
Parent(s): 4021f7e
HF examples folder
Browse files- planparser/app.py +14 -3
planparser/app.py
CHANGED
|
@@ -10,6 +10,7 @@ import gradio as gr
|
|
| 10 |
import requests
|
| 11 |
import pandas as pd
|
| 12 |
from PIL import Image, ImageDraw
|
|
|
|
| 13 |
from dotenv import load_dotenv
|
| 14 |
|
| 15 |
load_dotenv()
|
|
@@ -60,11 +61,21 @@ CLASS_NAME_MAP = {
|
|
| 60 |
def _collect_example_images(max_n: int = 30) -> list[str]:
|
| 61 |
if not EXAMPLES_DIR:
|
| 62 |
return []
|
|
|
|
| 63 |
p = Path(EXAMPLES_DIR).expanduser().resolve()
|
| 64 |
-
if not p.exists() or not p.is_dir():
|
| 65 |
-
return []
|
| 66 |
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
files = [f for f in p.rglob("*") if f.is_file() and f.suffix.lower() in exts]
|
| 69 |
if not files:
|
| 70 |
return []
|
|
|
|
| 10 |
import requests
|
| 11 |
import pandas as pd
|
| 12 |
from PIL import Image, ImageDraw
|
| 13 |
+
from huggingface_hub import snapshot_download
|
| 14 |
from dotenv import load_dotenv
|
| 15 |
|
| 16 |
load_dotenv()
|
|
|
|
| 61 |
def _collect_example_images(max_n: int = 30) -> list[str]:
|
| 62 |
if not EXAMPLES_DIR:
|
| 63 |
return []
|
| 64 |
+
|
| 65 |
p = Path(EXAMPLES_DIR).expanduser().resolve()
|
|
|
|
|
|
|
| 66 |
|
| 67 |
+
# if not a local folder, assume the dataset repo_id
|
| 68 |
+
if not (p.exists() and p.is_dir()):
|
| 69 |
+
local = snapshot_download(
|
| 70 |
+
repo_id=EXAMPLES_DIR.strip(),
|
| 71 |
+
repo_type="dataset",
|
| 72 |
+
allow_patterns=["*.jpg"],
|
| 73 |
+
local_dir="/tmp/examples_ds",
|
| 74 |
+
local_dir_use_symlinks=False,
|
| 75 |
+
)
|
| 76 |
+
p = Path(local)
|
| 77 |
+
|
| 78 |
+
exts = (".jpg")
|
| 79 |
files = [f for f in p.rglob("*") if f.is_file() and f.suffix.lower() in exts]
|
| 80 |
if not files:
|
| 81 |
return []
|