THEODOROS commited on
Commit
b773031
·
1 Parent(s): cd968d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -2
app.py CHANGED
@@ -90,7 +90,24 @@ def prompt_to_layout(user_prompt, intensity, fpath=None):
90
  spaces = [txt.split(':')[0] for txt in layout]
91
  coords = [txt.split(':')[1].rstrip() for txt in layout]
92
  coordinates = [re.findall(regex, coord) for coord in coords]
93
- layout_dict = dict(zip(spaces, coords))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  polygons = []
95
  for coord in coordinates:
96
  polygons.append([point.split(',') for point in coord])
@@ -104,7 +121,7 @@ def prompt_to_layout(user_prompt, intensity, fpath=None):
104
  legend = Image.open("labels.png")
105
  imgs_comb = np.vstack([im, legend])
106
  imgs_comb = Image.fromarray(imgs_comb)
107
- return imgs_comb, layout_dict
108
 
109
 
110
  # Gradio App
@@ -137,6 +154,10 @@ custom_css="""
137
  max-width: 1500px;
138
  }
139
 
 
 
 
 
140
  .gradio_wrapper .gradio_bg[theme=default] .panel_buttons {
141
  justify-content: flex-end;
142
  }
 
90
  spaces = [txt.split(':')[0] for txt in layout]
91
  coords = [txt.split(':')[1].rstrip() for txt in layout]
92
  coordinates = [re.findall(regex, coord) for coord in coords]
93
+
94
+ num_coords = []
95
+ for coord in coordinates:
96
+ temp = []
97
+ for xy in coord:
98
+ numbers = xy.split(',')
99
+ temp.append(tuple([int(num)/14.2 for num in numbers]))
100
+ num_coords.append(temp)
101
+
102
+ new_spaces = []
103
+ for i, v in enumerate(spaces):
104
+ totalcount = spaces.count(v)
105
+ count = spaces[:i].count(v)
106
+ new_spaces.append(v + str(count + 1) if totalcount > 1 else v)
107
+
108
+ out_dict = dict(zip(new_spaces, num_coords))
109
+ out_dict = json.dumps(out_dict)
110
+
111
  polygons = []
112
  for coord in coordinates:
113
  polygons.append([point.split(',') for point in coord])
 
121
  legend = Image.open("labels.png")
122
  imgs_comb = np.vstack([im, legend])
123
  imgs_comb = Image.fromarray(imgs_comb)
124
+ return imgs_comb, out_dict
125
 
126
 
127
  # Gradio App
 
154
  max-width: 1500px;
155
  }
156
 
157
+ .gradio_interface .panel:nth-child(2) .component:nth-child(3) {
158
+ display:none
159
+ }
160
+
161
  .gradio_wrapper .gradio_bg[theme=default] .panel_buttons {
162
  justify-content: flex-end;
163
  }