Spaces:
Running
Running
Commit
·
3f327ed
1
Parent(s):
9d54244
fix: set token
Browse files
app.py
CHANGED
|
@@ -41,6 +41,7 @@ logger = logging.getLogger(__name__)
|
|
| 41 |
env = os.environ.get('COIN_ENV', 'local')
|
| 42 |
if env == 'hf':
|
| 43 |
config_fp = 'hf_config.yaml'
|
|
|
|
| 44 |
else:
|
| 45 |
config_fp = 'local_config.yaml'
|
| 46 |
logger.info(f'Use config file: {config_fp}')
|
|
@@ -57,15 +58,22 @@ RESIZED_TO_BEFORE_DETECT = total_config['detector'].get('resized_to', 300)
|
|
| 57 |
def prepare_chromadb():
|
| 58 |
if env == 'local':
|
| 59 |
return
|
|
|
|
| 60 |
from huggingface_hub import snapshot_download
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
|
| 64 |
def _load_dataset(data_path):
|
| 65 |
logger.info('Load dataset from %s', data_path)
|
| 66 |
|
| 67 |
if env == 'hf':
|
| 68 |
-
dataset = load_dataset(data_path, split='train')
|
| 69 |
else:
|
| 70 |
dataset = load_dataset("imagefolder", data_dir=data_path, split='train')
|
| 71 |
return dataset
|
|
@@ -107,8 +115,7 @@ def load_chroma_db(db_dir, collection_name, model_name, device='cpu'):
|
|
| 107 |
|
| 108 |
embedding_function = ChromaEmbeddingFunction(model_name, device)
|
| 109 |
collection = client.get_collection(
|
| 110 |
-
name=collection_name,
|
| 111 |
-
embedding_function=embedding_function,
|
| 112 |
)
|
| 113 |
return collection
|
| 114 |
|
|
@@ -211,13 +218,21 @@ def main():
|
|
| 211 |
with gr.Column(variant='compact', scale=1):
|
| 212 |
gr.Markdown('### Results from Coin-CLIP')
|
| 213 |
cc_results = gr.Gallery(
|
| 214 |
-
label='Coin-CLIP Results',
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
)
|
| 216 |
|
| 217 |
with gr.Column(variant='compact', scale=1):
|
| 218 |
gr.Markdown('### Results from CLIP')
|
| 219 |
coin_results = gr.Gallery(
|
| 220 |
-
label='CLIP Results',
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
)
|
| 222 |
|
| 223 |
sub_btn.click(
|
|
|
|
| 41 |
env = os.environ.get('COIN_ENV', 'local')
|
| 42 |
if env == 'hf':
|
| 43 |
config_fp = 'hf_config.yaml'
|
| 44 |
+
hf_token = os.environ.get('HF_TOKEN')
|
| 45 |
else:
|
| 46 |
config_fp = 'local_config.yaml'
|
| 47 |
logger.info(f'Use config file: {config_fp}')
|
|
|
|
| 58 |
def prepare_chromadb():
|
| 59 |
if env == 'local':
|
| 60 |
return
|
| 61 |
+
|
| 62 |
from huggingface_hub import snapshot_download
|
| 63 |
+
|
| 64 |
+
snapshot_download(
|
| 65 |
+
repo_type='model',
|
| 66 |
+
repo_id='breezedeus/usa-coins-chromadb',
|
| 67 |
+
local_dir='./',
|
| 68 |
+
token=hf_token,
|
| 69 |
+
)
|
| 70 |
|
| 71 |
|
| 72 |
def _load_dataset(data_path):
|
| 73 |
logger.info('Load dataset from %s', data_path)
|
| 74 |
|
| 75 |
if env == 'hf':
|
| 76 |
+
dataset = load_dataset(data_path, split='train', token=hf_token)
|
| 77 |
else:
|
| 78 |
dataset = load_dataset("imagefolder", data_dir=data_path, split='train')
|
| 79 |
return dataset
|
|
|
|
| 115 |
|
| 116 |
embedding_function = ChromaEmbeddingFunction(model_name, device)
|
| 117 |
collection = client.get_collection(
|
| 118 |
+
name=collection_name, embedding_function=embedding_function,
|
|
|
|
| 119 |
)
|
| 120 |
return collection
|
| 121 |
|
|
|
|
| 218 |
with gr.Column(variant='compact', scale=1):
|
| 219 |
gr.Markdown('### Results from Coin-CLIP')
|
| 220 |
cc_results = gr.Gallery(
|
| 221 |
+
label='Coin-CLIP Results',
|
| 222 |
+
columns=3,
|
| 223 |
+
height=2200,
|
| 224 |
+
show_share_button=True,
|
| 225 |
+
visible=False,
|
| 226 |
)
|
| 227 |
|
| 228 |
with gr.Column(variant='compact', scale=1):
|
| 229 |
gr.Markdown('### Results from CLIP')
|
| 230 |
coin_results = gr.Gallery(
|
| 231 |
+
label='CLIP Results',
|
| 232 |
+
columns=3,
|
| 233 |
+
height=2200,
|
| 234 |
+
show_share_button=True,
|
| 235 |
+
visible=False,
|
| 236 |
)
|
| 237 |
|
| 238 |
sub_btn.click(
|