Spaces:
Paused
Paused
init
Browse files- Dockerfile +16 -0
- README.md +1 -3
- app.py +57 -0
- requirements.txt +7 -0
Dockerfile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.13-slim-bookworm
|
| 2 |
+
|
| 3 |
+
RUN useradd -m -u 1000 user
|
| 4 |
+
USER user
|
| 5 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
| 6 |
+
|
| 7 |
+
WORKDIR /app
|
| 8 |
+
|
| 9 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
| 10 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 11 |
+
|
| 12 |
+
COPY --chown=user . /app
|
| 13 |
+
|
| 14 |
+
EXPOSE 7860
|
| 15 |
+
|
| 16 |
+
CMD ["python", "app.py"]
|
README.md
CHANGED
|
@@ -6,6 +6,4 @@ colorTo: green
|
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
license: mit
|
| 9 |
-
---
|
| 10 |
-
|
| 11 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
license: mit
|
| 9 |
+
---
|
|
|
|
|
|
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import torch
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
from diffusers import AutoencoderTiny
|
| 6 |
+
from torchvision.transforms.functional import to_pil_image, center_crop, resize, to_tensor
|
| 7 |
+
|
| 8 |
+
device = 'cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu'
|
| 9 |
+
vae = None
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def get_model():
|
| 13 |
+
global vae
|
| 14 |
+
|
| 15 |
+
if vae is None:
|
| 16 |
+
model_id = "madebyollin/taesd"
|
| 17 |
+
vae = AutoencoderTiny.from_pretrained(model_id, safetensors=True).to(device)
|
| 18 |
+
return vae
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
@torch.no_grad()
|
| 22 |
+
def encode(image):
|
| 23 |
+
vae = get_model()
|
| 24 |
+
|
| 25 |
+
DIM = [512]
|
| 26 |
+
processed = center_crop(resize(image, DIM), DIM)
|
| 27 |
+
tensor = to_tensor(processed).unsqueeze(0).to(device)
|
| 28 |
+
latents = vae.encoder(tensor)
|
| 29 |
+
scaled = vae.scale_latents(latents).mul_(255).round_().byte()
|
| 30 |
+
return to_pil_image(scaled[0])
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
path = 'https://huggingface.co/buckets/ciCic/demo-purposes/resolve/images'
|
| 34 |
+
astronaut = f"{path}/6.png"
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def app():
|
| 38 |
+
return gr.Interface(encode,
|
| 39 |
+
gr.Image(type="pil",
|
| 40 |
+
label='512x512',
|
| 41 |
+
value=astronaut),
|
| 42 |
+
gr.Image(type="pil",
|
| 43 |
+
image_mode="RGBA",
|
| 44 |
+
label='64x64',
|
| 45 |
+
height=256,
|
| 46 |
+
width=256
|
| 47 |
+
),
|
| 48 |
+
examples=[
|
| 49 |
+
astronaut,
|
| 50 |
+
f"{path}/7.png",
|
| 51 |
+
f"{path}/34.png"
|
| 52 |
+
], flagging_mode='never', title='Image Encoder')
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
if __name__ == "__main__":
|
| 56 |
+
print("LAUNCHING")
|
| 57 |
+
app().launch(server_name="0.0.0.0", server_port=7860, share=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
torchvision
|
| 3 |
+
transformers
|
| 4 |
+
diffusers
|
| 5 |
+
pillow
|
| 6 |
+
accelerate
|
| 7 |
+
gradio==6.12.0
|