Spaces:
Runtime error
Runtime error
shijianjian
commited on
Commit
•
24217e7
1
Parent(s):
41f0d41
init
Browse files- app.py +30 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import kornia
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
|
6 |
+
def image_to_grayscale(image, version, step_no):
|
7 |
+
image = kornia.utils.image_to_tensor(image, keepdim=False) / 255.
|
8 |
+
image = kornia.geometry.transform.resize(
|
9 |
+
image, 384, interpolation='bilinear', align_corners=None, side='short', antialias=False)
|
10 |
+
dissolved = kornia.filters.StableDiffusionDissolving(version)(image, int(step_no))
|
11 |
+
output = kornia.utils.tensor_to_image(dissolved)
|
12 |
+
return output
|
13 |
+
|
14 |
+
|
15 |
+
iface = gr.Interface(
|
16 |
+
fn=image_to_grayscale,
|
17 |
+
inputs=[
|
18 |
+
gr.Image(type="numpy"),
|
19 |
+
gr.Dropdown(
|
20 |
+
["2.1", "1.5", "1.4"], value="2.1", multiselect=False, label="Stable Diffusion Version"
|
21 |
+
),
|
22 |
+
gr.Number(value=500, minimum=0, precision=0, maximum=1000, label="Timestep No."),
|
23 |
+
],
|
24 |
+
outputs="image",
|
25 |
+
title="Dissolving Transformations with Stable Diffusion",
|
26 |
+
description="Dissolving transformation based on `Dissolving Is Amplifying: Towards Fine-Grained Anomaly Detection`. Original rep is https://github.com/shijianjian/DIA. It has been included in Kornia lib (https://kornia.readthedocs.io/en/latest/augmentation.module.html#kornia.augmentation.RandomDissolving). You may try by `kornia.filters.StableDiffusionDissolving(version)(image, step_no)`, or `kornia.augmentation.RandomDissolving()(image)`. In this demo, the images are downsampled for fast computation."
|
27 |
+
)
|
28 |
+
|
29 |
+
# Launch the Gradio app
|
30 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
kornia @ git+https://github.com/kornia/kornia@main
|