Spaces:
Running
Running
Update gradio design
Browse files
app.py
CHANGED
@@ -98,8 +98,8 @@ def save_img(res, imgid, origin_shape, output_name, divide=False):
|
|
98 |
|
99 |
|
100 |
|
101 |
-
def paint_img(img):
|
102 |
-
max_step =
|
103 |
# imgid = 0
|
104 |
# output_name = os.path.join('output', str(len(os.listdir('output'))) if os.path.exists('output') else '0')
|
105 |
# os.makedirs(output_name, exist_ok= True)
|
@@ -188,20 +188,25 @@ def change_model(choice: str):
|
|
188 |
actor = actor.to(device).eval()
|
189 |
Decoder = Decoder.to(device).eval()
|
190 |
|
191 |
-
|
192 |
def wrapper(func):
|
|
|
193 |
def inner(*args, **kwargs):
|
|
|
194 |
val = args[0]
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
event.close()
|
202 |
-
|
|
|
|
|
203 |
return inner
|
204 |
|
|
|
205 |
examples = [
|
206 |
["image/chaoyue.png"],
|
207 |
["image/degang.png"],
|
@@ -209,29 +214,35 @@ examples = [
|
|
209 |
["image/Leslie.png"],
|
210 |
["image/mayun.png"],
|
211 |
]
|
212 |
-
|
213 |
with gr.Blocks() as demo:
|
214 |
with gr.Row():
|
215 |
with gr.Column():
|
216 |
input_image = gr.Image(label="Input image")
|
|
|
|
|
217 |
with gr.Row():
|
218 |
dropdown = gr.Dropdown(['Default', 'Round', 'Triangle', 'Bezier wo trans'], value= 'Default', label= 'Stroke choice')
|
219 |
with gr.Row():
|
220 |
with gr.Column():
|
221 |
-
clr_btn = gr.ClearButton([input_image], variant= "stop")
|
222 |
with gr.Column():
|
223 |
translate_btn = gr.Button(value="Paint", variant="primary")
|
224 |
|
225 |
with gr.Column():
|
226 |
-
output
|
|
|
|
|
227 |
dropdown.select(change_model, dropdown)
|
228 |
-
translate_btn.click(lambda x: gr.Button(value="Cancel", variant="stop") if x == "Paint" else gr.Button(value="Paint", variant="primary"), translate_btn, translate_btn)
|
229 |
-
.
|
|
|
|
|
230 |
examples = gr.Examples(examples=examples,
|
231 |
inputs=[input_image], cache_examples = False)
|
232 |
|
233 |
|
234 |
|
235 |
# demo = gr.Interface(fn=paint_img, inputs=gr.Image(), outputs="image", examples = examples)
|
236 |
-
demo.queue()
|
237 |
-
demo.launch(server_name="0.0.0.0")
|
|
|
98 |
|
99 |
|
100 |
|
101 |
+
def paint_img(img, max_step = 40):
|
102 |
+
max_step = int(max_step)
|
103 |
# imgid = 0
|
104 |
# output_name = os.path.join('output', str(len(os.listdir('output'))) if os.path.exists('output') else '0')
|
105 |
# os.makedirs(output_name, exist_ok= True)
|
|
|
188 |
actor = actor.to(device).eval()
|
189 |
Decoder = Decoder.to(device).eval()
|
190 |
|
191 |
+
from typing import Generator
|
192 |
def wrapper(func):
|
193 |
+
event:Generator = range(0)
|
194 |
def inner(*args, **kwargs):
|
195 |
+
nonlocal event
|
196 |
val = args[0]
|
197 |
+
if val == "Cancel":
|
198 |
+
args_ = tuple(x for i,x in enumerate(args) if i > 0)
|
199 |
+
event = func(*args_, **kwargs)
|
200 |
+
yield from event
|
201 |
+
else:
|
202 |
+
try:
|
203 |
event.close()
|
204 |
+
yield
|
205 |
+
except:
|
206 |
+
pass
|
207 |
return inner
|
208 |
|
209 |
+
|
210 |
examples = [
|
211 |
["image/chaoyue.png"],
|
212 |
["image/degang.png"],
|
|
|
214 |
["image/Leslie.png"],
|
215 |
["image/mayun.png"],
|
216 |
]
|
217 |
+
output = gr.Image(label="Painting Result")
|
218 |
with gr.Blocks() as demo:
|
219 |
with gr.Row():
|
220 |
with gr.Column():
|
221 |
input_image = gr.Image(label="Input image")
|
222 |
+
with gr.Row():
|
223 |
+
step = gr.Slider(20, 100, value= 40, step = 1, label= 'Painting step')
|
224 |
with gr.Row():
|
225 |
dropdown = gr.Dropdown(['Default', 'Round', 'Triangle', 'Bezier wo trans'], value= 'Default', label= 'Stroke choice')
|
226 |
with gr.Row():
|
227 |
with gr.Column():
|
228 |
+
clr_btn = gr.ClearButton([input_image, output], variant= "stop")
|
229 |
with gr.Column():
|
230 |
translate_btn = gr.Button(value="Paint", variant="primary")
|
231 |
|
232 |
with gr.Column():
|
233 |
+
output.render()
|
234 |
+
|
235 |
+
|
236 |
dropdown.select(change_model, dropdown)
|
237 |
+
click_event = translate_btn.click(lambda x: gr.Button(value="Cancel", variant="stop") if x == "Paint" else gr.Button(value="Paint", variant="primary"), translate_btn, translate_btn)\
|
238 |
+
.then(wrapper(paint_img), inputs=[translate_btn, input_image, step], outputs=output, trigger_mode = 'multiple')\
|
239 |
+
.then(lambda x: gr.Button(value="Paint", variant="primary"), translate_btn, translate_btn)
|
240 |
+
clr_btn.click(None, None, cancels=[click_event])
|
241 |
examples = gr.Examples(examples=examples,
|
242 |
inputs=[input_image], cache_examples = False)
|
243 |
|
244 |
|
245 |
|
246 |
# demo = gr.Interface(fn=paint_img, inputs=gr.Image(), outputs="image", examples = examples)
|
247 |
+
demo.queue(default_concurrency_limit= 4)
|
248 |
+
demo.launch(server_name="0.0.0.0", )
|
baseline/DRL/__pycache__/actor.cpython-311.pyc
ADDED
Binary file (8.35 kB). View file
|
|
baseline/Renderer/__pycache__/__init__.cpython-311.pyc
ADDED
Binary file (167 Bytes). View file
|
|
baseline/Renderer/__pycache__/model.cpython-311.pyc
ADDED
Binary file (3.49 kB). View file
|
|
baseline/Renderer/__pycache__/stroke_gen.cpython-311.pyc
ADDED
Binary file (2.23 kB). View file
|
|