Spaces:
Running
Running
Update
Browse files
README.md
CHANGED
@@ -4,9 +4,11 @@ emoji: 🌍
|
|
4 |
colorFrom: red
|
5 |
colorTo: indigo
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 3.
|
|
|
8 |
app_file: app.py
|
9 |
pinned: false
|
|
|
10 |
---
|
11 |
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
|
|
|
4 |
colorFrom: red
|
5 |
colorTo: indigo
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 3.35.2
|
8 |
+
python_version: 3.9.16
|
9 |
app_file: app.py
|
10 |
pinned: false
|
11 |
+
suggested_hardware: t4-small
|
12 |
---
|
13 |
|
14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces#reference
|
app.py
CHANGED
@@ -7,10 +7,7 @@ import numpy as np
|
|
7 |
|
8 |
from model import Model
|
9 |
|
10 |
-
DESCRIPTION = '
|
11 |
-
|
12 |
-
This is an unofficial demo for [https://github.com/autonomousvision/projected_gan](https://github.com/autonomousvision/projected_gan).
|
13 |
-
'''
|
14 |
|
15 |
|
16 |
def get_sample_image_url(name: str) -> str:
|
@@ -36,33 +33,33 @@ with gr.Blocks(css='style.css') as demo:
|
|
36 |
with gr.TabItem('App'):
|
37 |
with gr.Row():
|
38 |
with gr.Column():
|
39 |
-
model_name = gr.Dropdown(
|
40 |
-
|
41 |
-
|
42 |
-
seed = gr.Slider(
|
43 |
-
|
|
|
44 |
step=1,
|
45 |
-
value=0
|
46 |
-
|
47 |
-
|
48 |
-
2,
|
49 |
step=0.05,
|
50 |
-
value=0.7
|
51 |
-
label='Truncation psi')
|
52 |
run_button = gr.Button('Run')
|
53 |
with gr.Column():
|
54 |
result = gr.Image(label='Result', elem_id='result')
|
55 |
|
56 |
with gr.TabItem('Sample Images'):
|
57 |
with gr.Row():
|
58 |
-
model_name2 = gr.Dropdown(
|
59 |
-
|
60 |
-
|
61 |
with gr.Row():
|
62 |
text = get_sample_image_markdown(model_name2.value)
|
63 |
sample_images = gr.Markdown(text)
|
64 |
|
65 |
-
model_name.change(fn=model.set_model, inputs=model_name
|
66 |
run_button.click(fn=model.set_model_and_generate_image,
|
67 |
inputs=[
|
68 |
model_name,
|
@@ -74,4 +71,4 @@ with gr.Blocks(css='style.css') as demo:
|
|
74 |
inputs=model_name2,
|
75 |
outputs=sample_images)
|
76 |
|
77 |
-
demo.queue().launch(
|
|
|
7 |
|
8 |
from model import Model
|
9 |
|
10 |
+
DESCRIPTION = '# [Projected GAN](https://github.com/autonomousvision/projected_gan)'
|
|
|
|
|
|
|
11 |
|
12 |
|
13 |
def get_sample_image_url(name: str) -> str:
|
|
|
33 |
with gr.TabItem('App'):
|
34 |
with gr.Row():
|
35 |
with gr.Column():
|
36 |
+
model_name = gr.Dropdown(label='Model',
|
37 |
+
choices=model.MODEL_NAMES,
|
38 |
+
value=model.MODEL_NAMES[8])
|
39 |
+
seed = gr.Slider(label='Seed',
|
40 |
+
minimum=0,
|
41 |
+
maximum=np.iinfo(np.uint32).max,
|
42 |
step=1,
|
43 |
+
value=0)
|
44 |
+
psi = gr.Slider(label='Truncation psi',
|
45 |
+
minimum=0,
|
46 |
+
maximum=2,
|
47 |
step=0.05,
|
48 |
+
value=0.7)
|
|
|
49 |
run_button = gr.Button('Run')
|
50 |
with gr.Column():
|
51 |
result = gr.Image(label='Result', elem_id='result')
|
52 |
|
53 |
with gr.TabItem('Sample Images'):
|
54 |
with gr.Row():
|
55 |
+
model_name2 = gr.Dropdown(label='Model',
|
56 |
+
choices=model.MODEL_NAMES,
|
57 |
+
value=model.MODEL_NAMES[0])
|
58 |
with gr.Row():
|
59 |
text = get_sample_image_markdown(model_name2.value)
|
60 |
sample_images = gr.Markdown(text)
|
61 |
|
62 |
+
model_name.change(fn=model.set_model, inputs=model_name)
|
63 |
run_button.click(fn=model.set_model_and_generate_image,
|
64 |
inputs=[
|
65 |
model_name,
|
|
|
71 |
inputs=model_name2,
|
72 |
outputs=sample_images)
|
73 |
|
74 |
+
demo.queue(max_size=10).launch()
|
model.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
from __future__ import annotations
|
2 |
|
3 |
-
import os
|
4 |
import pathlib
|
5 |
import pickle
|
6 |
import sys
|
@@ -14,8 +13,6 @@ current_dir = pathlib.Path(__file__).parent
|
|
14 |
submodule_dir = current_dir / 'projected_gan'
|
15 |
sys.path.insert(0, submodule_dir.as_posix())
|
16 |
|
17 |
-
HF_TOKEN = os.getenv('HF_TOKEN')
|
18 |
-
|
19 |
|
20 |
class Model:
|
21 |
|
@@ -39,9 +36,8 @@ class Model:
|
|
39 |
self.model = self._load_model(self.model_name)
|
40 |
|
41 |
def _load_model(self, model_name: str) -> nn.Module:
|
42 |
-
path = hf_hub_download('
|
43 |
-
f'models/{model_name}.pkl'
|
44 |
-
use_auth_token=HF_TOKEN)
|
45 |
with open(path, 'rb') as f:
|
46 |
model = pickle.load(f)['G_ema']
|
47 |
model.eval()
|
|
|
1 |
from __future__ import annotations
|
2 |
|
|
|
3 |
import pathlib
|
4 |
import pickle
|
5 |
import sys
|
|
|
13 |
submodule_dir = current_dir / 'projected_gan'
|
14 |
sys.path.insert(0, submodule_dir.as_posix())
|
15 |
|
|
|
|
|
16 |
|
17 |
class Model:
|
18 |
|
|
|
36 |
self.model = self._load_model(self.model_name)
|
37 |
|
38 |
def _load_model(self, model_name: str) -> nn.Module:
|
39 |
+
path = hf_hub_download('public-data/projected_gan',
|
40 |
+
f'models/{model_name}.pkl')
|
|
|
41 |
with open(path, 'rb') as f:
|
42 |
model = pickle.load(f)['G_ema']
|
43 |
model.eval()
|
requirements.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
-
numpy==1.
|
2 |
-
Pillow==
|
3 |
-
scipy==1.
|
4 |
torch==1.10.2
|
5 |
torchvision==0.11.3
|
|
|
1 |
+
numpy==1.23.5
|
2 |
+
Pillow==10.0.0
|
3 |
+
scipy==1.10.1
|
4 |
torch==1.10.2
|
5 |
torchvision==0.11.3
|