lenkahamosova prusnak commited on
Commit
5081673
0 Parent(s):

Duplicate from prusnak/troublinggan

Browse files

Co-authored-by: Pavol Rusnak <prusnak@users.noreply.huggingface.co>

.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
.gitmodules ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ [submodule "stylegan2"]
2
+ path = stylegan2
3
+ url = https://github.com/NVlabs/stylegan2-ada-pytorch.git
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Troublinggan
3
+ emoji: 📊
4
+ colorFrom: pink
5
+ colorTo: purple
6
+ sdk: gradio
7
+ sdk_version: 3.29.0
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: prusnak/troublinggan
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+
4
+ import gradio as gr
5
+ import numpy as np
6
+ import torch
7
+ from PIL import Image
8
+
9
+ sys.path.append(os.path.join(os.path.dirname(__file__), "stylegan2"))
10
+
11
+ import dnnlib
12
+ import legacy
13
+
14
+ DEVICE = "cpu" # or "cuda"
15
+
16
+ device = torch.device(DEVICE)
17
+ with dnnlib.util.open_url("troublinggan-square.pkl") as f:
18
+ G_square = legacy.load_network_pkl(f)["G_ema"].to(device)
19
+ with dnnlib.util.open_url("troublinggan-rectangle.pkl") as f:
20
+ G_rectangle = legacy.load_network_pkl(f)["G_ema"].to(device)
21
+
22
+
23
+ def generate(sigma, model):
24
+ G = {"v1": G_square, "v2": G_rectangle}[model]
25
+ label = torch.zeros([1, G.c_dim], device=device)
26
+ z = torch.from_numpy(np.random.RandomState().randn(1, G.z_dim) * sigma).to(device)
27
+ img = G(
28
+ z,
29
+ label,
30
+ truncation_psi=1,
31
+ noise_mode="random",
32
+ force_fp32=(DEVICE == "cpu"),
33
+ )
34
+ img = (img.permute(0, 2, 3, 1) * 127.5 + 128).clamp(0, 255).to(torch.uint8)
35
+ img = Image.fromarray(img[0].cpu().numpy(), "RGB")
36
+ if model == "v2":
37
+ img = img.crop((0, 172, 1024, 1024 - 172))
38
+ return img
39
+
40
+
41
+ iface = gr.Interface(
42
+ fn=generate,
43
+ inputs=[
44
+ gr.Slider(
45
+ value=1.0,
46
+ minimum=0.5,
47
+ maximum=2.0,
48
+ step=0.25,
49
+ info="perceived randomness of the image",
50
+ ),
51
+ gr.Radio(
52
+ ["v1", "v2"],
53
+ value="v1",
54
+ info="v1: model containing photos from 2020 (resolution 512x512); v2: model containing photos from 2020-2021 (resolution 1024x680)",
55
+ ),
56
+ ],
57
+ outputs=["image"],
58
+ title="TroublingGAN",
59
+ description="Generate a random image from the TroublingGAN model",
60
+ article="Read more about TroublingGAN at [http://hamosova.com/TroublingGAN](http://hamosova.com/TroublingGAN)",
61
+ allow_flagging="never",
62
+ )
63
+ iface.launch()
poetry.lock ADDED
The diff for this file is too large to render. See raw diff
 
