Spaces:
Sleeping
Sleeping
File size: 7,223 Bytes
b0a9403 02295f5 b0a9403 02295f5 f5f64cf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
import gradio as gr
import os
import numpy as np
def Generate(Roomtype, UserNumber, RoomImage, Generatenumber, Displaynumber):
#read all images in the file
allimgspath, selectimgspath = ReadallImages("RoomImages", Generatenumber)
text = "Room Type: " + Roomtype + "\n" \
+ "Number of Users: " + str(UserNumber) + "\n" \
+ "Generated Result Number : " + str(Generatenumber) + "\n" \
+ "Displayed Result Number : " + str(Displaynumber)
outputs = [text]+selectimgspath
return outputs
#read all images in the file
def ReadallImages(path, SelectNumber):
# Allimages = []
Allimagespath = []
for file in os.listdir(path):
if file.endswith(".png"):
# img = cv2.imread(os.path.join(path, file))
Allimagespath.append(os.path.join(path, file))
# Allimages.append(img)
# only select the SelectNumber of images
SelectImagespath = []
for i in range(SelectNumber):
SelectImagespath.append(Allimagespath[i])
#random the order of the images
np.random.shuffle(SelectImagespath)
return Allimagespath, SelectImagespath
def GenerateOptions(ResultImgBlock, Styles, Layouts):
with gr.Group() as group:
with gr.Column():
img = gr.outputs.Image(type= "filepath", label="Result Image")
with gr.Row():
# Like = gr.inputs.Checkbox(label="Like")
# Dislike = gr.inputs.Checkbox(label="Disike")
with gr.Column():
gr.Markdown("### Score of Design Style 設計風格", elem_classes=["test"])
StyleScore = gr.Slider(minimum=0, maximum=10, step=1, default=5, label="Design Style: Score")
gr.Markdown("### Score of Design Layout 設計布局")
LayoutScore = gr.Slider(minimum=0, maximum=10, step=1, default=5, label="Design Layout: Score")
ResultImgBlock.append(img)
Styles.append(StyleScore)
Layouts.append(LayoutScore)
return group
def GenerateLayout(Total = 50, rownum=4):
ResultImgBlock = []
Styles = []
Layouts = []
Groups = []
Total = int(Total)
rownum = int(rownum)
for i in range(Total//rownum):
with gr.Row():
for i in range(rownum):
group = GenerateOptions(ResultImgBlock, Styles, Layouts)
Groups.append(group)
if Total % rownum != 0:
with gr.Row():
for i in range(Total % rownum):
group = GenerateOptions(ResultImgBlock, Styles, Layouts)
Groups.append(group)
return ResultImgBlock, Styles, Layouts, Groups
with gr.Blocks() as demo:
gr.Markdown(
"""
# RoomDreaming Testing UI/UX
### This is a test UI for RoomDreaming System!!
""")
with gr.Tab("Developer"):
with gr.Row():
with gr.Column():
Model = gr.inputs.Dropdown(["TestModel1", "TestModel2"], label="Model")
SamplingStep = gr.inputs.Slider(minimum=1, maximum=20, step=1, default=1, label="Sampling Step")
SamplingMethod = gr.inputs.Dropdown(["Euler a", "Euler", "LMS", "DPM++2Sa", "DPM++ 2M"], label="Sampling Method")
with gr.Column():
Batchcount = gr.inputs.Slider(minimum=1, maximum=10, step=1, default=1, label="Batch Count")
BatchSize = gr.inputs.Slider(minimum=1, maximum=10, step=1, default=1, label="Batch Size")
Seed = gr.inputs.Slider(minimum=1, maximum=10, step=1, default=1, label="Seed")
CN_bool = gr.inputs.Checkbox(label="ControlNet")
with gr.Row():
gr.Markdown("Result Number & Display Control!!")
GenerateNum = gr.Slider(minimum=1, maximum=50, step=1, default=50, label="Result Generate Number Controller")
DisplayNum = gr.Slider(minimum=1, maximum=50, step=1, default=50, label="Result Display Number Controller")
ConfirmDisplay = gr.Button("Confirm Display Number")
with gr.Accordion("Open for More!"):
gr.Markdown("Look at me...")
with gr.Tab("User"):
gr.Markdown("## User Requirements")
with gr.Row():
with gr.Column():
gr.Markdown("Basic Information")
Roomtype = gr.inputs.Dropdown(["Workshop","Office","Bedroom", "Livingroom", "Kitchen", "Bathroom", "Balcony", "Diningroom", "Studyroom", "Toilet", "Others"], label="Room Type")
UserNumber = gr.inputs.Slider(minimum=1, maximum=10, step=1, default=1, label="Number of Users")
AdditionalRequirements = gr.inputs.Textbox(label="Additional Requirements")
with gr.Column():
gr.Markdown("Room Image")
RoomImage = gr.inputs.Image(shape=(224, 224), label="Room Image")
StartIteration = gr.Button("Start Iteration", variant='primary')
gr.Markdown("## Iteration Results")
Banner = gr.outputs.Textbox(label="System Log")
with gr.Row():
StopIteration = gr.Button("Finish!", variant='stop')
#Tab Number
TabNum = 1
Tabs = []
ResultImgBlock, likebtns, dislikebtns, groups = [], [], [], []
def generateTab(Tabs, TabNum, ResultImgBlock, likebtns, dislikebtns, groups):
with gr.Tab("Iteration "+str(TabNum)) as tab:
with gr.Row():
globals()["NextIteration"+str(TabNum)] = gr.Button(str(TabNum)+ " - Next Iteration", variant='primary')
globals()["ClearIteration"+str(TabNum)] = gr.Button(str(TabNum)+ " - Clear Iteration")
ResultImgBlock, likebtns, dislikebtns , groups= GenerateLayout(50, 4)
print(tab)
TabNum += 1
Tabs.append(tab)
return TabNum , ResultImgBlock, likebtns, dislikebtns, groups
TabNum, ResultImgBlock, likebtns, dislikebtns, groups = generateTab(Tabs, TabNum, ResultImgBlock, likebtns, dislikebtns, groups)
a,b,c,d = [], [], [], []
e,f, g, h, i = [], [], [], [], []
e, f, g, h, i = generateTab(Tabs, TabNum, a, b, c, d)
def Display(DisplayNum):
DisplayNum = int(DisplayNum)
return {
**{ResultImgBlock[i]: gr.update(visible=False) for i in range(len(ResultImgBlock)-1, DisplayNum-1, -1)},
**{likebtns[i]: gr.update(visible=False) for i in range(len(likebtns)-1, DisplayNum-1, -1)},
**{dislikebtns[i]: gr.update(visible=False) for i in range(len(dislikebtns)-1, DisplayNum-1, -1)}
}
ConfirmDisplay.click(fn = Display, inputs=[DisplayNum], outputs=ResultImgBlock+likebtns+dislikebtns)
StartIteration.click(fn = Generate, inputs=[Roomtype, UserNumber, RoomImage, GenerateNum, DisplayNum], outputs=[Banner]+ResultImgBlock)
NextIteration1.click(fn = Generate, inputs=[Roomtype, UserNumber, RoomImage, GenerateNum, DisplayNum], outputs=[Banner]+f)
if __name__ == "__main__":
demo.launch()
|