Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,15 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
from diffusers import AutoencoderKL
|
| 4 |
-
from PIL import Image
|
| 5 |
import torchvision.transforms.v2 as transforms
|
| 6 |
from torchvision.io import read_image
|
| 7 |
from typing import Tuple, Dict, List
|
|
|
|
|
|
|
| 8 |
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
class VAETester:
|
| 11 |
def __init__(self, device: str = "cuda" if torch.cuda.is_available() else "cpu"):
|
|
@@ -43,7 +47,7 @@ class VAETester:
|
|
| 43 |
def process_image(self,
|
| 44 |
img: torch.Tensor,
|
| 45 |
vae: AutoencoderKL,
|
| 46 |
-
tolerance: float)
|
| 47 |
"""Process image through a single VAE"""
|
| 48 |
img_transformed = self.input_transform(img).to(self.device).unsqueeze(0)
|
| 49 |
original_base = self.base_transform(img).cpu()
|
|
@@ -67,7 +71,7 @@ class VAETester:
|
|
| 67 |
|
| 68 |
def process_all_models(self,
|
| 69 |
img: torch.Tensor,
|
| 70 |
-
tolerance: float)
|
| 71 |
"""Process image through all loaded VAEs"""
|
| 72 |
results = {}
|
| 73 |
for name, vae in self.vae_models.items():
|
|
@@ -80,7 +84,7 @@ class VAETester:
|
|
| 80 |
tester = VAETester()
|
| 81 |
|
| 82 |
|
| 83 |
-
def test_all_vaes(image_path: str, tolerance: float)
|
| 84 |
"""Gradio interface function to test all VAEs"""
|
| 85 |
try:
|
| 86 |
img_tensor = read_image(image_path)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
from diffusers import AutoencoderKL
|
|
|
|
| 4 |
import torchvision.transforms.v2 as transforms
|
| 5 |
from torchvision.io import read_image
|
| 6 |
from typing import Tuple, Dict, List
|
| 7 |
+
import os
|
| 8 |
+
from huggingface_hub import login
|
| 9 |
|
| 10 |
+
# Get token from environment variable
|
| 11 |
+
hf_token = os.getenv("HF_TOKEN")
|
| 12 |
+
login(token=hf_token)
|
| 13 |
|
| 14 |
class VAETester:
|
| 15 |
def __init__(self, device: str = "cuda" if torch.cuda.is_available() else "cpu"):
|
|
|
|
| 47 |
def process_image(self,
|
| 48 |
img: torch.Tensor,
|
| 49 |
vae: AutoencoderKL,
|
| 50 |
+
tolerance: float):
|
| 51 |
"""Process image through a single VAE"""
|
| 52 |
img_transformed = self.input_transform(img).to(self.device).unsqueeze(0)
|
| 53 |
original_base = self.base_transform(img).cpu()
|
|
|
|
| 71 |
|
| 72 |
def process_all_models(self,
|
| 73 |
img: torch.Tensor,
|
| 74 |
+
tolerance: float):
|
| 75 |
"""Process image through all loaded VAEs"""
|
| 76 |
results = {}
|
| 77 |
for name, vae in self.vae_models.items():
|
|
|
|
| 84 |
tester = VAETester()
|
| 85 |
|
| 86 |
|
| 87 |
+
def test_all_vaes(image_path: str, tolerance: float):
|
| 88 |
"""Gradio interface function to test all VAEs"""
|
| 89 |
try:
|
| 90 |
img_tensor = read_image(image_path)
|