pyproject.toml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [tool.poetry]
2
+ name = "troublinggan"
3
+ version = "0.1.0"
4
+ description = ""
5
+ authors = []
6
+ readme = "README.md"
7
+
8
+ [tool.poetry.dependencies]
9
+ python = ">=3.8,<3.12"
10
+ gradio = "^3.32.0"
11
+ torch = "^2.0.1"
12
+ numpy = "^1.24.3"
13
+ pillow = "^9.5.0"
14
+ scipy = "^1.10.1"
15
+
16
+ [tool.poetry.group.dev.dependencies]
17
+ black = "^23.3.0"
18
+ isort = "^5.12.0"
19
+
20
+ [build-system]
21
+ requires = ["poetry-core"]
22
+ build-backend = "poetry.core.masonry.api"
requirements.txt ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==23.1.0 ; python_version >= "3.8" and python_version < "3.12"
2
+ aiohttp==3.8.4 ; python_version >= "3.8" and python_version < "3.12"
3
+ aiosignal==1.3.1 ; python_version >= "3.8" and python_version < "3.12"
4
+ altair==5.0.0 ; python_version >= "3.8" and python_version < "3.12"
5
+ anyio==3.6.2 ; python_version >= "3.8" and python_version < "3.12"
6
+ async-timeout==4.0.2 ; python_version >= "3.8" and python_version < "3.12"
7
+ attrs==23.1.0 ; python_version >= "3.8" and python_version < "3.12"
8
+ certifi==2023.5.7 ; python_version >= "3.8" and python_version < "3.12"
9
+ charset-normalizer==3.1.0 ; python_version >= "3.8" and python_version < "3.12"
10
+ click==8.1.3 ; python_version >= "3.8" and python_version < "3.12"
11
+ colorama==0.4.6 ; python_version >= "3.8" and python_version < "3.12" and platform_system == "Windows"
12
+ contourpy==1.0.7 ; python_version >= "3.8" and python_version < "3.12"
13
+ cycler==0.11.0 ; python_version >= "3.8" and python_version < "3.12"
14
+ fastapi==0.95.2 ; python_version >= "3.8" and python_version < "3.12"
15
+ ffmpy==0.3.0 ; python_version >= "3.8" and python_version < "3.12"
16
+ filelock==3.12.0 ; python_version >= "3.8" and python_version < "3.12"
17
+ fonttools==4.39.4 ; python_version >= "3.8" and python_version < "3.12"
18
+ frozenlist==1.3.3 ; python_version >= "3.8" and python_version < "3.12"
19
+ fsspec==2023.5.0 ; python_version >= "3.8" and python_version < "3.12"
20
+ gradio-client==0.2.5 ; python_version >= "3.8" and python_version < "3.12"
21
+ gradio==3.32.0 ; python_version >= "3.8" and python_version < "3.12"
22
+ h11==0.14.0 ; python_version >= "3.8" and python_version < "3.12"
23
+ httpcore==0.17.1 ; python_version >= "3.8" and python_version < "3.12"
24
+ httpx==0.24.1 ; python_version >= "3.8" and python_version < "3.12"
25
+ huggingface-hub==0.14.1 ; python_version >= "3.8" and python_version < "3.12"
26
+ idna==3.4 ; python_version >= "3.8" and python_version < "3.12"
27
+ importlib-resources==5.12.0 ; python_version >= "3.8" and python_version < "3.10"
28
+ jinja2==3.1.2 ; python_version >= "3.8" and python_version < "3.12"
29
+ jsonschema==4.17.3 ; python_version >= "3.8" and python_version < "3.12"
30
+ kiwisolver==1.4.4 ; python_version >= "3.8" and python_version < "3.12"
31
+ linkify-it-py==2.0.2 ; python_version >= "3.8" and python_version < "3.12"
32
+ markdown-it-py==2.2.0 ; python_version >= "3.8" and python_version < "3.12"
33
+ markdown-it-py[linkify]==2.2.0 ; python_version >= "3.8" and python_version < "3.12"
34
+ markupsafe==2.1.2 ; python_version >= "3.8" and python_version < "3.12"
35
+ matplotlib==3.7.1 ; python_version >= "3.8" and python_version < "3.12"
36
+ mdit-py-plugins==0.3.3 ; python_version >= "3.8" and python_version < "3.12"
37
+ mdurl==0.1.2 ; python_version >= "3.8" and python_version < "3.12"
38
+ mpmath==1.3.0 ; python_version >= "3.8" and python_version < "3.12"
39
+ multidict==6.0.4 ; python_version >= "3.8" and python_version < "3.12"
40
+ networkx==3.1 ; python_version >= "3.8" and python_version < "3.12"
41
+ numpy==1.24.3 ; python_version >= "3.8" and python_version < "3.12"
42
+ orjson==3.8.12 ; python_version >= "3.8" and python_version < "3.12"
43
+ packaging==23.1 ; python_version >= "3.8" and python_version < "3.12"
44
+ pandas==2.0.1 ; python_version >= "3.8" and python_version < "3.12"
45
+ pillow==9.5.0 ; python_version >= "3.8" and python_version < "3.12"
46
+ pkgutil-resolve-name==1.3.10 ; python_version >= "3.8" and python_version < "3.9"
47
+ pydantic==1.10.7 ; python_version >= "3.8" and python_version < "3.12"
48
+ pydub==0.25.1 ; python_version >= "3.8" and python_version < "3.12"
49
+ pygments==2.15.1 ; python_version >= "3.8" and python_version < "3.12"
50
+ pyparsing==3.0.9 ; python_version >= "3.8" and python_version < "3.12"
51
+ pyrsistent==0.19.3 ; python_version >= "3.8" and python_version < "3.12"
52
+ python-dateutil==2.8.2 ; python_version >= "3.8" and python_version < "3.12"
53
+ python-multipart==0.0.6 ; python_version >= "3.8" and python_version < "3.12"
54
+ pytz==2023.3 ; python_version >= "3.8" and python_version < "3.12"
55
+ pyyaml==6.0 ; python_version >= "3.8" and python_version < "3.12"
56
+ requests==2.31.0 ; python_version >= "3.8" and python_version < "3.12"
57
+ scipy==1.10.1 ; python_version >= "3.8" and python_version < "3.12"
58
+ semantic-version==2.10.0 ; python_version >= "3.8" and python_version < "3.12"
59
+ six==1.16.0 ; python_version >= "3.8" and python_version < "3.12"
60
+ sniffio==1.3.0 ; python_version >= "3.8" and python_version < "3.12"
61
+ starlette==0.27.0 ; python_version >= "3.8" and python_version < "3.12"
62
+ sympy==1.12 ; python_version >= "3.8" and python_version < "3.12"
63
+ toolz==0.12.0 ; python_version >= "3.8" and python_version < "3.12"
64
+ torch==2.0.1 ; python_version >= "3.8" and python_version < "3.12"
65
+ tqdm==4.65.0 ; python_version >= "3.8" and python_version < "3.12"
66
+ typing-extensions==4.5.0 ; python_version >= "3.8" and python_version < "3.12"
67
+ tzdata==2023.3 ; python_version >= "3.8" and python_version < "3.12"
68
+ uc-micro-py==1.0.2 ; python_version >= "3.8" and python_version < "3.12"
69
+ urllib3==2.0.2 ; python_version >= "3.8" and python_version < "3.12"
70
+ uvicorn==0.22.0 ; python_version >= "3.8" and python_version < "3.12"
71
+ websockets==11.0.3 ; python_version >= "3.8" and python_version < "3.12"
72
+ yarl==1.9.2 ; python_version >= "3.8" and python_version < "3.12"
73
+ zipp==3.15.0 ; python_version >= "3.8" and python_version < "3.10"
stylegan2 ADDED
@@ -0,0 +1 @@
 
 
1
+ Subproject commit 6f160b3d22b8b178ebe533a50d4d5e63aedba21d
troublinggan-rectangle.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b1240e05c061ba2edd076f7c9877f69b643890ced81d24390cc92a0018f926f3
3
+ size 369008389
troublinggan-square.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:859760239bd12bb43750e988069332ee706f1f5ab8d664af88dfba20a844e3ec
3
+ size 351315276