doosa.ganesh commited on
Commit ·
304725e
1
Parent(s): a4d5523
local support
Browse files- .env.example +6 -0
- .gitignore +3 -1
- app.py +18 -11
- requirements.txt +2 -1
.env.example
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Credentials for the app login
|
| 2 |
+
APP_USERNAME=admin
|
| 3 |
+
APP_PASSWORD=password
|
| 4 |
+
|
| 5 |
+
# Hugging Face token for downloading private/restricted data
|
| 6 |
+
HF_TOKEN=your_huggingface_token_here
|
.gitignore
CHANGED
|
@@ -11,4 +11,6 @@ __pycache__/
|
|
| 11 |
.gradio/
|
| 12 |
|
| 13 |
# Mac
|
| 14 |
-
.DS_Store
|
|
|
|
|
|
|
|
|
| 11 |
.gradio/
|
| 12 |
|
| 13 |
# Mac
|
| 14 |
+
.DS_Store
|
| 15 |
+
|
| 16 |
+
.env
|
app.py
CHANGED
|
@@ -3,7 +3,11 @@ import os
|
|
| 3 |
import json
|
| 4 |
import gradio as gr
|
| 5 |
import argparse
|
| 6 |
-
from huggingface_hub import snapshot_download
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
HF_DATA_REPO = "doosaganesh/virtual-tryon-data"
|
| 9 |
DATA_ROOT = None
|
|
@@ -34,6 +38,14 @@ def check_login(username, password):
|
|
| 34 |
def get_data_root():
|
| 35 |
global DATA_ROOT
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
if DATA_ROOT is None:
|
| 38 |
|
| 39 |
print("Downloading dataset from Hugging Face...")
|
|
@@ -225,16 +237,14 @@ def build_ui(site_id, person_image="source_models/female/asian/model_1.png"):
|
|
| 225 |
fn=go_prev,
|
| 226 |
inputs=[outfit_selector],
|
| 227 |
outputs=[outfit_selector],
|
| 228 |
-
queue=False
|
| 229 |
-
show_progress="hidden"
|
| 230 |
)
|
| 231 |
|
| 232 |
next_btn.click(
|
| 233 |
fn=go_next,
|
| 234 |
inputs=[outfit_selector],
|
| 235 |
outputs=[outfit_selector],
|
| 236 |
-
queue=False
|
| 237 |
-
show_progress="hidden"
|
| 238 |
)
|
| 239 |
|
| 240 |
def update_view(index):
|
|
@@ -275,24 +285,21 @@ def build_ui(site_id, person_image="source_models/female/asian/model_1.png"):
|
|
| 275 |
fn=update_view,
|
| 276 |
inputs=[outfit_selector],
|
| 277 |
outputs=[garments_gallery, result_img, review_radio, model_img, seed_prod_txt, seed_ext_txt],
|
| 278 |
-
queue=False
|
| 279 |
-
show_progress="hidden"
|
| 280 |
)
|
| 281 |
|
| 282 |
review_radio.change(
|
| 283 |
fn=on_review_change,
|
| 284 |
inputs=[outfit_selector, review_radio],
|
| 285 |
outputs=[],
|
| 286 |
-
queue=False
|
| 287 |
-
show_progress="hidden"
|
| 288 |
)
|
| 289 |
|
| 290 |
demo.load(
|
| 291 |
fn=update_view,
|
| 292 |
inputs=[outfit_selector],
|
| 293 |
outputs=[garments_gallery, result_img, review_radio, model_img, seed_prod_txt, seed_ext_txt],
|
| 294 |
-
queue=False
|
| 295 |
-
show_progress="hidden"
|
| 296 |
)
|
| 297 |
|
| 298 |
return demo
|
|
|
|
| 3 |
import json
|
| 4 |
import gradio as gr
|
| 5 |
import argparse
|
| 6 |
+
from huggingface_hub import hf_hub_download, snapshot_download
|
| 7 |
+
from dotenv import load_dotenv
|
| 8 |
+
|
| 9 |
+
# Load local .env file if it exists
|
| 10 |
+
load_dotenv()
|
| 11 |
|
| 12 |
HF_DATA_REPO = "doosaganesh/virtual-tryon-data"
|
| 13 |
DATA_ROOT = None
|
|
|
|
| 38 |
def get_data_root():
|
| 39 |
global DATA_ROOT
|
| 40 |
|
| 41 |
+
# Priority 1: Check if datasets folder exists locally in the project root
|
| 42 |
+
if os.path.exists("datasets"):
|
| 43 |
+
print("Using local datasets folder.")
|
| 44 |
+
return os.getcwd()
|
| 45 |
+
|
| 46 |
+
# Priority 2: Use tmp storage (standard for HF Spaces)
|
| 47 |
+
data_root = "/tmp/tryon-data"
|
| 48 |
+
|
| 49 |
if DATA_ROOT is None:
|
| 50 |
|
| 51 |
print("Downloading dataset from Hugging Face...")
|
|
|
|
| 237 |
fn=go_prev,
|
| 238 |
inputs=[outfit_selector],
|
| 239 |
outputs=[outfit_selector],
|
| 240 |
+
queue=False
|
|
|
|
| 241 |
)
|
| 242 |
|
| 243 |
next_btn.click(
|
| 244 |
fn=go_next,
|
| 245 |
inputs=[outfit_selector],
|
| 246 |
outputs=[outfit_selector],
|
| 247 |
+
queue=False
|
|
|
|
| 248 |
)
|
| 249 |
|
| 250 |
def update_view(index):
|
|
|
|
| 285 |
fn=update_view,
|
| 286 |
inputs=[outfit_selector],
|
| 287 |
outputs=[garments_gallery, result_img, review_radio, model_img, seed_prod_txt, seed_ext_txt],
|
| 288 |
+
queue=False
|
|
|
|
| 289 |
)
|
| 290 |
|
| 291 |
review_radio.change(
|
| 292 |
fn=on_review_change,
|
| 293 |
inputs=[outfit_selector, review_radio],
|
| 294 |
outputs=[],
|
| 295 |
+
queue=False
|
|
|
|
| 296 |
)
|
| 297 |
|
| 298 |
demo.load(
|
| 299 |
fn=update_view,
|
| 300 |
inputs=[outfit_selector],
|
| 301 |
outputs=[garments_gallery, result_img, review_radio, model_img, seed_prod_txt, seed_ext_txt],
|
| 302 |
+
queue=False
|
|
|
|
| 303 |
)
|
| 304 |
|
| 305 |
return demo
|
requirements.txt
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
gradio
|
| 2 |
huggingface_hub
|
| 3 |
requests
|
| 4 |
-
Pillow
|
|
|
|
|
|
| 1 |
gradio
|
| 2 |
huggingface_hub
|
| 3 |
requests
|
| 4 |
+
Pillow
|
| 5 |
+
python-dotenv
|