Spaces:
Paused
Paused
Convert to ZeroGPU; Gradio 5.7 -> 6.29, Python 3.12, torch 2.9.1
Browse files- README.md +2 -1
- app.py +7 -3
- requirements.txt +6 -8
README.md
CHANGED
|
@@ -4,7 +4,8 @@ emoji: 🔥
|
|
| 4 |
colorFrom: yellow
|
| 5 |
colorTo: yellow
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: other
|
|
|
|
| 4 |
colorFrom: yellow
|
| 5 |
colorTo: yellow
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 6.29.0
|
| 8 |
+
python_version: "3.12"
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
license: other
|
app.py
CHANGED
|
@@ -5,7 +5,7 @@ from diffusers import AutoencoderKL, EulerDiscreteScheduler, UNet2DConditionMode
|
|
| 5 |
from esrgan_model import UpscalerESRGAN
|
| 6 |
import gradio as gr
|
| 7 |
from huggingface_hub import hf_hub_download
|
| 8 |
-
|
| 9 |
import torch
|
| 10 |
import torch.nn as nn
|
| 11 |
from torchvision.io import read_image
|
|
@@ -92,18 +92,21 @@ torch.cuda.empty_cache()
|
|
| 92 |
|
| 93 |
|
| 94 |
# Define image generation function
|
| 95 |
-
|
| 96 |
@torch.no_grad()
|
| 97 |
def generate_image(
|
| 98 |
input_image, seed: int = 42, guidance_scale: float = 2.0, num_inference_steps: int = 50, is_upscale: bool = False
|
| 99 |
):
|
|
|
|
|
|
|
|
|
|
| 100 |
# Configure scheduler
|
| 101 |
scheduler = EulerDiscreteScheduler.from_pretrained(path_scheduler)
|
| 102 |
scheduler.is_scale_input_called = True # suppress warning
|
| 103 |
scheduler.set_timesteps(num_inference_steps)
|
| 104 |
|
| 105 |
# Set seed for reproducibility
|
| 106 |
-
generator = torch.Generator(device=device).manual_seed(seed)
|
| 107 |
x = torch.randn(1, 4, 64, 64, generator=generator, device=device)
|
| 108 |
|
| 109 |
# Process input image
|
|
@@ -193,6 +196,7 @@ demo = gr.Interface(
|
|
| 193 |
examples=examples,
|
| 194 |
examples_per_page=4,
|
| 195 |
submit_btn="Generate",
|
|
|
|
| 196 |
)
|
| 197 |
|
| 198 |
demo.launch()
|
|
|
|
| 5 |
from esrgan_model import UpscalerESRGAN
|
| 6 |
import gradio as gr
|
| 7 |
from huggingface_hub import hf_hub_download
|
| 8 |
+
import spaces
|
| 9 |
import torch
|
| 10 |
import torch.nn as nn
|
| 11 |
from torchvision.io import read_image
|
|
|
|
| 92 |
|
| 93 |
|
| 94 |
# Define image generation function
|
| 95 |
+
@spaces.GPU(duration=40)
|
| 96 |
@torch.no_grad()
|
| 97 |
def generate_image(
|
| 98 |
input_image, seed: int = 42, guidance_scale: float = 2.0, num_inference_steps: int = 50, is_upscale: bool = False
|
| 99 |
):
|
| 100 |
+
if input_image is None:
|
| 101 |
+
raise gr.Error("Please upload an image.")
|
| 102 |
+
num_inference_steps = max(1, int(num_inference_steps))
|
| 103 |
# Configure scheduler
|
| 104 |
scheduler = EulerDiscreteScheduler.from_pretrained(path_scheduler)
|
| 105 |
scheduler.is_scale_input_called = True # suppress warning
|
| 106 |
scheduler.set_timesteps(num_inference_steps)
|
| 107 |
|
| 108 |
# Set seed for reproducibility
|
| 109 |
+
generator = torch.Generator(device=device).manual_seed(int(seed))
|
| 110 |
x = torch.randn(1, 4, 64, 64, generator=generator, device=device)
|
| 111 |
|
| 112 |
# Process input image
|
|
|
|
| 196 |
examples=examples,
|
| 197 |
examples_per_page=4,
|
| 198 |
submit_btn="Generate",
|
| 199 |
+
api_name="generate",
|
| 200 |
)
|
| 201 |
|
| 202 |
demo.launch()
|
requirements.txt
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 1 |
-
torch
|
| 2 |
-
torchvision
|
| 3 |
-
diffusers>=0.
|
| 4 |
-
transformers>=
|
| 5 |
-
|
| 6 |
-
spaces
|
| 7 |
-
huggingface-hub>=0.26.2
|
| 8 |
-
accelerate>=1.1.1
|
|
|
|
| 1 |
+
torch==2.9.1
|
| 2 |
+
torchvision==0.24.1
|
| 3 |
+
diffusers>=0.35
|
| 4 |
+
transformers>=5
|
| 5 |
+
accelerate
|
| 6 |
+
spaces
|
|
|
|
|
|