|
import gradio as gr |
|
import visual |
|
import gen |
|
|
|
def showpuzzle(encoding): |
|
p1 = visual.parse(encoding) |
|
return visual.fig(p1) |
|
|
|
showpuzzint = gr.Interface(fn=showpuzzle, inputs=gr.Text(label="Puzzle encoding"), outputs=gr.Plot()) |
|
|
|
|
|
def genpuzzle(width,height,is_square,shuffle,seed): |
|
if is_square: |
|
height=width |
|
p = gen.genpuzzle(width,height,seed) |
|
if seed==0: |
|
seed=gen.seed1 |
|
if not shuffle: |
|
return visual.fig(p),seed,gen.h(p),'' |
|
p_ = gen.shuf(p) |
|
p2 = visual.join(p,p_) |
|
return visual.fig(p2),seed,gen.h(p),gen.h(p_) |
|
|
|
genint = gr.Interface(fn=genpuzzle, inputs=[gr.Slider(label="Width",step=1,minimum=1,maximum=40,value=3),gr.Slider(label="Height",step=1,minimum=1,maximum=40,value=3),gr.Checkbox(label="Square",value=True),gr.Checkbox(label="Shuffle"),gr.Number(label="Seed",value=0)], outputs=[gr.Plot(label="Puzzle"),gr.Number(label="Seed"),gr.Text(label="Puzzle encoding"),gr.Text(label="Shuffled encoding")]) |
|
|
|
def shuffle(encoding,show): |
|
p = visual.parse(encoding) |
|
p_ = gen.shuf(p) |
|
if show: |
|
return visual.fig(p_),gen.h(p_) |
|
return None,gen.h(p_) |
|
|
|
shufint = gr.Interface(fn=shuffle, inputs=[gr.Text(label="Puzzle encoding"),gr.Checkbox(label="Visualise")], outputs=[gr.Plot(label="Visualisation"),gr.Text(label="Shuffled encoding")]) |
|
|
|
|
|
demo = gr.TabbedInterface([genint,showpuzzint,shufint],["generate","visualise","shuffle"],title="comp2209 Tools") |
|
demo.launch() |
|
|