Spaces:
Runtime error
Runtime error
Badr AlKhamissi
commited on
Commit
·
05e4671
1
Parent(s):
02fb36d
making it work
Browse files- app.py +29 -19
- code/config/base.yaml +1 -1
app.py
CHANGED
@@ -17,9 +17,7 @@ sys.path.append('/home/user/app/code')
|
|
17 |
# os.system('git clone https://github.com/BachiLi/diffvg.git')
|
18 |
os.system('git submodule update --init')
|
19 |
os.chdir('diffvg')
|
20 |
-
print(os.getcwd())
|
21 |
os.system('git submodule update --init --recursive')
|
22 |
-
print(os.getcwd())
|
23 |
os.system('python setup.py install --user')
|
24 |
sys.path.append("/home/user/.local/lib/python3.8/site-packages/diffvg-0.0.1-py3.8-linux-x86_64.egg")
|
25 |
|
@@ -32,8 +30,7 @@ from diffusers import StableDiffusionPipeline
|
|
32 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
33 |
|
34 |
model = None
|
35 |
-
model = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5",
|
36 |
-
torch_dtype=torch.float16).to(device)
|
37 |
|
38 |
from typing import Mapping
|
39 |
from tqdm import tqdm
|
@@ -69,7 +66,7 @@ pydiffvg.set_print_timing(False)
|
|
69 |
gamma = 1.0
|
70 |
|
71 |
|
72 |
-
def set_config(semantic_concept, word,
|
73 |
|
74 |
cfg_d = edict()
|
75 |
cfg_d.config = "code/config/base.yaml"
|
@@ -91,7 +88,7 @@ def set_config(semantic_concept, word, letter, font_name, num_steps):
|
|
91 |
|
92 |
cfg.semantic_concept = semantic_concept
|
93 |
cfg.word = word
|
94 |
-
cfg.optimized_letter =
|
95 |
cfg.font = font_name
|
96 |
cfg.seed = 0
|
97 |
cfg.num_iter = num_steps
|
@@ -246,6 +243,11 @@ def run_main_app(semantic_concept, word, letter, font_name, num_steps, example=0
|
|
246 |
yield gr.update(value=filename_init,visible=True),gr.update(visible=False),gr.update(value=image,visible=True)
|
247 |
|
248 |
|
|
|
|
|
|
|
|
|
|
|
249 |
with gr.Blocks() as demo:
|
250 |
|
251 |
gr.HTML(TITLE)
|
@@ -254,27 +256,36 @@ with gr.Blocks() as demo:
|
|
254 |
with gr.Row():
|
255 |
with gr.Column():
|
256 |
|
257 |
-
|
258 |
-
label='
|
259 |
max_lines=1,
|
260 |
placeholder=
|
261 |
-
'Enter
|
262 |
)
|
263 |
|
264 |
-
|
265 |
-
label='
|
266 |
max_lines=1,
|
267 |
placeholder=
|
268 |
-
'Enter a
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
)
|
270 |
-
|
271 |
-
|
272 |
-
label='
|
273 |
max_lines=1,
|
274 |
-
|
275 |
-
'Choose a letter in the word to optimize. For example: Y'
|
276 |
)
|
277 |
|
|
|
|
|
|
|
278 |
num_steps = gr.Slider(label='Optimization Iterations',
|
279 |
minimum=0,
|
280 |
maximum=500,
|
@@ -350,8 +361,7 @@ with gr.Blocks() as demo:
|
|
350 |
# inputs
|
351 |
inputs = [
|
352 |
semantic_concept,
|
353 |
-
word,
|
354 |
-
letter,
|
355 |
font_name,
|
356 |
num_steps
|
357 |
]
|
|
|
17 |
# os.system('git clone https://github.com/BachiLi/diffvg.git')
|
18 |
os.system('git submodule update --init')
|
19 |
os.chdir('diffvg')
|
|
|
20 |
os.system('git submodule update --init --recursive')
|
|
|
21 |
os.system('python setup.py install --user')
|
22 |
sys.path.append("/home/user/.local/lib/python3.8/site-packages/diffvg-0.0.1-py3.8-linux-x86_64.egg")
|
23 |
|
|
|
30 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
31 |
|
32 |
model = None
|
33 |
+
model = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16).to(device)
|
|
|
34 |
|
35 |
from typing import Mapping
|
36 |
from tqdm import tqdm
|
|
|
66 |
gamma = 1.0
|
67 |
|
68 |
|
69 |
+
def set_config(semantic_concept, word, font_name, num_steps):
|
70 |
|
71 |
cfg_d = edict()
|
72 |
cfg_d.config = "code/config/base.yaml"
|
|
|
88 |
|
89 |
cfg.semantic_concept = semantic_concept
|
90 |
cfg.word = word
|
91 |
+
cfg.optimized_letter = word
|
92 |
cfg.font = font_name
|
93 |
cfg.seed = 0
|
94 |
cfg.num_iter = num_steps
|
|
|
243 |
yield gr.update(value=filename_init,visible=True),gr.update(visible=False),gr.update(value=image,visible=True)
|
244 |
|
245 |
|
246 |
+
def change_prompt(concept, prompt_suffix):
|
247 |
+
if concept == "":
|
248 |
+
concept = "{concept}"
|
249 |
+
return f"a {concept}. {prompt_suffix}"
|
250 |
+
|
251 |
with gr.Blocks() as demo:
|
252 |
|
253 |
gr.HTML(TITLE)
|
|
|
256 |
with gr.Row():
|
257 |
with gr.Column():
|
258 |
|
259 |
+
word = gr.Text(
|
260 |
+
label='Text',
|
261 |
max_lines=1,
|
262 |
placeholder=
|
263 |
+
'Enter text. For example: حصان'
|
264 |
)
|
265 |
|
266 |
+
semantic_concept = gr.Text(
|
267 |
+
label='Concept',
|
268 |
max_lines=1,
|
269 |
placeholder=
|
270 |
+
'Enter a semantic concept that you want your text to morph into (in English). For example: horse'
|
271 |
+
)
|
272 |
+
|
273 |
+
|
274 |
+
prompt_suffix = gr.Text(
|
275 |
+
label='Prompt Suffix',
|
276 |
+
max_lines=1,
|
277 |
+
value="minimal flat 2d vector. lineal color. trending on artstation"
|
278 |
)
|
279 |
+
|
280 |
+
prompt = gr.Text(
|
281 |
+
label='Prompt',
|
282 |
max_lines=1,
|
283 |
+
value="a {concept}. minimal flat 2d vector. lineal color. trending on artstation."
|
|
|
284 |
)
|
285 |
|
286 |
+
semantic_concept.change(change_prompt, [semantic_concept, prompt_suffix], prompt)
|
287 |
+
prompt_suffix.change(change_prompt, [semantic_concept, prompt_suffix], prompt)
|
288 |
+
|
289 |
num_steps = gr.Slider(label='Optimization Iterations',
|
290 |
minimum=0,
|
291 |
maximum=500,
|
|
|
361 |
# inputs
|
362 |
inputs = [
|
363 |
semantic_concept,
|
364 |
+
word,
|
|
|
365 |
font_name,
|
366 |
num_steps
|
367 |
]
|
code/config/base.yaml
CHANGED
@@ -43,7 +43,7 @@ conformal_0.5_dist_pixel_100_kernel201:
|
|
43 |
use_conformal_loss: true
|
44 |
angeles_w: 0.5
|
45 |
|
46 |
-
|
47 |
parent_config: baseline
|
48 |
level_of_cc: 1
|
49 |
num_iter: 500
|
|
|
43 |
use_conformal_loss: true
|
44 |
angeles_w: 0.5
|
45 |
|
46 |
+
demo:
|
47 |
parent_config: baseline
|
48 |
level_of_cc: 1
|
49 |
num_iter: 500
|