Spaces:
Running on Zero
Running on Zero
SpaceCatNugget commited on
Commit ·
3f7bc7c
1
Parent(s): 2d71bf3
zerogpu support + gradio fix
Browse files- app.py +20 -4
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -9,12 +9,27 @@ import requests
|
|
| 9 |
from io import BytesIO
|
| 10 |
from pathlib import Path
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
import gradio as gr
|
| 13 |
from PIL import Image
|
| 14 |
from huggingface_hub import hf_hub_download
|
| 15 |
-
from dotenv import load_dotenv
|
| 16 |
-
|
| 17 |
-
load_dotenv()
|
| 18 |
|
| 19 |
# ---------------------------------------------------------------------------
|
| 20 |
# Paths — use /data (persistent storage) if available, else /home/user
|
|
@@ -157,6 +172,7 @@ def setup():
|
|
| 157 |
# ---------------------------------------------------------------------------
|
| 158 |
# Inference
|
| 159 |
# ---------------------------------------------------------------------------
|
|
|
|
| 160 |
def generate(target_img, clothing_img, progress=gr.Progress(track_tqdm=True)):
|
| 161 |
if target_img is None or clothing_img is None:
|
| 162 |
raise gr.Error("Please upload both images before generating.")
|
|
@@ -281,7 +297,7 @@ with gr.Blocks(title="Cloth Swap", theme=gr.themes.Soft()) as demo:
|
|
| 281 |
clothing_input = gr.Image(label="Clothing reference", type="numpy", height=400)
|
| 282 |
btn = gr.Button("✨ Generate", variant="primary", size="lg")
|
| 283 |
output = gr.Image(label="Result", height=500)
|
| 284 |
-
gr.Markdown("*Generation takes ~1–2 minutes
|
| 285 |
|
| 286 |
btn.click(
|
| 287 |
fn=generate,
|
|
|
|
| 9 |
from io import BytesIO
|
| 10 |
from pathlib import Path
|
| 11 |
|
| 12 |
+
# Load .env for local development (ignored if not installed / not present)
|
| 13 |
+
try:
|
| 14 |
+
from dotenv import load_dotenv
|
| 15 |
+
load_dotenv()
|
| 16 |
+
except ImportError:
|
| 17 |
+
pass
|
| 18 |
+
|
| 19 |
+
# Compatibility shim — newer huggingface_hub removed HfFolder which old gradio needs
|
| 20 |
+
import huggingface_hub as _hfhub
|
| 21 |
+
if not hasattr(_hfhub, "HfFolder"):
|
| 22 |
+
class _HfFolder:
|
| 23 |
+
@staticmethod
|
| 24 |
+
def get_token(): return _hfhub.get_token()
|
| 25 |
+
@staticmethod
|
| 26 |
+
def save_token(token): pass
|
| 27 |
+
_hfhub.HfFolder = _HfFolder
|
| 28 |
+
|
| 29 |
+
import spaces
|
| 30 |
import gradio as gr
|
| 31 |
from PIL import Image
|
| 32 |
from huggingface_hub import hf_hub_download
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
# ---------------------------------------------------------------------------
|
| 35 |
# Paths — use /data (persistent storage) if available, else /home/user
|
|
|
|
| 172 |
# ---------------------------------------------------------------------------
|
| 173 |
# Inference
|
| 174 |
# ---------------------------------------------------------------------------
|
| 175 |
+
@spaces.GPU(duration=180)
|
| 176 |
def generate(target_img, clothing_img, progress=gr.Progress(track_tqdm=True)):
|
| 177 |
if target_img is None or clothing_img is None:
|
| 178 |
raise gr.Error("Please upload both images before generating.")
|
|
|
|
| 297 |
clothing_input = gr.Image(label="Clothing reference", type="numpy", height=400)
|
| 298 |
btn = gr.Button("✨ Generate", variant="primary", size="lg")
|
| 299 |
output = gr.Image(label="Result", height=500)
|
| 300 |
+
gr.Markdown("*Generation takes ~1–2 minutes.*")
|
| 301 |
|
| 302 |
btn.click(
|
| 303 |
fn=generate,
|
requirements.txt
CHANGED
|
@@ -1,2 +1,3 @@
|
|
| 1 |
requests
|
| 2 |
Pillow
|
|
|
|
|
|
| 1 |
requests
|
| 2 |
Pillow
|
| 3 |
+
python-dotenv
|